Skip to content

Commit

Permalink
Add page showing all transactions in a datatable
Browse files Browse the repository at this point in the history
Remove the "Deferred transactions" page because it is now redundant.
  • Loading branch information
sde1000 committed Jan 18, 2024
1 parent 68e9eb3 commit 20476e0
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 59 deletions.
21 changes: 14 additions & 7 deletions quicktill/tillweb/datatable.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def transactions(request, info):
columns = {
'id': Transaction.id,
'sessionid': Transaction.sessionid,
'session_date': Session.date,
'total': Transaction.total,
'discount_total': Transaction.discount_total,
'notes': Transaction.notes,
Expand All @@ -144,11 +145,16 @@ def transactions(request, info):
undefer('discount_total'),
contains_eager(Transaction.session))

# Searching by amount is slow across the entire table. Disable
# this if we are not filtering the table first.
enable_amount_search = False

# Apply filters from parameters. The 'unfiltered' item count for
# this table is after this filtering step.
try:
sessionid = int(request.GET.get('sessionid'))
q = q.filter(Session.id == sessionid)
enable_amount_search = True
except (ValueError, TypeError):
pass

Expand All @@ -157,11 +163,12 @@ def transactions(request, info):
fq = q
state = request.GET.get('state', 'any')
if state == "closed":
q = q.filter(Transaction.closed == True)
fq = fq.filter(Transaction.closed == True)
elif state == "open":
q = q.filter(Transaction.closed == False)
fq = fq.filter(Transaction.closed == False)\
.filter(Transaction.sessionid != None)
elif state == "deferred":
q = q.filter(Transaction.sessionid == None)
fq = fq.filter(Transaction.sessionid == None)
if search_value:
try:
intsearch = int(search_value)
Expand All @@ -177,7 +184,7 @@ def transactions(request, info):
if intsearch:
qs.append(columns['id'] == intsearch)
qs.append(columns['sessionid'] == intsearch)
if decsearch is not None:
if enable_amount_search and decsearch is not None:
qs.append(columns['total'] == decsearch)
qs.append(columns['discount_total'] == decsearch)
fq = q.filter(or_(*qs))
Expand All @@ -186,9 +193,9 @@ def transactions(request, info):
request, q, fq, columns, lambda t: {
'id': t.id,
'url': t.get_absolute_url(),
'sessionid': t.session.id,
'session_url': t.session.get_absolute_url(),
'session_date': t.session.date,
'sessionid': t.session.id if t.session else None,
'session_url': t.session.get_absolute_url() if t.session else None,
'session_date': t.session.date if t.session else None,
'total': t.total,
'discount_total': t.discount_total,
'notes': t.notes,
Expand Down
2 changes: 1 addition & 1 deletion quicktill/tillweb/templates/tillweb/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{% endfor %}{% if currentsession.pending_total %}({{money}}{{currentsession.pending_total}} unpaid){% endif %}</a>
{% else %}No current session{% endif %}
{% if deferred %}
<br><a href="{% url "tillweb-deferred-transactions" pubname=pubname %}">{{money}}{{deferred}} deferred transactions</a>
<br><a href="{% url "tillweb-transactions" pubname=pubname %}?state=deferred">{{money}}{{deferred}} deferred transactions</a>
{% endif %}
</div>
</div>
Expand Down
12 changes: 10 additions & 2 deletions quicktill/tillweb/templates/tillweb/tillweb.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@
if (data) {
return "Closed";
}
return "Open";
if (row["sessionid"]) {
return "Open";
}
return "Deferred";
};
};
</script>
Expand Down Expand Up @@ -115,7 +118,12 @@
<div class="collapse navbar-collapse" id="tillwebNavbar">
<ul class="navbar-nav flex-column w-100 justify-content-between">
<li class="nav-item"><a class="nav-link" href="{% url "tillweb-pubroot" pubname=pubname %}">Main Menu</a></li>
<li class="nav-item"><a class="nav-link "href="{% url "tillweb-sessions" pubname=pubname %}">Sessions</a></li>
<li class="nav-item dropdown"><a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Register</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="{% url "tillweb-sessions" pubname=pubname %}">Sessions</a>
<a class="dropdown-item" href="{% url "tillweb-transactions" pubname=pubname %}">Transactions</a>
</div>
</li>
<li class="nav-item"><a class="nav-link" href="{% url "tillweb-departments" pubname=pubname %}">Departments</a></li>
<li class="nav-item dropdown"><a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Stock management</a>
<div class="dropdown-menu">
Expand Down
36 changes: 0 additions & 36 deletions quicktill/tillweb/templates/tillweb/transactions-deferred.html

