haldis/app/templates/order.html

187 lines
9.1 KiB
HTML
Raw Normal View History

2015-03-31 20:15:22 +02:00
{% extends "layout.html" %}
{% set active_page = "orders" -%}
2015-06-04 21:20:38 +02:00
{% set order_items = order.group_by_user() -%}
{% set courier_or_admin = not current_user.is_anonymous() and (current_user.is_admin() or current_user.id == order.courier_id) -%}
2015-03-31 20:15:22 +02:00
{% import "utils.html" as util %}
{% block container %}
<div class="row">
2019-12-05 19:39:35 +01:00
<div class="col-md-push-1 col-md-10 darker order_overview" id="info"><!-- Shitty html -->
<h3 id="order-title">Order {{ order.id }}
2015-06-09 13:46:37 +02:00
<div class="pull-right">
{% if order.can_close(current_user.id) -%}
2019-09-10 02:50:22 +02:00
<form action="{{ url_for('order_bp.close_order', order_id=order.id) }}" method="post" style="display:inline">
<input type="submit" class="btn btn-danger" value="Close"></input>
</form>
{% endif %}{% if courier_or_admin %}
2019-09-10 02:50:22 +02:00
<a class="btn btn-warning" href="{{ url_for('order_bp.order_edit', order_id=order.id) }}">Edit</a>
2015-06-09 13:46:37 +02:00
{%- endif %}
</div></h3>
courier: {{ order.courier.username }}
{% if order.courier == None and not current_user.is_anonymous() %}
2019-09-10 02:50:22 +02:00
<form action="{{ url_for('order_bp.volunteer', order_id=order.id) }}" method="post" style="display:inline">
<input type="submit" class="btn btn-primary btn-sm" value="Volunteer"></input>
</form>
2015-03-31 20:15:22 +02:00
{% endif %}
<br/>
location: {% if order.location %}
<a href="{{ url_for('general_bp.location', location_id=order.location_id) }}">{{ order.location_name }}</a>
{% else %}
{{ order.location_name }}
{% endif %}<br/>
2015-06-04 18:45:59 +02:00
{% if order.location.telephone != None %}
telephone: <a href="tel://{{ order.location.telephone }}">{{ order.location.telephone }}</a><br/>
{% endif %}
start: {{ order.starttime.strftime("%d/%m/%Y %H:%M") }}<br>
{% if order.stoptime %}
closing time: {{ order.stoptime.strftime("%H:%M") }} (<span class="time">{{ order.stoptime|countdown }}</span>)
{% else %}open{% endif %}<br/>
2015-06-04 21:20:38 +02:00
total price: {{ total_price|euro }} {% if courier_or_admin %}- remaining debts: {{ debts|euro }}{% endif %}
2015-03-31 20:15:22 +02:00
</div>
{% if form -%}
2019-12-05 19:39:35 +01:00
<div class="col-md-push-1 col-md-10 darker order_order" id="form">
2015-03-31 20:15:22 +02:00
<h4>Order:</h4>
2019-09-10 02:50:22 +02:00
<form method="post" action="{{ url_for('order_bp.order_item_create', order_id=order.id) }}">
2018-03-19 18:52:15 +01:00
<span class="pull-right">
<a class="btn btn-primary" onclick="chooseRandom()">Choose for me</a>
</span>
2015-03-31 20:15:22 +02:00
{{ form.csrf_token }}
<div class="form-group select2-container select2 {{ 'has-errors' if form.dish_id.errors}}">
{{ form.dish_id.label(class='control-label') }}<br>
{{ form.dish_id(class='form-control select') }}
{{ util.render_form_field_errors(form.dish_id) }}
2015-03-31 20:15:22 +02:00
</div>
<div class="form-group {{ 'has-errors' if form.dish_id.errors }}">
{{ form.comment.label(class='control-label') }}<br>
{{ form.comment(class='form-control', placeholder='Fill in comment, when applicable') }}
{{ util.render_form_field_errors(form.comment) }}
2015-06-24 22:10:26 +02:00
</div>
2020-02-21 18:38:30 +01:00
{% for choice_field in form.single_choices %}
<div class="form-group {{ 'has-errors' if choice_field }}">
{{ choice_field.label(class='control-label') }}<br>
{{ choice_field(class='form-control') }}
{{ util.render_form_field_errors(choice_field) }}
</div>
{% endfor %}
{% for choice_field in form.multi_choices %}
<div class="form-group {{ 'has-errors' if choice_field }}">
{{ choice_field.label(class='control-label') }}<br>
{{ choice_field(class='form-control') }}
{{ util.render_form_field_errors(choice_field) }}
</div>
{% endfor %}
2015-03-31 20:15:22 +02:00
{% if current_user.is_anonymous() %}
<div class="form-group{{ ' has-error' if form.name.errors }}{{ ' required' if form.name.flags.required }}">
{{ form.name.label(class='control-label') }}
{{ form.name(class='form-control', placeholder='Fill in your name...') }}
2015-03-31 20:15:22 +02:00
{{ util.render_form_field_errors(form.name) }}
</div>
{% endif %}
<div class="form-group" style="padding-top: 8px;">
{{ form.submit_button(class='btn btn-primary') }}
</div>
</form>
</div>
{%- endif %}
</div>
<div class="row" id="items">
2019-12-05 19:39:35 +01:00
<div class="col-md-push-1 col-md-5 darker order_items" id="items-list">
2015-06-04 21:20:38 +02:00
<h3>Items</h3>
<table class="table table-hover table-condensed">
<thead>
2015-06-24 22:24:21 +02:00
<tr><th>Name</th><th>Item</th><th>Price</th>{% if courier_or_admin %}<th>Paid?</th>{% endif %}<th>Delete</th></tr>
2015-06-04 21:20:38 +02:00
</thead>
<tbody>
{% for item in order.items -%}
<tr>
<td>{{ item.get_name() }}</td>
<td><span title="{{ item.comment if item.comment }}">{{ item.dish_name }}{{ "*" if item.comment }}</span></td>
<td>{{ item.price|euro }}</td>
{% if courier_or_admin %}<td>{% if not item.paid %}
<form action="{{ url_for('order_bp.item_paid', order_id=order.id, item_id=item.id) }}" method="post" style="display:inline">
<input type="submit" class="btn btn-xs btn-primary" value="Pay"></input>
</form>
{% else %} <span class="glyphicon glyphicon-chevron-down"></span>
{% endif %}</td>
{% endif %}
<td>{% if item.can_delete(order.id, current_user.id, session.get('anon_name', '')) -%}
<form action="{{ url_for('order_bp.delete_item', order_id=order.id, item_id=item.id) }}" method="post" style="display:inline">
<button class="btn btn-link" type="submit"><span class="glyphicon glyphicon-remove"></span></button>
</form>
{%- endif %}<br/></td>
2015-06-04 21:20:38 +02:00
</tr>
{%- endfor %}
</tbody>
</table>
2015-03-31 20:15:22 +02:00
</div>
2019-12-05 19:39:35 +01:00
<div class="col-md-push-2 col-md-4 darker box order_ordered" id="items-ordered">
<h3>Ordered dishes: {{ order.items.count() }}</h3>
2019-09-10 02:50:22 +02:00
<a class="divLink" href="{{ url_for('order_bp.items_showcase', order_id=order.id) }}"></a>
{% for key, value in order.group_by_dish().items() -%}
2015-06-24 22:10:26 +02:00
<div class="product">
{{ key }}: {{ value["count"] }}
{% if value["comments"]|any -%}
<ul class="comments">
{% for comment in value["comments"] -%}
<li>{% if comment %}{{ comment }}
{% else %}<i>No comment</i>
{% endif %}</li>
2015-06-24 22:10:26 +02:00
{% endfor %}
</ul>
2015-06-24 22:10:26 +02:00
{%- endif %}
</div>
2015-06-04 21:20:38 +02:00
{%- endfor %}
2015-03-31 20:15:22 +02:00
</div>
</div>
<div class="row">
2019-12-05 19:39:35 +01:00
<div class="col-md-push-1 col-md-5 darker order_depts" id="debts">
2015-03-31 20:15:22 +02:00
<h3>Debts</h3>
2015-06-04 21:20:38 +02:00
<table class="table table-hover table-condensed">
<thead>
<tr><th>Name</th><th>Total</th><th>To pay</th>{% if courier_or_admin %}<th>Paid?</th>{% endif %}</tr>
</thead>
<tbody>
{% for key, value in order_items.items() -%}
<tr>
<td>{{ key }}</td>
<td>{{ value["total"]|euro }}</td>
<td>{{ value["to_pay"]|euro }}</td>
{% if courier_or_admin %}<td>{% if not value["to_pay"] == 0 %}
<form action="{{ url_for('order_bp.items_user_paid', order_id=order.id, user_name=key) }}" method="post" style="display:inline">
<input type="submit" class="btn btn-xs btn-primary" value="Pay"></input>
</form>
{% else %} <span class="glyphicon glyphicon-chevron-down"></span> {% endif %}</td>{% endif %}
2015-06-04 21:20:38 +02:00
</tr>
{%- endfor %}
</tbody>
</table>
2015-03-31 20:15:22 +02:00
</div>
</div>
{% endblock %}
{% block styles %}
{{ super() }}
<link rel="stylesheet" href="{{ url_for('static', filename='css/select2.min.css') }}" />
2015-03-31 20:15:22 +02:00
<link rel="stylesheet" href="{{ url_for('static', filename='css/select2-bootstrap.min.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/print.css') }}">
2015-03-31 20:15:22 +02:00
{% endblock %}
{% block scripts %}
{{ super() }}
<script src="{{ url_for('static', filename='js/select2.min.js') }}"></script>
2015-03-31 20:15:22 +02:00
<script type="text/javascript">
2018-03-19 18:52:15 +01:00
var select = $('.select').select2({
2015-06-09 13:46:37 +02:00
'sorter': function(results) {
return results.sort();
}
});
2018-03-19 18:52:15 +01:00
var options = select[0].options;
function chooseRandom() {
var index = Math.floor((Math.random() * options.length))
var choice = options[index]
select.val(choice.value).trigger("change")
}
2015-03-31 20:15:22 +02:00
</script>
2015-04-05 13:08:02 +02:00
{% endblock %}