2019-08-10 17:00:16 +00:00
|
|
|
{% extends "base.html" %}
|
2019-07-17 11:53:58 +00:00
|
|
|
{% comment %}
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
{% endcomment %}
|
|
|
|
|
|
|
|
{% load i18n static %}
|
|
|
|
|
|
|
|
{% block content %}
|
2020-03-13 00:57:32 +00:00
|
|
|
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-xl-12">
|
2020-03-14 14:13:58 +00:00
|
|
|
<div class="btn-group btn-group-toggle" style="width: 100%" data-toggle="buttons">
|
|
|
|
<label class="btn btn-sm btn-outline-primary active">
|
|
|
|
<input type="radio" name="transaction_type" id="type_gift" checked>
|
|
|
|
Virement
|
|
|
|
</label>
|
|
|
|
<label class="btn btn-sm btn-outline-primary">
|
|
|
|
<input type="radio" name="transaction_type" id="type_transfer">
|
|
|
|
Transfert
|
|
|
|
</label>
|
|
|
|
<label class="btn btn-sm btn-outline-primary">
|
|
|
|
<input type="radio" name="transaction_type" id="type_credit">
|
|
|
|
Crédit
|
|
|
|
</label>
|
|
|
|
<label class="btn btn-sm btn-outline-primary">
|
|
|
|
<input type="radio" name="transaction_type" id="type_debit">
|
|
|
|
Retrait
|
|
|
|
</label>
|
|
|
|
</div>
|
2020-03-13 00:57:32 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2020-03-12 22:12:49 +00:00
|
|
|
<div class="row">
|
2020-03-13 00:57:32 +00:00
|
|
|
<div class="col-md-6" id="emitters_div" style="display: none;">
|
2020-03-12 22:12:49 +00:00
|
|
|
<div class="card border-success shadow mb-4">
|
|
|
|
<div class="card-header">
|
|
|
|
<p class="card-text font-weight-bold">
|
|
|
|
Sélection des émetteurs
|
|
|
|
</p>
|
2019-07-17 11:53:58 +00:00
|
|
|
</div>
|
2020-03-12 22:12:49 +00:00
|
|
|
<ul class="list-group list-group-flush" id="source_note_list">
|
|
|
|
</ul>
|
|
|
|
<div class="card-body">
|
|
|
|
<input class="form-control mx-auto d-block" type="text" id="source_note" />
|
|
|
|
<ul class="list-group list-group-flush" id="source_alias_matched">
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2020-03-14 14:13:58 +00:00
|
|
|
<div class="col-md-6" id="external_div" style="display: none;">
|
|
|
|
<div class="card border-success shadow mb-4">
|
|
|
|
<div class="card-header">
|
|
|
|
<p class="card-text font-weight-bold">
|
|
|
|
Paiement externe
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<ul class="list-group list-group-flush" id="source_note_list">
|
|
|
|
</ul>
|
|
|
|
<div class="card-body">
|
|
|
|
<div class="form-row">
|
|
|
|
<div class="col-md-12">
|
|
|
|
<label for="credit_type">Type de transfert :</label>
|
|
|
|
<select id="credit_type" class="custom-select">
|
|
|
|
{% for special_type in special_types %}
|
|
|
|
<option value="{{ special_type.id }}">{{ special_type.special_type }}</option>
|
|
|
|
{% endfor %}
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
|
|
<div class="col-md-12">
|
|
|
|
<label for="last_name">Nom :</label>
|
|
|
|
<input type="text" id="last_name" class="form-control" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
|
|
<div class="col-md-12">
|
|
|
|
<label for="first_name">Prénom :</label>
|
|
|
|
<input type="text" id="first_name" class="form-control" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
|
|
<div class="col-md-12">
|
|
|
|
<label for="bank">Banque :</label>
|
|
|
|
<input type="text" id="bank" class="form-control" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2020-03-13 00:57:32 +00:00
|
|
|
<div class="col-md-12" id="dests_div">
|
2020-03-12 22:12:49 +00:00
|
|
|
<div class="card border-info shadow mb-4">
|
|
|
|
<div class="card-header">
|
|
|
|
<p class="card-text font-weight-bold">
|
|
|
|
Sélection des destinataires
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<ul class="list-group list-group-flush" id="dest_note_list">
|
|
|
|
</ul>
|
|
|
|
<div class="card-body">
|
|
|
|
<input class="form-control mx-auto d-block" type="text" id="dest_note" />
|
|
|
|
<ul class="list-group list-group-flush" id="dest_alias_matched">
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="form-row">
|
|
|
|
<div class="form-group col-md-6">
|
|
|
|
<label for="amount">{% trans "Amount" %} :</label>
|
|
|
|
<input class="form-control mx-auto d-block" type="number" min="-20" id="amount" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="form-group col-md-6">
|
|
|
|
<label for="reason">{% trans "Reason" %} :</label>
|
|
|
|
<input class="form-control mx-auto d-block" type="text" id="reason" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="form-row">
|
|
|
|
<div class="col-md-12">
|
|
|
|
<button id="transfer" class="form-control btn btn-primary">{% trans 'Transfer' %}</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{% endblock %}
|
|
|
|
|
|
|
|
{% block extrajavascript %}
|
|
|
|
<script>
|
2020-03-13 08:26:39 +00:00
|
|
|
sources = [];
|
|
|
|
sources_notes_display = [];
|
|
|
|
dests = [];
|
|
|
|
dests_notes_display = [];
|
2020-03-14 14:13:58 +00:00
|
|
|
|
|
|
|
function reset() {
|
|
|
|
sources_notes_display.length = 0;
|
|
|
|
sources.length = 0;
|
|
|
|
dests_notes_display.length = 0;
|
|
|
|
dests.length = 0;
|
|
|
|
$("#source_note_list").html("");
|
|
|
|
$("#dest_note_list").html("");
|
|
|
|
$("#source_alias_matched").html("");
|
|
|
|
$("#dest_alias_matched").html("");
|
|
|
|
$("#amount").val("");
|
|
|
|
$("#reason").val("");
|
|
|
|
$("#last_name").val("");
|
|
|
|
$("#first_name").val("");
|
|
|
|
$("#bank").val("");
|
|
|
|
refreshBalance();
|
|
|
|
}
|
2020-03-12 22:12:49 +00:00
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
autoCompleteNote("source_note", "source_alias_matched", "source_note_list", sources, sources_notes_display,
|
|
|
|
"source_alias", "source_note");
|
|
|
|
autoCompleteNote("dest_note", "dest_alias_matched", "dest_note_list", dests, dests_notes_display,
|
|
|
|
"dest_alias", "dest_note");
|
|
|
|
});
|
|
|
|
|
2020-03-14 14:13:58 +00:00
|
|
|
$("#type_gift").click(function() {
|
|
|
|
$("#emitters_div").hide();
|
|
|
|
$("#external_div").hide();
|
|
|
|
$("#dests_div").attr('class', 'col-md-12');
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#type_transfer").click(function() {
|
|
|
|
$("#emitters_div").show();
|
|
|
|
$("#external_div").hide();
|
|
|
|
$("#dests_div").attr('class', 'col-md-6');
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#type_credit").click(function() {
|
|
|
|
$("#emitters_div").hide();
|
|
|
|
$("#external_div").show();
|
|
|
|
$("#dests_div").attr('class', 'col-md-6');
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#type_debit").click(function() {
|
|
|
|
$("#emitters_div").hide();
|
|
|
|
$("#external_div").show();
|
|
|
|
$("#dests_div").attr('class', 'col-md-6');
|
2020-03-13 00:57:32 +00:00
|
|
|
});
|
|
|
|
|
2020-03-12 22:12:49 +00:00
|
|
|
$("#transfer").click(function() {
|
2020-03-14 14:13:58 +00:00
|
|
|
if ($("#type_gift").is(':checked')) {
|
2020-03-13 00:57:32 +00:00
|
|
|
dests_notes_display.forEach(function (dest) {
|
2020-03-12 22:12:49 +00:00
|
|
|
$.post("/api/note/transaction/transaction/",
|
2020-03-13 00:57:32 +00:00
|
|
|
{
|
|
|
|
"csrfmiddlewaretoken": CSRF_TOKEN,
|
|
|
|
"quantity": dest[3],
|
|
|
|
"amount": $("#amount").val(),
|
|
|
|
"reason": $("#reason").val() + " (Don)",
|
|
|
|
"valid": true,
|
|
|
|
"polymorphic_ctype": {{ polymorphic_ctype }},
|
|
|
|
"resourcetype": "Transaction",
|
|
|
|
"source": {{ user.note.id }},
|
|
|
|
"destination": dest[1]
|
|
|
|
}, function () {
|
|
|
|
let msgDiv = $("#messages");
|
|
|
|
let html = msgDiv.html();
|
|
|
|
html += "<div class=\"alert alert-success\">Le transfert de "
|
|
|
|
+ pretty_money(dest[3] * $("#amount").val()) + " de votre note "
|
|
|
|
+ " vers la note " + dest[0] + " a été fait avec succès !</div>\n";
|
|
|
|
msgDiv.html(html);
|
2020-03-12 22:12:49 +00:00
|
|
|
|
2020-03-14 14:13:58 +00:00
|
|
|
reset();
|
2020-03-13 00:57:32 +00:00
|
|
|
}).fail(function (err) {
|
2020-03-12 22:12:49 +00:00
|
|
|
let msgDiv = $("#messages");
|
|
|
|
let html = msgDiv.html();
|
2020-03-13 00:57:32 +00:00
|
|
|
html += "<div class=\"alert alert-danger\">Le transfert de "
|
|
|
|
+ pretty_money(dest[3] * $("#amount").val()) + " de votre note "
|
|
|
|
+ " vers la note " + dest[0] + " a échoué : " + err.responseText + "</div>\n";
|
2020-03-12 22:12:49 +00:00
|
|
|
msgDiv.html(html);
|
2020-03-13 00:57:32 +00:00
|
|
|
|
2020-03-14 14:13:58 +00:00
|
|
|
reset();
|
2020-03-13 00:57:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2020-03-14 14:13:58 +00:00
|
|
|
else if ($("#type_transfer").is(':checked')) {
|
2020-03-13 00:57:32 +00:00
|
|
|
sources_notes_display.forEach(function (source) {
|
|
|
|
dests_notes_display.forEach(function (dest) {
|
|
|
|
$.post("/api/note/transaction/transaction/",
|
|
|
|
{
|
|
|
|
"csrfmiddlewaretoken": CSRF_TOKEN,
|
|
|
|
"quantity": source[3] * dest[3],
|
|
|
|
"amount": $("#amount").val(),
|
|
|
|
"reason": $("#reason").val() + " (Transfert)",
|
|
|
|
"valid": true,
|
|
|
|
"polymorphic_ctype": {{ polymorphic_ctype }},
|
|
|
|
"resourcetype": "Transaction",
|
|
|
|
"source": source[1],
|
|
|
|
"destination": dest[1]
|
|
|
|
}, function () {
|
|
|
|
let msgDiv = $("#messages");
|
|
|
|
let html = msgDiv.html();
|
|
|
|
html += "<div class=\"alert alert-success\">Le transfert de "
|
|
|
|
+ pretty_money(source[3] * dest[3] * $("#amount").val()) + " de la note " + source[0]
|
|
|
|
+ " vers la note " + dest[0] + " a été fait avec succès !</div>\n";
|
|
|
|
msgDiv.html(html);
|
2020-03-12 22:12:49 +00:00
|
|
|
|
2020-03-14 14:13:58 +00:00
|
|
|
reset();
|
2020-03-13 00:57:32 +00:00
|
|
|
}).fail(function (err) {
|
|
|
|
let msgDiv = $("#messages");
|
|
|
|
let html = msgDiv.html();
|
|
|
|
html += "<div class=\"alert alert-danger\">Le transfert de "
|
|
|
|
+ pretty_money(source[3] * dest[3] * $("#amount").val()) + " de la note " + source[0]
|
|
|
|
+ " vers la note " + dest[0] + " a échoué : " + err.responseText + "</div>\n";
|
|
|
|
msgDiv.html(html);
|
|
|
|
|
2020-03-14 14:13:58 +00:00
|
|
|
reset();
|
2020-03-13 00:57:32 +00:00
|
|
|
});
|
2020-03-12 22:12:49 +00:00
|
|
|
});
|
|
|
|
});
|
2020-03-14 14:13:58 +00:00
|
|
|
} else if ($("#type_credit").is(':checked') || $("#type_debit").is(':checked')) {
|
|
|
|
let special_note = $("#credit_type").val();
|
|
|
|
let user_note = dests_notes_display[0][1];
|
|
|
|
let source, dest, reason;
|
|
|
|
if ($("#type_credit").is(':checked')) {
|
|
|
|
source = special_note;
|
|
|
|
dest = user_note;
|
|
|
|
reason = $("#reason").val() + " (Crédit " + $("#credit_type option:selected").text().toLowerCase() + ")";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
source = user_note;
|
|
|
|
dest = special_note;
|
|
|
|
reason = $("#reason").val() + " (Retrait " + $("#credit_type option:selected").text().toLowerCase() + ")";
|
|
|
|
}
|
|
|
|
$.post("/api/note/transaction/transaction/",
|
|
|
|
{
|
|
|
|
"csrfmiddlewaretoken": CSRF_TOKEN,
|
|
|
|
"quantity": dest[3],
|
|
|
|
"amount": $("#amount").val(),
|
|
|
|
"reason": reason,
|
|
|
|
"valid": true,
|
|
|
|
"polymorphic_ctype": {{ special_polymorphic_ctype }},
|
|
|
|
"resourcetype": "SpecialTransaction",
|
|
|
|
"source": source,
|
|
|
|
"destination": dest,
|
|
|
|
"last_name": $("#last_name").val(),
|
|
|
|
"first_name": $("#first_name").val(),
|
|
|
|
"bank": $("#bank").val()
|
|
|
|
}, function () {
|
|
|
|
let msgDiv = $("#messages");
|
|
|
|
let html = msgDiv.html();
|
|
|
|
html += "<div class=\"alert alert-success\">Le crédit/retrait a bien été effectué !</div>\n";
|
|
|
|
msgDiv.html(html);
|
|
|
|
|
|
|
|
reset();
|
|
|
|
}).fail(function (err) {
|
|
|
|
let msgDiv = $("#messages");
|
|
|
|
let html = msgDiv.html();
|
|
|
|
html += "<div class=\"alert alert-danger\">Le crédit/transfert a échoué : " + err.responseText + "</div>\n";
|
|
|
|
msgDiv.html(html);
|
|
|
|
|
|
|
|
reset();
|
|
|
|
});
|
2020-03-13 00:57:32 +00:00
|
|
|
}
|
2020-03-12 22:12:49 +00:00
|
|
|
});
|
|
|
|
</script>
|
2019-08-10 17:00:16 +00:00
|
|
|
{% endblock %}
|