counter_click.jinja 5.62 KB
Newer Older
Skia's avatar
Skia committed
1
{% extends "core/base.jinja" %}
2
3
{% from "core/macros.jinja" import user_mini_profile %}

Skia's avatar
Skia committed
4

5
{% macro add_product(id, content) %}
Skia's avatar
Skia committed
6
<form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}" class="form_button">
Skia's avatar
Skia committed
7
    {% csrf_token %}
8
    <input type="hidden" name="action" value="add_product">
Skia's avatar
Skia committed
9
    <button type="submit" name="product_id" value="{{ id }}"> {{ content|safe }} </button>
10
11
12
13
</form>
{% endmacro %}

{% macro del_product(id, content) %}
Skia's avatar
Skia committed
14
<form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}" class="form_button">
15
16
17
    {% csrf_token %}
    <input type="hidden" name="action" value="del_product">
    <button type="submit" name="product_id" value="{{ id }}"> {{ content }} </button>
Skia's avatar
Skia committed
18
19
20
</form>
{% endmacro %}

21
22
23
24
{% block title %}
{{ counter }}
{% endblock %}

Skia's avatar
Skia committed
25
{% block content %}
Skia's avatar
Skia committed
26
<h4>{{ counter }}</h4>
Skia's avatar
Skia committed
27

28
<div id="user_info">
Skia's avatar
Skia committed
29
    <h5>{% trans %}Customer{% endtrans %}</h5>
30
31
    {{ user_mini_profile(customer.user) }}
    <p>{% trans %}Amount: {% endtrans %}{{ customer.amount }}</p>
Skia's avatar
Skia committed
32
</div>
Skia's avatar
Skia committed
33
<div id="bar_ui">
Skia's avatar
Skia committed
34
    <h5>{% trans %}Selling{% endtrans %}</h5>
Skia's avatar
Skia committed
35
36
37
38
39
40
    <div>
        {% if request.session['too_young'] %}
        <p><strong>{% trans %}Too young for that product{% endtrans %}</strong></p>
        {% endif %}
        {% if request.session['not_allowed'] %}
        <p><strong>{% trans %}Not allowed for that product{% endtrans %}</strong></p>
Skia's avatar
Skia committed
41
        {% endif %}
Skia's avatar
Skia committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
        {% if request.session['not_enough'] %}
        <p><strong>{% trans %}Not enough money{% endtrans %}</strong></p>
        {% endif %}
        <form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}">
            {% csrf_token %}
            <input type="hidden" name="action" value="code">
            <input type="input" name="code" value="" autofocus id="code_field"/>
            <input type="submit" value="{% trans %}Go{% endtrans %}" />
        </form>
        <p>{% trans %}Basket: {% endtrans %}</p>
        <ul>
            {% for id,infos in request.session['basket']|dictsort %}
            {% set product = counter.products.filter(id=id).first() %}
            {% set s = infos['qty'] * infos['price'] / 100 %}
            <li>{{ del_product(id, '-') }} {{ infos['qty'] + infos['bonus_qty'] }} {{ add_product(id, '+') }}
            {{ product.name }}: {{ "%0.2f"|format(s) }}
            {% if infos['bonus_qty'] %}
                P
            {% endif %}
            </li>
            {% endfor %}
        </ul>
        <p><strong>{% trans %}Total: {% endtrans %}{{ "%0.2f"|format(basket_total) }}</strong></p>
        <form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}">
            {% csrf_token %}
            <input type="hidden" name="action" value="finish">
            <input type="submit" value="{% trans %}Finish{% endtrans %}" />
        </form>
        <form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}">
            {% csrf_token %}
            <input type="hidden" name="action" value="cancel">
            <input type="submit" value="{% trans %}Cancel{% endtrans %}" />
        </form>
    </div>
    {% if counter.type == 'BAR' %}
    <h5>{% trans %}Refilling{% endtrans %}</h5>
    <div>
        <form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}">
            {% csrf_token %}
            {{ refill_form.as_p() }}
            <input type="hidden" name="action" value="refill">
            <input type="submit" value="{% trans %}Go{% endtrans %}" />
        </form>
    </div>
86
    {% endif %}
Skia's avatar
Skia committed
87
88
89
90
91
92
93
</div>
<div id="products">
    {% for t in categories -%}
    {%- if counter.products.filter(product_type=t).exists() -%}
    <h5>{{ t }}</h5>
    <div id="cat_{{ t }}">
        {% for p in counter.products.filter(product_type=t).all() -%}
Skia's avatar
Skia committed
94
95
96
97
98
99
100
101
            {% set file = None %}
            {% if p.icon %}
                {% set file = p.icon.url %}
            {% else %}
                {% set file = static('core/img/na.gif') %}
            {% endif %}
            {% set prod = '<strong>%s</strong><hr><img src="%s" /><span>%s €<br>%s</span>' % (p.name, file, p.selling_price, p.code) %}
                {{ add_product(p.id, prod) }}
Skia's avatar
Skia committed
102
        {%- endfor %}
103
    </div>
Skia's avatar
Skia committed
104
105
    {%- endif -%}
    {%- endfor %}
Skia's avatar
Skia committed
106
</div>
107

Skia's avatar
Skia committed
108
109
{% endblock %}

110
111
112
113
114
{% block script %}
{{ super() }}
<script>
$( function() {
    var products = [
Skia's avatar
Skia committed
115
    {% for p in counter.products.all() -%}
116
117
118
119
120
        {
            value: "{{ p.code }}",
            label: "{{ p.name }}",
            tags: "{{ p.code }} {{ p.name }}",
        },
Skia's avatar
Skia committed
121
    {%- endfor %}
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
    ];
    var quantity = "";
    var search = "";
    var pattern = /^(\d+x)?(.*)/i;
    $( "#code_field" ).autocomplete({
        select: function (event, ui) {
            event.preventDefault();
            $("#code_field").val(quantity + ui.item.value);
        },
        focus: function (event, ui) {
            event.preventDefault();
            $("#code_field").val(quantity + ui.item.value);
        },
        source: function( request, response ) {
            var res = pattern.exec(request.term);
            quantity = res[1] || "";
            search = res[2];
            var matcher = new RegExp( $.ui.autocomplete.escapeRegex( search ), "i" );
            response($.grep( products, function( value ) {
                value = value.tags;
                return matcher.test( value );
            }));
        },
    });
});
Skia's avatar
Skia committed
147
148
149
150
151
152
153
154
$( function() {
    $("#bar_ui").accordion({
        heightStyle: "content",
        });
    $("#products").accordion({
        heightStyle: "content",
        });
});
155
156
157
</script>
{% endblock %}

Skia's avatar
Skia committed
158
159