Skip to content

Commit

Permalink
Add a 'Payments' tab to session detail pages
Browse files Browse the repository at this point in the history
  • Loading branch information
sde1000 committed Jan 16, 2024
1 parent 9f368e6 commit f229184
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
3 changes: 3 additions & 0 deletions quicktill/tillweb/datatable.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def payments(request, info):
columns = {
'id': Payment.id,
'transid': Payment.transid,
'paytype_description': PayType.description,
'time': Payment.time,
'paytype': Payment.paytype_id,
'text': Payment.text,
Expand Down Expand Up @@ -168,6 +169,7 @@ def payments(request, info):
columns['text'].ilike(f'%{search_value}%'),
columns['source'].ilike(f'{search_value}%'),
columns['user'].ilike(f'%{search_value}%'),
columns['paytype_description'].ilike(f'%{search_value}%'),
]
if intsearch:
qs.append(columns['id'] == intsearch)
Expand All @@ -184,6 +186,7 @@ def payments(request, info):
'trans_url': p.transaction.get_absolute_url(),
'time': p.time,
'paytype': p.paytype_id,
'paytype_description': p.paytype.description,
'paytype_url': p.paytype.get_absolute_url(),
'text': p.text,
'source': p.source,
Expand Down
82 changes: 82 additions & 0 deletions quicktill/tillweb/templates/tillweb/session.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@
Transactions
</a>
</li>
<li class="nav-item">
<a class="nav-link" id="paymentsTab" href="#payments" data-toggle="tab" data-target="#payments" role="tab" aria-controls="payments" aria-selected="false">
Payments
</a>
</li>
<li class="nav-item">
<a class="nav-link" id="infoTab" href="#info" data-toggle="tab" data-target="#info" role="tab" aria-controls="info" aria-selected="false">
Info
Expand Down Expand Up @@ -144,6 +149,25 @@
</div>
<div class="tab-pane fade" id="transactions" aria-labelledby="transactionsTab">
</div>
<div class="tab-pane fade" id="payments" aria-labelledby="paymentsTab">
<div class="mb-1"></div>
<table class="table table-sm table-striped" id="paymentsTable">
<thead class="thead-light">
<tr>
<th scope="col">ID</th>
<th scope="col">Transaction</th>
<th scope="col">Method</th>
<th scope="col">Description</th>
<th scope="col">Amount</th>
<th scope="col">Time</th>
<th scope="col">Source</th>
<th scope="col">Pending?</th>
<th scope="col">User</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
<div class="tab-pane fade" id="info" aria-labelledby="infoTab">
<a class="btn btn-secondary mt-3 mb-3" href="{% url "tillweb-session-spreadsheet" pubname=pubname sessionid=session.id %}">Download spreadsheet</a>
{% with logs=session.logs %}
Expand Down Expand Up @@ -193,6 +217,7 @@

let depttotals_table = null;
let usertotals_table = null;
let payments_table = null;

function init_depttotals_table() {
depttotals_table = $("#depttakings").DataTable({
Expand Down Expand Up @@ -324,6 +349,53 @@
});
};

function init_payments_table() {
payments_table = $("#paymentsTable").DataTable({
ajax: {
url: '{% url "tillweb-datatable-payments" pubname=pubname %}',
dataSrc: 'data',
data: function (d) {
d.sessionid = {{session.id}};
},
},
columns: [
{ data: 'id',
render: render_link('url', DataTable.render.text()),
},
{ data: 'transid',
render: render_link('trans_url', DataTable.render.text()),
},
{ data: 'paytype_description',
render: render_link('paytype_url', DataTable.render.text()),
},
{ data: 'text',
render: DataTable.render.text(),
},
{ data: 'amount',
render: render_money(),
},
{ data: 'time',
render: render_link('url', DataTable.render.datetime()),
searchable: false,
},
{ data: 'source',
render: DataTable.render.text(),
},
{ data: 'pending',
render: render_yesno(),
searchable: false,
},
{ data: 'user',
render: render_link('user_url', DataTable.render.text()),
},
],
order: [ [0, 'desc'] ],
searching: true,
paging: true,
serverSide: true,
});
};

$(document).ready(function(){
$('[data-toggle="tabajax"]').on("click.tillweb", function (e) {
const $this = $(this),
Expand Down Expand Up @@ -365,6 +437,16 @@
}
});

$('#paymentsTab').on("click", function (e) {
if (payments_table === null) {
init_payments_table();
} else {
{% if not session.endtime %}
payments_table.ajax.reload();
{% endif %}
}
});

$('#deptTakingsTab').trigger('click');
});
</script>
Expand Down

0 comments on commit f229184

Please sign in to comment.