This file was deleted.

85 changes: 85 additions & 0 deletions quicktill/tillweb/templates/tillweb/transactions.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{% extends "tillweb/tillweb.html" %}

{% block title %}{{till}} — transactions{% endblock %}

{% block tillcontent %}

<div class="form-group row">
<label for="stateSelect" class="col-3 col-form-label">Transaction state</label>
<div class="col-9">
<select class="form-control" id="stateSelect">
<option value="all">Any</option>
<option value="closed">Closed</option>
<option value="open">Open</option>
<option value="deferred">Deferred</option>
</select>
</div>
</div>

<table class="table table-sm table-striped" id="transactionsTable">
<thead class="thead-light">
<tr>
<th scope="col">Transaction</th>
<th scope="col">Session</th>
<th scope="col">Date</th>
<th scope="col">Amount</th>
<th scope="col">Discount</th>
<th scope="col">Note</th>
<th scope="col">State</th>
</tr>
</thead>
<tbody></tbody>
</table>

<script type="text/javascript">
$(document).ready(function() {
const urlParams = new URLSearchParams(window.location.search);
const state = urlParams.get('state') || 'all';
$("#stateSelect").val(state);
let transaction_state = state;
const transactions_table = $("#transactionsTable").DataTable({
ajax: {
url: '{% url "tillweb-datatable-transactions" pubname=pubname %}',
dataSrc: 'data',
data: function (d) {
d.state = transaction_state;
},
},
columns: [
{ data: 'id',
render: render_link('url', DataTable.render.text()),
},
{ data: 'sessionid',
render: render_link('session_url', DataTable.render.text()),
},
{ data: 'session_date',
render: DataTable.render.date(),
searchable: false,
},
{ data: 'total',
render: render_money(),
},
{ data: 'discount_total',
render: render_money(),
},
{ data: 'notes',
render: DataTable.render.text(),
},
{ data: 'closed',
render: render_closed(),
searchable: false,
},
],
order: [ [0, 'desc'] ],
searching: true,
paging: true,
serverSide: true,
});
$("#stateSelect").change(function() {
transaction_state = this.value;
transactions_table.ajax.reload(null, true);
});
});
</script>

{% endblock %}
3 changes: 1 addition & 2 deletions quicktill/tillweb/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
name="tillweb-session-department"),
])),

path('transaction/deferred/', views.transactions_deferred,
name="tillweb-deferred-transactions"),
path('transaction/', views.transactions, name="tillweb-transactions"),
path('transaction/<int:transid>/', views.transaction,
name="tillweb-transaction"),

Expand Down
15 changes: 4 additions & 11 deletions quicktill/tillweb/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,17 +738,10 @@ def sessiondept(request, info, sessionid, dept):


@tillweb_view
def transactions_deferred(request, info):
"""Page showing all deferred transactions"""
t = td.s.query(Transaction)\
.options(undefer('total'))\
.filter(Transaction.sessionid == None)\
.order_by(Transaction.id)\
.all()
return ('transactions-deferred.html', {
'transactions': t,
'nav': [("Deferred transactions",
info.reverse('tillweb-deferred-transactions'))],
def transactions(request, info):
return ('transactions.html', {
'nav': [("Transactions",
info.reverse('tillweb-transactions'))],
})


Expand Down

0 comments on commit 20476e0

Please sign in to comment.