2020-08-09 12:01:59 +00:00
|
|
|
var LOCK = false;
|
2020-08-09 11:19:27 +00:00
|
|
|
|
2020-03-17 17:47:16 +00:00
|
|
|
sources = [];
|
|
|
|
sources_notes_display = [];
|
|
|
|
dests = [];
|
|
|
|
dests_notes_display = [];
|
|
|
|
|
|
|
|
function refreshHistory() {
|
|
|
|
$("#history").load("/note/transfer/ #history");
|
|
|
|
}
|
|
|
|
|
2020-07-30 13:14:13 +00:00
|
|
|
function reset(refresh=true) {
|
2020-03-17 17:47:16 +00:00
|
|
|
sources_notes_display.length = 0;
|
|
|
|
sources.length = 0;
|
|
|
|
dests_notes_display.length = 0;
|
|
|
|
dests.length = 0;
|
|
|
|
$("#source_note_list").html("");
|
|
|
|
$("#dest_note_list").html("");
|
2020-08-01 10:12:56 +00:00
|
|
|
let source_field = $("#source_note");
|
|
|
|
source_field.val("");
|
2020-08-01 21:03:10 +00:00
|
|
|
let event = jQuery.Event("keyup");
|
|
|
|
event.originalEvent = {charCode: 97};
|
|
|
|
source_field.trigger(event);
|
2020-08-01 10:12:56 +00:00
|
|
|
source_field.removeClass('is-invalid');
|
2020-08-21 19:00:46 +00:00
|
|
|
source_field.attr("data-original-title", "").tooltip("hide");
|
2020-08-01 10:12:56 +00:00
|
|
|
let dest_field = $("#dest_note");
|
|
|
|
dest_field.val("");
|
2020-08-01 21:03:10 +00:00
|
|
|
dest_field.trigger(event);
|
2020-08-01 10:12:56 +00:00
|
|
|
dest_field.removeClass('is-invalid');
|
2020-08-21 19:00:46 +00:00
|
|
|
dest_field.attr("data-original-title", "").tooltip("hide");
|
2020-07-31 19:24:23 +00:00
|
|
|
let amount_field = $("#amount");
|
|
|
|
amount_field.val("");
|
|
|
|
amount_field.removeClass('is-invalid');
|
|
|
|
$("#amount-required").html("");
|
|
|
|
let reason_field = $("#reason");
|
|
|
|
reason_field.val("");
|
|
|
|
reason_field.removeClass('is-invalid');
|
|
|
|
$("#reason-required").html("");
|
2020-03-17 17:47:16 +00:00
|
|
|
$("#last_name").val("");
|
|
|
|
$("#first_name").val("");
|
|
|
|
$("#bank").val("");
|
2020-03-19 13:25:43 +00:00
|
|
|
$("#user_note").val("");
|
|
|
|
$("#profile_pic").attr("src", "/media/pic/default.png");
|
2020-08-05 17:52:36 +00:00
|
|
|
$("#profile_pic_link").attr("href", "#");
|
2020-07-30 13:14:13 +00:00
|
|
|
if (refresh) {
|
|
|
|
refreshBalance();
|
|
|
|
refreshHistory();
|
|
|
|
}
|
2020-08-09 11:19:27 +00:00
|
|
|
|
|
|
|
LOCK = false;
|
2020-03-17 17:47:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
2020-04-10 20:43:55 +00:00
|
|
|
/**
|
|
|
|
* If we are in credit/debit mode, check that only one note is entered.
|
|
|
|
* More over, get first name and last name to autocomplete fields.
|
|
|
|
*/
|
|
|
|
function checkUniqueNote() {
|
|
|
|
if ($("#type_credit").is(":checked") || $("#type_debit").is(":checked")) {
|
|
|
|
let arr = $("#type_credit").is(":checked") ? dests_notes_display : sources_notes_display;
|
|
|
|
|
2020-04-10 21:41:13 +00:00
|
|
|
if (arr.length === 0)
|
|
|
|
return;
|
|
|
|
|
2020-04-10 20:43:55 +00:00
|
|
|
let last = arr[arr.length - 1];
|
|
|
|
arr.length = 0;
|
|
|
|
arr.push(last);
|
|
|
|
|
|
|
|
last.quantity = 1;
|
|
|
|
|
|
|
|
if (!last.note.user) {
|
|
|
|
$.getJSON("/api/note/note/" + last.note.id + "/?format=json", function(note) {
|
|
|
|
last.note.user = note.user;
|
2020-03-24 00:34:47 +00:00
|
|
|
$.getJSON("/api/user/" + last.note.user + "/", function(user) {
|
|
|
|
$("#last_name").val(user.last_name);
|
|
|
|
$("#first_name").val(user.first_name);
|
|
|
|
});
|
2020-04-10 20:43:55 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$.getJSON("/api/user/" + last.note.user + "/", function(user) {
|
|
|
|
$("#last_name").val(user.last_name);
|
|
|
|
$("#first_name").val(user.first_name);
|
|
|
|
});
|
2020-03-19 13:25:43 +00:00
|
|
|
}
|
2020-04-10 20:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2020-03-17 17:47:16 +00:00
|
|
|
|
2020-04-10 20:43:55 +00:00
|
|
|
autoCompleteNote("source_note", "source_note_list", sources, sources_notes_display,
|
|
|
|
"source_alias", "source_note", "user_note", "profile_pic", checkUniqueNote);
|
|
|
|
autoCompleteNote("dest_note", "dest_note_list", dests, dests_notes_display,
|
|
|
|
"dest_alias", "dest_note", "user_note", "profile_pic", checkUniqueNote);
|
2020-03-17 17:47:16 +00:00
|
|
|
|
2020-04-10 21:41:13 +00:00
|
|
|
let source = $("#source_note");
|
|
|
|
let dest = $("#dest_note");
|
|
|
|
|
|
|
|
$("#type_transfer").click(function() {
|
2020-08-09 11:19:27 +00:00
|
|
|
if (LOCK)
|
|
|
|
return;
|
|
|
|
|
2020-08-01 08:58:21 +00:00
|
|
|
$("#source_me_div").removeClass('d-none');
|
2020-08-01 10:12:56 +00:00
|
|
|
$("#source_note").removeClass('is-invalid');
|
|
|
|
$("#dest_note").removeClass('is-invalid');
|
2020-04-10 21:41:13 +00:00
|
|
|
$("#special_transaction_div").addClass('d-none');
|
|
|
|
source.attr('disabled', false);
|
|
|
|
$("#source_note_list").removeClass('d-none');
|
|
|
|
dest.attr('disabled', false);
|
|
|
|
$("#dest_note_list").removeClass('d-none');
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#type_credit").click(function() {
|
2020-08-09 11:19:27 +00:00
|
|
|
if (LOCK)
|
|
|
|
return;
|
|
|
|
|
2020-08-01 08:58:21 +00:00
|
|
|
$("#source_me_div").addClass('d-none');
|
2020-08-01 10:12:56 +00:00
|
|
|
$("#source_note").removeClass('is-invalid');
|
|
|
|
$("#dest_note").removeClass('is-invalid');
|
2020-04-10 21:41:13 +00:00
|
|
|
$("#special_transaction_div").removeClass('d-none');
|
|
|
|
$("#source_note_list").addClass('d-none');
|
|
|
|
$("#dest_note_list").removeClass('d-none');
|
|
|
|
source.attr('disabled', true);
|
|
|
|
source.val($("#credit_type option:selected").text());
|
|
|
|
source.tooltip('hide');
|
|
|
|
dest.attr('disabled', false);
|
|
|
|
dest.val('');
|
|
|
|
dest.tooltip('hide');
|
|
|
|
|
|
|
|
if (dests_notes_display.length > 1) {
|
|
|
|
$("#dest_note_list").html('');
|
|
|
|
dests_notes_display.length = 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#type_debit").click(function() {
|
2020-08-09 11:19:27 +00:00
|
|
|
if (LOCK)
|
|
|
|
return;
|
|
|
|
|
2020-08-01 08:58:21 +00:00
|
|
|
$("#source_me_div").addClass('d-none');
|
2020-08-01 10:12:56 +00:00
|
|
|
$("#source_note").removeClass('is-invalid');
|
|
|
|
$("#dest_note").removeClass('is-invalid');
|
2020-04-10 21:41:13 +00:00
|
|
|
$("#special_transaction_div").removeClass('d-none');
|
|
|
|
$("#source_note_list").removeClass('d-none');
|
|
|
|
$("#dest_note_list").addClass('d-none');
|
|
|
|
source.attr('disabled', false);
|
|
|
|
source.val('');
|
|
|
|
source.tooltip('hide');
|
|
|
|
dest.attr('disabled', true);
|
|
|
|
dest.val($("#credit_type option:selected").text());
|
|
|
|
dest.tooltip('hide');
|
|
|
|
|
|
|
|
if (sources_notes_display.length > 1) {
|
|
|
|
$("#source_note_list").html('');
|
|
|
|
sources_notes_display.length = 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#credit_type").change(function() {
|
|
|
|
let type = $("#credit_type option:selected").text();
|
|
|
|
if ($("#type_credit").is(":checked"))
|
|
|
|
source.val(type);
|
|
|
|
else
|
|
|
|
dest.val(type);
|
|
|
|
});
|
2020-03-17 17:47:16 +00:00
|
|
|
|
2020-07-29 20:55:12 +00:00
|
|
|
// Ensure we begin in transfer mode. Removing these lines may cause problems when reloading.
|
|
|
|
let type_transfer = $("#type_transfer"); // Default mode
|
|
|
|
type_transfer.removeAttr('checked');
|
2020-03-17 17:47:16 +00:00
|
|
|
$("#type_credit").removeAttr('checked');
|
|
|
|
$("#type_debit").removeAttr('checked');
|
2020-04-06 05:06:52 +00:00
|
|
|
|
|
|
|
if (location.hash)
|
|
|
|
$("#type_" + location.hash.substr(1)).click();
|
|
|
|
else
|
2020-07-29 20:55:12 +00:00
|
|
|
type_transfer.click();
|
2020-04-06 05:06:52 +00:00
|
|
|
location.hash = "";
|
2020-07-29 20:55:12 +00:00
|
|
|
|
|
|
|
$("#source_me").click(function() {
|
2020-08-09 11:19:27 +00:00
|
|
|
if (LOCK)
|
|
|
|
return;
|
|
|
|
|
2020-07-29 20:55:12 +00:00
|
|
|
// Shortcut to set the current user as the only emitter
|
2020-07-31 19:24:23 +00:00
|
|
|
sources_notes_display.length = 0;
|
|
|
|
sources.length = 0;
|
|
|
|
$("#source_note_list").html("");
|
2020-07-29 20:55:12 +00:00
|
|
|
|
|
|
|
let source_note = $("#source_note");
|
|
|
|
source_note.focus();
|
2020-07-30 13:14:13 +00:00
|
|
|
source_note.val("");
|
2020-07-29 20:55:12 +00:00
|
|
|
let event = jQuery.Event("keyup");
|
2020-07-30 13:14:13 +00:00
|
|
|
event.originalEvent = {charCode: 97};
|
|
|
|
source_note.trigger(event);
|
|
|
|
source_note.val(username);
|
|
|
|
event = jQuery.Event("keyup");
|
|
|
|
event.originalEvent = {charCode: 97};
|
2020-07-29 20:55:12 +00:00
|
|
|
source_note.trigger(event);
|
|
|
|
let fill_note = function() {
|
|
|
|
if (sources.length === 0) {
|
|
|
|
setTimeout(fill_note, 100);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
event = jQuery.Event("keypress");
|
|
|
|
event.originalEvent = {charCode: 13};
|
|
|
|
source_note.trigger(event);
|
|
|
|
|
|
|
|
source_note.tooltip('hide');
|
|
|
|
source_note.val('');
|
|
|
|
$("#dest_note").focus();
|
|
|
|
};
|
|
|
|
fill_note();
|
|
|
|
});
|
2020-03-17 17:47:16 +00:00
|
|
|
});
|
|
|
|
|
2020-04-06 05:06:52 +00:00
|
|
|
$("#btn_transfer").click(function() {
|
2020-08-09 11:19:27 +00:00
|
|
|
if (LOCK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LOCK = true;
|
|
|
|
|
2020-07-31 19:24:23 +00:00
|
|
|
let error = false;
|
|
|
|
|
|
|
|
let amount_field = $("#amount");
|
|
|
|
amount_field.removeClass('is-invalid');
|
|
|
|
$("#amount-required").html("");
|
|
|
|
|
|
|
|
let reason_field = $("#reason");
|
|
|
|
reason_field.removeClass('is-invalid');
|
|
|
|
$("#reason-required").html("");
|
|
|
|
|
|
|
|
if (!amount_field.val() || isNaN(amount_field.val()) || amount_field.val() <= 0) {
|
|
|
|
amount_field.addClass('is-invalid');
|
|
|
|
$("#amount-required").html("<strong>Ce champ est requis et doit comporter un nombre décimal strictement positif.</strong>");
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
|
2020-08-05 14:23:32 +00:00
|
|
|
let amount = Math.floor(100 * amount_field.val());
|
|
|
|
if (amount > 2147483647) {
|
|
|
|
amount_field.addClass('is-invalid');
|
|
|
|
$("#amount-required").html("<strong>Le montant ne doit pas excéder 21474836.47 €.</strong>");
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
|
2020-07-31 19:24:23 +00:00
|
|
|
if (!reason_field.val()) {
|
|
|
|
reason_field.addClass('is-invalid');
|
|
|
|
$("#reason-required").html("<strong>Ce champ est requis.</strong>");
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
|
2020-08-03 08:03:51 +00:00
|
|
|
if (!sources_notes_display.length && !$("#type_credit").is(':checked')) {
|
|
|
|
$("#source_note").addClass('is-invalid');
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dests_notes_display.length && !$("#type_debit").is(':checked')) {
|
|
|
|
$("#dest_note").addClass('is-invalid');
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
|
2020-08-09 11:19:27 +00:00
|
|
|
if (error) {
|
|
|
|
LOCK = false;
|
2020-07-31 19:24:23 +00:00
|
|
|
return;
|
2020-08-09 11:19:27 +00:00
|
|
|
}
|
2020-07-31 19:24:23 +00:00
|
|
|
|
|
|
|
let reason = reason_field.val();
|
|
|
|
|
2020-07-29 20:55:12 +00:00
|
|
|
if ($("#type_transfer").is(':checked')) {
|
2020-07-31 19:24:23 +00:00
|
|
|
// We copy the arrays to ensure that transactions are well-processed even if the form is reset
|
|
|
|
[...sources_notes_display].forEach(function (source) {
|
|
|
|
[...dests_notes_display].forEach(function (dest) {
|
2020-08-06 10:46:44 +00:00
|
|
|
if (source.note.id === dest.note.id) {
|
|
|
|
addMsg("Attention : la transaction de " + pretty_money(amount) + " de la note " + source.name
|
|
|
|
+ " vers la note " + dest.name + " n'a pas été faite car il s'agit de la même note au départ" +
|
|
|
|
" et à l'arrivée.","warning", 10000);
|
2020-08-15 22:04:35 +00:00
|
|
|
LOCK = false;
|
2020-08-06 10:46:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-17 17:47:16 +00:00
|
|
|
$.post("/api/note/transaction/transaction/",
|
|
|
|
{
|
|
|
|
"csrfmiddlewaretoken": CSRF_TOKEN,
|
|
|
|
"quantity": source.quantity * dest.quantity,
|
2020-07-31 19:24:23 +00:00
|
|
|
"amount": amount,
|
|
|
|
"reason": reason,
|
2020-03-17 17:47:16 +00:00
|
|
|
"valid": true,
|
|
|
|
"polymorphic_ctype": TRANSFER_POLYMORPHIC_CTYPE,
|
|
|
|
"resourcetype": "Transaction",
|
2020-03-28 20:31:22 +00:00
|
|
|
"source": source.note.id,
|
2020-03-26 13:45:48 +00:00
|
|
|
"source_alias": source.name,
|
2020-03-28 20:31:22 +00:00
|
|
|
"destination": dest.note.id,
|
2020-03-26 13:45:48 +00:00
|
|
|
"destination_alias": dest.name
|
2020-03-25 14:27:38 +00:00
|
|
|
}).done(function () {
|
2020-08-06 10:36:28 +00:00
|
|
|
if (source.note.membership && source.note.membership.date_end < new Date().toISOString())
|
2020-08-05 18:40:30 +00:00
|
|
|
addMsg("Attention : la note émettrice " + source.name + " n'est plus adhérente.",
|
|
|
|
"danger", 30000);
|
2020-08-06 10:36:28 +00:00
|
|
|
if (dest.note.membership && dest.note.membership.date_end < new Date().toISOString())
|
2020-08-05 18:40:30 +00:00
|
|
|
addMsg("Attention : la note destination " + dest.name + " n'est plus adhérente.",
|
|
|
|
"danger", 30000);
|
|
|
|
|
2020-08-01 10:12:56 +00:00
|
|
|
if (!isNaN(source.note.balance)) {
|
|
|
|
let newBalance = source.note.balance - source.quantity * dest.quantity * amount;
|
|
|
|
if (newBalance <= -5000) {
|
|
|
|
addMsg("Le transfert de "
|
|
|
|
+ pretty_money(source.quantity * dest.quantity * amount) + " de la note "
|
|
|
|
+ source.name + " vers la note " + dest.name + " a été fait avec succès, " +
|
2020-08-01 19:48:18 +00:00
|
|
|
"mais la note émettrice est en négatif sévère.", "danger", 10000);
|
2020-08-01 10:12:56 +00:00
|
|
|
reset();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (newBalance < 0) {
|
|
|
|
addMsg("Le transfert de "
|
|
|
|
+ pretty_money(source.quantity * dest.quantity * amount) + " de la note "
|
|
|
|
+ source.name + " vers la note " + dest.name + " a été fait avec succès, " +
|
2020-08-01 19:48:18 +00:00
|
|
|
"mais la note émettrice est en négatif.", "warning", 10000);
|
2020-08-01 10:12:56 +00:00
|
|
|
reset();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-03-17 17:47:16 +00:00
|
|
|
addMsg("Le transfert de "
|
2020-07-31 19:24:23 +00:00
|
|
|
+ pretty_money(source.quantity * dest.quantity * amount) + " de la note " + source.name
|
2020-07-31 17:43:03 +00:00
|
|
|
+ " vers la note " + dest.name + " a été fait avec succès !", "success", 10000);
|
2020-03-17 17:47:16 +00:00
|
|
|
|
|
|
|
reset();
|
2020-08-05 14:23:32 +00:00
|
|
|
}).fail(function (err) { // do it again but valid = false
|
|
|
|
let errObj = JSON.parse(err.responseText);
|
|
|
|
if (errObj["non_field_errors"]) {
|
|
|
|
addMsg("Le transfert de "
|
|
|
|
+ pretty_money(source.quantity * dest.quantity * amount) + " de la note " + source.name
|
|
|
|
+ " vers la note " + dest.name + " a échoué : " + errObj["non_field_errors"], "danger");
|
2020-08-15 22:02:09 +00:00
|
|
|
LOCK = false;
|
2020-08-05 14:23:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-25 14:27:38 +00:00
|
|
|
$.post("/api/note/transaction/transaction/",
|
|
|
|
{
|
|
|
|
"csrfmiddlewaretoken": CSRF_TOKEN,
|
|
|
|
"quantity": source.quantity * dest.quantity,
|
2020-07-31 19:24:23 +00:00
|
|
|
"amount": amount,
|
|
|
|
"reason": reason,
|
2020-03-25 14:27:38 +00:00
|
|
|
"valid": false,
|
|
|
|
"invalidity_reason": "Solde insuffisant",
|
|
|
|
"polymorphic_ctype": TRANSFER_POLYMORPHIC_CTYPE,
|
|
|
|
"resourcetype": "Transaction",
|
2020-03-28 20:31:22 +00:00
|
|
|
"source": source.note.id,
|
2020-03-26 13:45:48 +00:00
|
|
|
"source_alias": source.name,
|
2020-03-28 20:31:22 +00:00
|
|
|
"destination": dest.note.id,
|
2020-03-26 13:45:48 +00:00
|
|
|
"destination_alias": dest.name
|
2020-03-25 14:27:38 +00:00
|
|
|
}).done(function () {
|
|
|
|
addMsg("Le transfert de "
|
2020-07-31 19:24:23 +00:00
|
|
|
+ pretty_money(source.quantity * dest.quantity * amount) + " de la note " + source.name
|
2020-07-31 17:43:03 +00:00
|
|
|
+ " vers la note " + dest.name + " a échoué : Solde insuffisant", "danger", 10000);
|
2020-08-03 08:54:52 +00:00
|
|
|
reset();
|
2020-03-25 14:27:38 +00:00
|
|
|
}).fail(function (err) {
|
2020-08-05 14:23:32 +00:00
|
|
|
let errObj = JSON.parse(err.responseText);
|
|
|
|
let error = errObj["detail"] ? errObj["detail"] : errObj["non_field_errors"]
|
|
|
|
if (!error)
|
|
|
|
error = err.responseText;
|
2020-03-25 14:27:38 +00:00
|
|
|
addMsg("Le transfert de "
|
2020-07-31 19:24:23 +00:00
|
|
|
+ pretty_money(source.quantity * dest.quantity * amount) + " de la note " + source.name
|
2020-08-05 14:23:32 +00:00
|
|
|
+ " vers la note " + dest.name + " a échoué : " + error, "danger");
|
2020-08-15 22:02:09 +00:00
|
|
|
LOCK = false;
|
2020-03-25 14:27:38 +00:00
|
|
|
});
|
2020-03-17 17:47:16 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else if ($("#type_credit").is(':checked') || $("#type_debit").is(':checked')) {
|
|
|
|
let special_note = $("#credit_type").val();
|
2020-04-10 20:43:55 +00:00
|
|
|
let user_note;
|
2020-08-05 18:40:30 +00:00
|
|
|
let alias;
|
2020-07-31 19:24:23 +00:00
|
|
|
let given_reason = reason;
|
2020-08-01 10:12:56 +00:00
|
|
|
let source_id, dest_id;
|
2020-03-17 17:47:16 +00:00
|
|
|
if ($("#type_credit").is(':checked')) {
|
2020-08-05 18:40:30 +00:00
|
|
|
user_note = dests_notes_display[0].note;
|
|
|
|
alias = dests_notes_display[0].name;
|
2020-08-01 10:12:56 +00:00
|
|
|
source_id = special_note;
|
2020-08-05 18:40:30 +00:00
|
|
|
dest_id = user_note.id;
|
2020-03-17 17:47:16 +00:00
|
|
|
reason = "Crédit " + $("#credit_type option:selected").text().toLowerCase();
|
|
|
|
if (given_reason.length > 0)
|
|
|
|
reason += " (" + given_reason + ")";
|
|
|
|
}
|
|
|
|
else {
|
2020-08-05 18:40:30 +00:00
|
|
|
user_note = sources_notes_display[0].note;
|
|
|
|
alias = sources_notes_display[0].name;
|
|
|
|
source_id = user_note.id;
|
2020-08-01 10:12:56 +00:00
|
|
|
dest_id = special_note;
|
2020-03-17 17:47:16 +00:00
|
|
|
reason = "Retrait " + $("#credit_type option:selected").text().toLowerCase();
|
|
|
|
if (given_reason.length > 0)
|
|
|
|
reason += " (" + given_reason + ")";
|
|
|
|
}
|
|
|
|
$.post("/api/note/transaction/transaction/",
|
|
|
|
{
|
|
|
|
"csrfmiddlewaretoken": CSRF_TOKEN,
|
|
|
|
"quantity": 1,
|
2020-07-31 19:24:23 +00:00
|
|
|
"amount": amount,
|
2020-03-17 17:47:16 +00:00
|
|
|
"reason": reason,
|
|
|
|
"valid": true,
|
|
|
|
"polymorphic_ctype": SPECIAL_TRANSFER_POLYMORPHIC_CTYPE,
|
|
|
|
"resourcetype": "SpecialTransaction",
|
2020-08-01 10:12:56 +00:00
|
|
|
"source": source_id,
|
2020-08-05 18:40:30 +00:00
|
|
|
"source_alias": sources_notes_display.length ? alias : null,
|
2020-08-01 10:12:56 +00:00
|
|
|
"destination": dest_id,
|
2020-08-05 18:40:30 +00:00
|
|
|
"destination_alias": dests_notes_display.length ? alias : null,
|
2020-03-17 17:47:16 +00:00
|
|
|
"last_name": $("#last_name").val(),
|
|
|
|
"first_name": $("#first_name").val(),
|
|
|
|
"bank": $("#bank").val()
|
2020-03-25 14:27:38 +00:00
|
|
|
}).done(function () {
|
2020-07-31 17:43:03 +00:00
|
|
|
addMsg("Le crédit/retrait a bien été effectué !", "success", 10000);
|
2020-08-06 10:36:28 +00:00
|
|
|
if (user_note.membership && user_note.membership.date_end < new Date().toISOString())
|
2020-08-05 18:40:30 +00:00
|
|
|
addMsg("Attention : la note " + alias + " n'est plus adhérente.", "danger", 10000);
|
2020-03-17 17:47:16 +00:00
|
|
|
reset();
|
|
|
|
}).fail(function (err) {
|
2020-08-05 14:23:32 +00:00
|
|
|
let errObj = JSON.parse(err.responseText);
|
|
|
|
let error = errObj["detail"] ? errObj["detail"] : errObj["non_field_errors"]
|
|
|
|
if (!error)
|
|
|
|
error = err.responseText;
|
|
|
|
addMsg("Le crédit/retrait a échoué : " + error, "danger", 10000);
|
2020-08-15 22:02:09 +00:00
|
|
|
LOCK = false;
|
2020-03-17 17:47:16 +00:00
|
|
|
});
|
|
|
|
}
|
2020-03-28 20:31:22 +00:00
|
|
|
});
|