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 %}
|
|
|
|
|
2020-03-16 11:11:16 +00:00
|
|
|
{% load i18n static django_tables2 %}
|
2019-07-17 11:53:58 +00:00
|
|
|
|
|
|
|
{% block content %}
|
2020-03-13 00:57:32 +00:00
|
|
|
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-xl-12">
|
2020-03-14 14:36:03 +00:00
|
|
|
<div class="btn-group btn-group-toggle" style="width: 100%; padding: 0 0 2em 0" data-toggle="buttons">
|
2020-03-16 12:06:02 +00:00
|
|
|
<label for="type_gift" class="btn btn-sm btn-outline-primary active">
|
2020-03-14 14:13:58 +00:00
|
|
|
<input type="radio" name="transaction_type" id="type_gift" checked>
|
2020-03-14 16:40:31 +00:00
|
|
|
{% trans "Gift" %}
|
2020-03-14 14:13:58 +00:00
|
|
|
</label>
|
2020-03-16 12:06:02 +00:00
|
|
|
<label for="type_transfer" class="btn btn-sm btn-outline-primary">
|
2020-03-14 14:13:58 +00:00
|
|
|
<input type="radio" name="transaction_type" id="type_transfer">
|
2020-03-14 16:40:31 +00:00
|
|
|
{% trans "Transfer" %}
|
2020-03-14 14:13:58 +00:00
|
|
|
</label>
|
2020-03-16 12:06:02 +00:00
|
|
|
<label for="type_credit" class="btn btn-sm btn-outline-primary">
|
2020-03-14 14:13:58 +00:00
|
|
|
<input type="radio" name="transaction_type" id="type_credit">
|
2020-03-14 16:40:31 +00:00
|
|
|
{% trans "Credit" %}
|
2020-03-14 14:13:58 +00:00
|
|
|
</label>
|
2020-03-16 12:06:02 +00:00
|
|
|
<label type="type_debit" class="btn btn-sm btn-outline-primary">
|
2020-03-14 14:13:58 +00:00
|
|
|
<input type="radio" name="transaction_type" id="type_debit">
|
2020-03-14 16:40:31 +00:00
|
|
|
{% trans "Debit" %}
|
2020-03-14 14:13:58 +00:00
|
|
|
</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-16 11:26:41 +00:00
|
|
|
<div class="col-md-4" 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">
|
2020-03-14 16:40:31 +00:00
|
|
|
{% trans "Select emitters" %}
|
2020-03-12 22:12:49 +00:00
|
|
|
</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-16 11:26:41 +00:00
|
|
|
<div class="col-xl-4" id="note_infos_div">
|
|
|
|
<div class="card border-success shadow mb-4">
|
|
|
|
<img src="/media/pic/default.png"
|
|
|
|
id="profile_pic" alt="" class="img-fluid rounded mx-auto d-block">
|
|
|
|
<div class="card-body text-center">
|
|
|
|
<span id="user_note"></span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="col-md-4" id="external_div" style="display: none;">
|
2020-03-14 14:13:58 +00:00
|
|
|
<div class="card border-success shadow mb-4">
|
|
|
|
<div class="card-header">
|
|
|
|
<p class="card-text font-weight-bold">
|
2020-03-14 16:40:31 +00:00
|
|
|
{% trans "External payment" %}
|
2020-03-14 14:13:58 +00:00
|
|
|
</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">
|
2020-03-14 16:40:31 +00:00
|
|
|
<label for="credit_type">{% trans "Transfer type" %} :</label>
|
2020-03-14 14:13:58 +00:00
|
|
|
<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">
|
2020-03-14 16:40:31 +00:00
|
|
|
<label for="last_name">{% trans "Name" %} :</label>
|
2020-03-14 14:13:58 +00:00
|
|
|
<input type="text" id="last_name" class="form-control" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
|
|
<div class="col-md-12">
|
2020-03-14 16:40:31 +00:00
|
|
|
<label for="first_name">{% trans "First name" %} :</label>
|
2020-03-14 14:13:58 +00:00
|
|
|
<input type="text" id="first_name" class="form-control" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
|
|
<div class="col-md-12">
|
2020-03-14 16:40:31 +00:00
|
|
|
<label for="bank">{% trans "Bank" %} :</label>
|
2020-03-14 14:13:58 +00:00
|
|
|
<input type="text" id="bank" class="form-control" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2020-03-16 11:26:41 +00:00
|
|
|
<div class="col-md-8" id="dests_div">
|
2020-03-12 22:12:49 +00:00
|
|
|
<div class="card border-info shadow mb-4">
|
|
|
|
<div class="card-header">
|
2020-03-14 14:36:03 +00:00
|
|
|
<p class="card-text font-weight-bold" id="dest_title">
|
2020-03-14 16:40:31 +00:00
|
|
|
{% trans "Select receivers" %}
|
2020-03-12 22:12:49 +00:00
|
|
|
</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>
|
2020-03-16 11:11:16 +00:00
|
|
|
|
|
|
|
<div class="card shadow mb-4" id="history">
|
|
|
|
<div class="card-header">
|
|
|
|
<p class="card-text font-weight-bold">
|
|
|
|
{% trans "Recent transactions history" %}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
{% render_table table %}
|
|
|
|
</div>
|
2020-03-12 22:12:49 +00:00
|
|
|
{% 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
|
|
|
|
2020-03-16 11:11:16 +00:00
|
|
|
function refreshHistory() {
|
|
|
|
$("#history").load("/note/transfer/ #history");
|
|
|
|
}
|
|
|
|
|
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-16 11:11:16 +00:00
|
|
|
refreshHistory();
|
2020-03-14 14:13:58 +00:00
|
|
|
}
|
2020-03-12 22:12:49 +00:00
|
|
|
|
|
|
|
$(document).ready(function() {
|
2020-03-14 14:36:03 +00:00
|
|
|
autoCompleteNote("source_note", "source_alias_matched", "source_note_list", sources, sources_notes_display,
|
2020-03-16 11:26:41 +00:00
|
|
|
"source_alias", "source_note", "user_note", "profile_pic");
|
2020-03-14 14:36:03 +00:00
|
|
|
autoCompleteNote("dest_note", "dest_alias_matched", "dest_note_list", dests, dests_notes_display,
|
2020-03-16 11:26:41 +00:00
|
|
|
"dest_alias", "dest_note", "user_note", "profile_pic", function() {
|
2020-03-14 14:36:03 +00:00
|
|
|
let last = dests_notes_display[dests_notes_display.length - 1];
|
|
|
|
dests_notes_display.length = 0;
|
|
|
|
dests_notes_display.push(last);
|
|
|
|
|
2020-03-16 11:11:16 +00:00
|
|
|
last.quantity = 1;
|
2020-03-14 14:36:03 +00:00
|
|
|
|
2020-03-16 11:11:16 +00:00
|
|
|
$.getJSON("/api/user/" + last.note.user + "/", function(user) {
|
2020-03-14 14:36:03 +00:00
|
|
|
$("#last_name").val(user.last_name);
|
|
|
|
$("#first_name").val(user.first_name);
|
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
2020-03-16 12:06:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Ensure we begin in gift mode. Removing these lines may cause problems when reloading.
|
|
|
|
$("#type_gift").prop('checked', 'true');
|
|
|
|
$("#type_transfer").removeAttr('checked');
|
|
|
|
$("#type_credit").removeAttr('checked');
|
|
|
|
$("#type_debit").removeAttr('checked');
|
|
|
|
$("label[for='type_gift']").attr('class', 'btn btn-sm btn-outline-primary');
|
|
|
|
$("label[for='type_transfer']").attr('class', 'btn btn-sm btn-outline-primary');
|
|
|
|
$("label[for='type_debit']").attr('class', 'btn btn-sm btn-outline-primary');
|
2020-03-12 22:12:49 +00:00
|
|
|
});
|
|
|
|
|
2020-03-14 14:13:58 +00:00
|
|
|
$("#type_gift").click(function() {
|
|
|
|
$("#emitters_div").hide();
|
|
|
|
$("#external_div").hide();
|
2020-03-16 11:26:41 +00:00
|
|
|
$("#dests_div").attr('class', 'col-md-8');
|
2020-03-14 16:40:31 +00:00
|
|
|
$("#dest_title").text("{% trans "Select receivers" %}");
|
2020-03-14 14:13:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$("#type_transfer").click(function() {
|
|
|
|
$("#emitters_div").show();
|
|
|
|
$("#external_div").hide();
|
2020-03-16 11:26:41 +00:00
|
|
|
$("#dests_div").attr('class', 'col-md-4');
|
2020-03-14 16:40:31 +00:00
|
|
|
$("#dest_title").text("{% trans "Select receivers" %}");
|
2020-03-14 14:13:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$("#type_credit").click(function() {
|
|
|
|
$("#emitters_div").hide();
|
|
|
|
$("#external_div").show();
|
2020-03-16 11:26:41 +00:00
|
|
|
$("#dests_div").attr('class', 'col-md-4');
|
2020-03-14 16:40:31 +00:00
|
|
|
$("#dest_title").text("{% trans "Credit note" %}");
|
2020-03-14 14:13:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$("#type_debit").click(function() {
|
|
|
|
$("#emitters_div").hide();
|
|
|
|
$("#external_div").show();
|
2020-03-16 11:26:41 +00:00
|
|
|
$("#dests_div").attr('class', 'col-md-4');
|
2020-03-14 16:40:31 +00:00
|
|
|
$("#dest_title").text("{% trans "Debit note" %}");
|
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,
|
2020-03-16 11:11:16 +00:00
|
|
|
"quantity": dest.quantity,
|
2020-03-13 00:57:32 +00:00
|
|
|
"amount": $("#amount").val(),
|
2020-03-16 11:11:16 +00:00
|
|
|
"reason": $("#reason").val(),
|
2020-03-13 00:57:32 +00:00
|
|
|
"valid": true,
|
|
|
|
"polymorphic_ctype": {{ polymorphic_ctype }},
|
|
|
|
"resourcetype": "Transaction",
|
2020-03-16 11:11:16 +00:00
|
|
|
"type": "gift",
|
2020-03-13 00:57:32 +00:00
|
|
|
"source": {{ user.note.id }},
|
2020-03-16 11:11:16 +00:00
|
|
|
"destination": dest.id
|
2020-03-13 00:57:32 +00:00
|
|
|
}, function () {
|
2020-03-16 11:11:16 +00:00
|
|
|
addMsg("Le transfert de "
|
|
|
|
+ pretty_money(dest.quantity * $("#amount").val()) + " de votre note "
|
|
|
|
+ " vers la note " + dest.name + " a été fait avec succès !", "success");
|
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-16 11:11:16 +00:00
|
|
|
addMsg("Le transfert de "
|
|
|
|
+ pretty_money(dest.quantity * $("#amount").val()) + " de votre note "
|
|
|
|
+ " vers la note " + dest.name + " a échoué : " + err.responseText, "danger");
|
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,
|
2020-03-16 11:11:16 +00:00
|
|
|
"quantity": source.quantity * dest.quantity,
|
2020-03-13 00:57:32 +00:00
|
|
|
"amount": $("#amount").val(),
|
2020-03-16 11:11:16 +00:00
|
|
|
"reason": $("#reason").val(),
|
2020-03-13 00:57:32 +00:00
|
|
|
"valid": true,
|
|
|
|
"polymorphic_ctype": {{ polymorphic_ctype }},
|
|
|
|
"resourcetype": "Transaction",
|
2020-03-16 11:11:16 +00:00
|
|
|
"type": "transfer",
|
|
|
|
"source": source.id,
|
|
|
|
"destination": dest.id
|
2020-03-13 00:57:32 +00:00
|
|
|
}, function () {
|
2020-03-16 11:11:16 +00:00
|
|
|
addMsg("Le transfert de "
|
|
|
|
+ pretty_money(source.quantity * dest.quantity * $("#amount").val()) + " de la note " + source.name
|
|
|
|
+ " vers la note " + dest.name + " a été fait avec succès !", "success");
|
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-16 11:11:16 +00:00
|
|
|
addMsg("Le transfert de "
|
|
|
|
+ pretty_money(source.quantity * dest.quantity * $("#amount").val()) + " de la note " + source.name
|
|
|
|
+ " vers la note " + dest.name + " a échoué : " + err.responseText, "danger");
|
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-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();
|
2020-03-16 11:11:16 +00:00
|
|
|
let user_note = dests_notes_display[0].id;
|
|
|
|
let given_reason = $("#reason").val();
|
|
|
|
let source, dest, reason, type;
|
2020-03-14 14:13:58 +00:00
|
|
|
if ($("#type_credit").is(':checked')) {
|
|
|
|
source = special_note;
|
|
|
|
dest = user_note;
|
2020-03-16 11:11:16 +00:00
|
|
|
type = "credit";
|
|
|
|
reason = "Crédit " + $("#credit_type option:selected").text().toLowerCase();
|
|
|
|
if (given_reason.length > 0)
|
|
|
|
reason += " (" + given_reason + ")";
|
2020-03-14 14:13:58 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
source = user_note;
|
|
|
|
dest = special_note;
|
2020-03-16 11:11:16 +00:00
|
|
|
type = "debit";
|
|
|
|
reason = "Retrait " + $("#credit_type option:selected").text().toLowerCase();
|
|
|
|
if (given_reason.length > 0)
|
|
|
|
reason += " (" + given_reason + ")";
|
2020-03-14 14:13:58 +00:00
|
|
|
}
|
|
|
|
$.post("/api/note/transaction/transaction/",
|
|
|
|
{
|
|
|
|
"csrfmiddlewaretoken": CSRF_TOKEN,
|
2020-03-16 11:11:16 +00:00
|
|
|
"quantity": 1,
|
2020-03-14 14:13:58 +00:00
|
|
|
"amount": $("#amount").val(),
|
|
|
|
"reason": reason,
|
|
|
|
"valid": true,
|
|
|
|
"polymorphic_ctype": {{ special_polymorphic_ctype }},
|
|
|
|
"resourcetype": "SpecialTransaction",
|
2020-03-16 11:11:16 +00:00
|
|
|
"type": type,
|
2020-03-14 14:13:58 +00:00
|
|
|
"source": source,
|
|
|
|
"destination": dest,
|
|
|
|
"last_name": $("#last_name").val(),
|
|
|
|
"first_name": $("#first_name").val(),
|
|
|
|
"bank": $("#bank").val()
|
|
|
|
}, function () {
|
2020-03-16 11:11:16 +00:00
|
|
|
addMsg("Le crédit/retrait a bien été effectué !", "success");
|
2020-03-14 14:13:58 +00:00
|
|
|
reset();
|
|
|
|
}).fail(function (err) {
|
2020-03-16 11:11:16 +00:00
|
|
|
addMsg("Le crédit/transfert a échoué : " + err.responseText, "danger");
|
|
|
|
reset();
|
2020-03-14 14:13:58 +00:00
|
|
|
});
|
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 %}
|