

{% extends 'accounting.html' %}

{% load i18n widget_tweaks %}


{% block content %}

    {{ block.super }}

    <style>
        .filter-form {
            margin-bottom: 10px
        }
    </style>

    <h4 class="pull-left">
        {% trans 'Service report' %}
        ({{ date_from|date:'d.m.Y' }} - {{ date_to|date:'d.m.Y' }})
    </h4>

    <button class="btn btn-primary pull-right print-btn" onClick="window.print();">
        {% trans 'Print' %}
    </button>

    <div class="clearfix"></div>

    <hr class="hidden-print" />

    <form class="filter-form" data-role="filter-form">
        {{ form.errors }}
        <div class="row">
            <div class="col-md-4">
                {{ form.worker|add_class:'form-control' }}
            </div>
            <div class="col-md-4">
                {{ form.date_from|add_class:'form-control'|attr:'autocomplete:off' }}
            </div>
            <div class="col-md-4">
                {{ form.date_to|add_class:'form-control'|attr:'autocomplete:off' }}
            </div>
        </div>
    </form>

    <div class="clearfix"></div>

    <table class="table table-bordered table-condensed">
        <thead>
            <tr>
                <th>№</th>
                <th>{% trans 'Date' %}</th>
                <th>{% trans 'Service' %}</th>
                <th>{% trans 'Customer' %}</th>
                <th>{% trans 'Worker' %}</th>
                <th>{% trans 'Quantity' %}</th>
                <th>{% trans 'Price' %}</th>
                <th>{% trans 'Sum' %}</th>
            </tr>
        </thead>
        <tbody>
            {% for service in services %}
                <tr>
                    <td>{{ forloop.counter }}</td>
                    <td>{{ service.created }}</td>
                    <td>{{ service.item.name }}</td>
                    <td>{{ service.customer|default:'' }}</td>
                    <td>{{ service.worker|default:'' }}</td>
                    <td>{{ service.qty }}</td>
                    <td>{{ service.price }}</td>
                    <td>{{ service.subtotal }}</td>
                </tr>
            {% endfor %}
            <tr>
                <td colspan="5" class="text-right">
                    {% trans 'Total' %}:
                </td>
                <td>{{ totals.qty }}</td>
                <td></td>
                <td>{{ totals.grand_total }}</td>
            </tr>
        </tbody>
    </table>
{% endblock %}


{% block js %}
    {{ block.super }}
    <script>
        (function ($) {
            var $form = $('[data-role=filter-form]');
            $form.find('input, select').change(function () {
                $form.submit();
            });
        })(jQuery);
    </script>
{% endblock %}
