counter_click.jinja 5.86 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

Skia's avatar
Skia committed
5
6
{% macro add_product(id, content, class="") %}
<form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}" class="{{ class }}">
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
</form>
{% endmacro %}

Skia's avatar
Skia committed
13
14
{% macro del_product(id, content, class="") %}
<form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}" class="{{ class }}">
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
        {% 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 %}
Skia's avatar
Skia committed
56
            <li>{{ del_product(id, '-', "inline") }} {{ infos['qty'] + infos['bonus_qty'] }} {{ add_product(id, '+', "inline") }}
Skia's avatar
Skia committed
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
            {{ 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
</div>
<div id="products">
89
90
91
92
93
94
95
    <ul>
        {% for t in categories -%}
        {%- if counter.products.filter(product_type=t).exists() -%}
        <li><a href="#cat_{{ t|slugify }}">{{ t }}</a></li>
        {%- endif -%}
        {%- endfor %}
    </ul>
Skia's avatar
Skia committed
96
97
    {% for t in categories -%}
    {%- if counter.products.filter(product_type=t).exists() -%}
98
99
    <div id="cat_{{ t|slugify }}">
        <h5>{{ t }}</h5>
Skia's avatar
Skia committed
100
        {% for p in counter.products.filter(product_type=t).all() -%}
Skia's avatar
Skia committed
101
102
103
104
105
106
107
            {% 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) %}
Skia's avatar
Skia committed
108
                {{ add_product(p.id, prod, "form_button") }}
Skia's avatar
Skia committed
109
        {%- endfor %}
110
    </div>
Skia's avatar
Skia committed
111
112
    {%- endif -%}
    {%- endfor %}
Skia's avatar
Skia committed
113
</div>
114

Skia's avatar
Skia committed
115
116
{% endblock %}

117
118
119
120
121
{% block script %}
{{ super() }}
<script>
$( function() {
    var products = [
Skia's avatar
Skia committed
122
    {% for p in counter.products.all() -%}
123
124
125
126
127
        {
            value: "{{ p.code }}",
            label: "{{ p.name }}",
            tags: "{{ p.code }} {{ p.name }}",
        },
Skia's avatar
Skia committed
128
    {%- endfor %}
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
    ];
    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
154
155
156
157
$( function() {
    $("#bar_ui").accordion({
        heightStyle: "content",
        });
158
    $("#products").tabs();
Skia's avatar
Skia committed
159
});
160
161
162
</script>
{% endblock %}

Skia's avatar
Skia committed
163
164