2020-03-28 00:45:13 +00:00
|
|
|
{% extends "base.html" %}
|
|
|
|
{% load static %}
|
|
|
|
{% load i18n %}
|
|
|
|
{% load render_table from django_tables2 %}
|
|
|
|
{% load pretty_money %}
|
|
|
|
{% load perms %}
|
|
|
|
|
|
|
|
{% block content %}
|
2020-03-28 15:52:58 +00:00
|
|
|
<a href="{% url "activity:activity_detail" pk=activity.pk %}">
|
|
|
|
<button class="btn btn-light">{% trans "Return to activity page" %}</button>
|
|
|
|
</a>
|
|
|
|
|
2020-03-28 00:45:13 +00:00
|
|
|
<input id="alias" type="text" class="form-control" placeholder="Nom/note ...">
|
|
|
|
|
2020-03-28 12:38:31 +00:00
|
|
|
<hr>
|
|
|
|
|
2020-03-28 00:45:13 +00:00
|
|
|
<div id="entry_table">
|
2020-03-28 15:52:58 +00:00
|
|
|
<h2 class="text-center">{{ entries.count }} {% if entries.count >= 2 %}{% trans "entries" %}{% else %}{% trans "entry" %}{% endif %}</h2>
|
2020-03-28 00:45:13 +00:00
|
|
|
{% render_table table %}
|
|
|
|
</div>
|
|
|
|
{% endblock %}
|
|
|
|
|
|
|
|
{% block extrajavascript %}
|
|
|
|
<script>
|
|
|
|
old_pattern = null;
|
|
|
|
alias_obj = $("#alias");
|
|
|
|
|
2020-03-28 12:38:31 +00:00
|
|
|
function reloadTable(force=false) {
|
2020-03-28 00:45:13 +00:00
|
|
|
let pattern = alias_obj.val();
|
|
|
|
|
2020-03-28 12:38:31 +00:00
|
|
|
if ((pattern === old_pattern || pattern === "") && !force)
|
2020-03-28 00:45:13 +00:00
|
|
|
return;
|
|
|
|
|
2020-03-28 12:38:31 +00:00
|
|
|
$("#entry_table").load(location.href + "?search=" + pattern.replace(" ", "%20") + " #entry_table", init);
|
|
|
|
refreshBalance();
|
|
|
|
}
|
|
|
|
|
|
|
|
alias_obj.keyup(reloadTable);
|
|
|
|
|
|
|
|
$(document).ready(init);
|
|
|
|
|
|
|
|
function init() {
|
|
|
|
$(".table-row").click(function(e) {
|
|
|
|
let target = e.target.parentElement;
|
|
|
|
target = $("#" + target.id);
|
|
|
|
|
|
|
|
let type = target.attr("data-type");
|
|
|
|
let id = target.attr("data-id");
|
2020-03-28 15:52:58 +00:00
|
|
|
let last_name = target.attr("data-last-name");
|
|
|
|
let first_name = target.attr("data-first-name");
|
2020-03-28 12:38:31 +00:00
|
|
|
|
|
|
|
if (type === "membership") {
|
|
|
|
$.post("/api/activity/entry/?format=json", {
|
|
|
|
csrfmiddlewaretoken: CSRF_TOKEN,
|
|
|
|
activity: {{ activity.id }},
|
|
|
|
note: id,
|
|
|
|
guest: null
|
|
|
|
}).done(function () {
|
|
|
|
addMsg("Entrée effectuée !", "success");
|
|
|
|
reloadTable(true);
|
|
|
|
}).fail(function(xhr) {
|
|
|
|
errMsg(xhr.responseJSON);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
2020-03-28 15:52:58 +00:00
|
|
|
let line_obj = $("#buttons_guest_" + id);
|
|
|
|
if (line_obj.length || target.attr('class').includes("table-success")) {
|
|
|
|
line_obj.remove();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let tr = "<tr class='text-center'>" +
|
|
|
|
"<td id='buttons_guest_" + id + "' style='table-danger center' colspan='5'>" +
|
|
|
|
"<button id='transaction_guest_" + id + "' class='btn btn-secondary'>Payer avec la note de l'hôte</button> " +
|
|
|
|
"<button id='transaction_guest_" + id + "_especes' class='btn btn-secondary'>Payer en espèces</button> " +
|
|
|
|
"<button id='transaction_guest_" + id + "_cb' class='btn btn-secondary'>Payer en CB</button></td>" +
|
|
|
|
"<tr>";
|
|
|
|
$(tr).insertAfter(target);
|
|
|
|
|
|
|
|
let makeTransaction = function() {
|
|
|
|
$.post("/api/activity/entry/?format=json", {
|
|
|
|
csrfmiddlewaretoken: CSRF_TOKEN,
|
|
|
|
activity: {{ activity.id }},
|
|
|
|
note: target.attr("data-inviter"),
|
|
|
|
guest: id
|
|
|
|
}).done(function () {
|
|
|
|
addMsg("Entrée effectuée !", "success");
|
|
|
|
reloadTable(true);
|
|
|
|
}).fail(function (xhr) {
|
|
|
|
errMsg(xhr.responseJSON);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
let credit = function(credit_id, credit_name) {
|
|
|
|
return function() {
|
|
|
|
$.post("/api/note/transaction/transaction/",
|
|
|
|
{
|
|
|
|
"csrfmiddlewaretoken": CSRF_TOKEN,
|
|
|
|
"quantity": 1,
|
|
|
|
"amount": {{ activity.activity_type.guest_entry_fee }},
|
|
|
|
"reason": "Crédit " + credit_name + " (invitation {{ activity.name }})",
|
|
|
|
"valid": true,
|
|
|
|
"polymorphic_ctype": {{ notespecial_ctype }},
|
|
|
|
"resourcetype": "SpecialTransaction",
|
|
|
|
"source": credit_id,
|
|
|
|
"destination": target.attr('data-inviter'),
|
|
|
|
"last_name": last_name,
|
|
|
|
"first_name": first_name,
|
|
|
|
"bank": ""
|
|
|
|
}).done(function () {
|
|
|
|
makeTransaction();
|
|
|
|
reset();
|
|
|
|
}).fail(function (xhr) {
|
|
|
|
errMsg(xhr.responseJSON);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
$("#transaction_guest_" + id).click(makeTransaction);
|
|
|
|
$("#transaction_guest_" + id + "_especes").click(credit(1, "espèces"));
|
|
|
|
$("#transaction_guest_" + id + "_cb").click(credit(2, "carte bancaire"));
|
2020-03-28 12:38:31 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-03-28 00:45:13 +00:00
|
|
|
</script>
|
|
|
|
{% endblock %}
|