mirror of https://gitlab.crans.org/bde/nk20
When a transaction can't becreated because the user don't have the permission to take too much money, then we create an invalid transaction
This commit is contained in:
parent
bc3fdbe7a7
commit
5cf75ebf9e
|
@ -327,7 +327,7 @@
|
||||||
"note",
|
"note",
|
||||||
"transaction"
|
"transaction"
|
||||||
],
|
],
|
||||||
"query": "[\"AND\", {\"source\": [\"user\", \"note\"]}, {\"amount__lte\": [\"user\", \"note\", \"balance\"]}]",
|
"query": "[\"AND\", {\"source\": [\"user\", \"note\"]}, [\"OR\", {\"amount__lte\": [\"user\", \"note\", \"balance\"]}, {\"valid\": false}]]",
|
||||||
"type": "add",
|
"type": "add",
|
||||||
"mask": 1,
|
"mask": 1,
|
||||||
"field": "",
|
"field": "",
|
||||||
|
@ -387,7 +387,7 @@
|
||||||
"note",
|
"note",
|
||||||
"recurrenttransaction"
|
"recurrenttransaction"
|
||||||
],
|
],
|
||||||
"query": "[\"AND\", {\"destination\": [\"club\", \"note\"]}, {\"amount__lte\": {\"F\": [\"ADD\", [\"F\", \"source__balance\"], 5000]}}]",
|
"query": "[\"AND\", {\"destination\": [\"club\", \"note\"]}, [\"OR\", {\"amount__lte\": {\"F\": [\"ADD\", [\"F\", \"source__balance\"], 5000]}}, {\"valid\": false}]]",
|
||||||
"type": "add",
|
"type": "add",
|
||||||
"mask": 2,
|
"mask": 2,
|
||||||
"field": "",
|
"field": "",
|
||||||
|
|
|
@ -199,8 +199,26 @@ function consume(source, dest, quantity, amount, reason, type, category, templat
|
||||||
"category": category,
|
"category": category,
|
||||||
"template": template
|
"template": template
|
||||||
}, reset).fail(function (e) {
|
}, reset).fail(function (e) {
|
||||||
|
$.post("/api/note/transaction/transaction/",
|
||||||
|
{
|
||||||
|
"csrfmiddlewaretoken": CSRF_TOKEN,
|
||||||
|
"quantity": quantity,
|
||||||
|
"amount": amount,
|
||||||
|
"reason": reason,
|
||||||
|
"valid": false,
|
||||||
|
"invalidity_reason": "Solde insuffisant",
|
||||||
|
"polymorphic_ctype": type,
|
||||||
|
"resourcetype": "RecurrentTransaction",
|
||||||
|
"source": source,
|
||||||
|
"destination": dest,
|
||||||
|
"category": category,
|
||||||
|
"template": template
|
||||||
|
}).done(function() {
|
||||||
|
reset();
|
||||||
|
addMsg("La transaction n'a pas pu être validée pour cause de solde insuffisant.", "danger");
|
||||||
|
}).fail(function () {
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
addMsg("Une erreur est survenue lors de la transaction : " + e.responseText, "danger");
|
addMsg("Une erreur est survenue lors de la transaction : " + e.responseText, "danger");
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,11 +73,30 @@ $("#transfer").click(function() {
|
||||||
"resourcetype": "Transaction",
|
"resourcetype": "Transaction",
|
||||||
"source": user_id,
|
"source": user_id,
|
||||||
"destination": dest.id
|
"destination": dest.id
|
||||||
}, function () {
|
}).done(function () {
|
||||||
addMsg("Le transfert de "
|
addMsg("Le transfert de "
|
||||||
+ pretty_money(dest.quantity * 100 * $("#amount").val()) + " de votre note "
|
+ pretty_money(dest.quantity * 100 * $("#amount").val()) + " de votre note "
|
||||||
+ " vers la note " + dest.name + " a été fait avec succès !", "success");
|
+ " vers la note " + dest.name + " a été fait avec succès !", "success");
|
||||||
|
|
||||||
|
reset();
|
||||||
|
}).fail(function () {
|
||||||
|
$.post("/api/note/transaction/transaction/",
|
||||||
|
{
|
||||||
|
"csrfmiddlewaretoken": CSRF_TOKEN,
|
||||||
|
"quantity": dest.quantity,
|
||||||
|
"amount": 100 * $("#amount").val(),
|
||||||
|
"reason": $("#reason").val(),
|
||||||
|
"valid": false,
|
||||||
|
"invalidity_reason": "Solde insuffisant",
|
||||||
|
"polymorphic_ctype": TRANSFER_POLYMORPHIC_CTYPE,
|
||||||
|
"resourcetype": "Transaction",
|
||||||
|
"source": user_id,
|
||||||
|
"destination": dest.id
|
||||||
|
}).done(function () {
|
||||||
|
addMsg("Le transfert de "
|
||||||
|
+ pretty_money(dest.quantity * 100 * $("#amount").val()) + " de votre note "
|
||||||
|
+ " vers la note " + dest.name + " a échoué : Solde insuffisant", "danger");
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
}).fail(function (err) {
|
}).fail(function (err) {
|
||||||
addMsg("Le transfert de "
|
addMsg("Le transfert de "
|
||||||
|
@ -87,6 +106,7 @@ $("#transfer").click(function() {
|
||||||
reset();
|
reset();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else if ($("#type_transfer").is(':checked')) {
|
else if ($("#type_transfer").is(':checked')) {
|
||||||
sources_notes_display.forEach(function (source) {
|
sources_notes_display.forEach(function (source) {
|
||||||
|
@ -102,11 +122,30 @@ $("#transfer").click(function() {
|
||||||
"resourcetype": "Transaction",
|
"resourcetype": "Transaction",
|
||||||
"source": source.id,
|
"source": source.id,
|
||||||
"destination": dest.id
|
"destination": dest.id
|
||||||
}, function () {
|
}).done(function () {
|
||||||
addMsg("Le transfert de "
|
addMsg("Le transfert de "
|
||||||
+ pretty_money(source.quantity * dest.quantity * 100 * $("#amount").val()) + " de la note " + source.name
|
+ pretty_money(source.quantity * dest.quantity * 100 * $("#amount").val()) + " de la note " + source.name
|
||||||
+ " vers la note " + dest.name + " a été fait avec succès !", "success");
|
+ " vers la note " + dest.name + " a été fait avec succès !", "success");
|
||||||
|
|
||||||
|
reset();
|
||||||
|
}).fail(function (err) {
|
||||||
|
$.post("/api/note/transaction/transaction/",
|
||||||
|
{
|
||||||
|
"csrfmiddlewaretoken": CSRF_TOKEN,
|
||||||
|
"quantity": source.quantity * dest.quantity,
|
||||||
|
"amount": 100 * $("#amount").val(),
|
||||||
|
"reason": $("#reason").val(),
|
||||||
|
"valid": false,
|
||||||
|
"invalidity_reason": "Solde insuffisant",
|
||||||
|
"polymorphic_ctype": TRANSFER_POLYMORPHIC_CTYPE,
|
||||||
|
"resourcetype": "Transaction",
|
||||||
|
"source": source.id,
|
||||||
|
"destination": dest.id
|
||||||
|
}).done(function () {
|
||||||
|
addMsg("Le transfert de "
|
||||||
|
+ pretty_money(source.quantity * dest.quantity * 100 * $("#amount").val()) + " de la note " + source.name
|
||||||
|
+ " vers la note " + dest.name + " a échoué : Solde insuffisant", "danger");
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
}).fail(function (err) {
|
}).fail(function (err) {
|
||||||
addMsg("Le transfert de "
|
addMsg("Le transfert de "
|
||||||
|
@ -117,6 +156,7 @@ $("#transfer").click(function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
} else if ($("#type_credit").is(':checked') || $("#type_debit").is(':checked')) {
|
} else if ($("#type_credit").is(':checked') || $("#type_debit").is(':checked')) {
|
||||||
let special_note = $("#credit_type").val();
|
let special_note = $("#credit_type").val();
|
||||||
let user_note = dests_notes_display[0].id;
|
let user_note = dests_notes_display[0].id;
|
||||||
|
@ -150,11 +190,11 @@ $("#transfer").click(function() {
|
||||||
"last_name": $("#last_name").val(),
|
"last_name": $("#last_name").val(),
|
||||||
"first_name": $("#first_name").val(),
|
"first_name": $("#first_name").val(),
|
||||||
"bank": $("#bank").val()
|
"bank": $("#bank").val()
|
||||||
}, function () {
|
}).done(function () {
|
||||||
addMsg("Le crédit/retrait a bien été effectué !", "success");
|
addMsg("Le crédit/retrait a bien été effectué !", "success");
|
||||||
reset();
|
reset();
|
||||||
}).fail(function (err) {
|
}).fail(function (err) {
|
||||||
addMsg("Le crédit/transfert a échoué : " + err.responseText, "danger");
|
addMsg("Le crédit/retrait a échoué : " + err.responseText, "danger");
|
||||||
reset();
|
reset();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue