1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2025-06-30 05:01:10 +02:00

💄 Warn users when a note balance is bellow 0 or -50 €

This commit is contained in:
Yohann D'ANELLO
2020-08-01 12:12:56 +02:00
parent 82aa0182e3
commit 59bfdbbfc7
2 changed files with 72 additions and 17 deletions

View File

@ -156,7 +156,7 @@ function reset() {
function consumeAll() {
notes_display.forEach(function(note_display) {
buttons.forEach(function(button) {
consume(note_display.note.id, note_display.name, button.dest, button.quantity * note_display.quantity, button.amount,
consume(note_display.note, note_display.name, button.dest, button.quantity * note_display.quantity, button.amount,
button.name + " (" + button.category_name + ")", button.type, button.category_id, button.id);
});
});
@ -164,7 +164,7 @@ function consumeAll() {
/**
* Create a new transaction from a button through the API.
* @param source The note that paid the item (type: int)
* @param source The note that paid the item (type: note)
* @param source_alias The alias used for the source (type: str)
* @param dest The note that sold the item (type: int)
* @param quantity The quantity sold (type: int)
@ -184,13 +184,25 @@ function consume(source, source_alias, dest, quantity, amount, reason, type, cat
"valid": true,
"polymorphic_ctype": type,
"resourcetype": "RecurrentTransaction",
"source": source,
"source": source.id,
"source_alias": source_alias,
"destination": dest,
"category": category,
"template": template
}, reset).fail(function (e) {
$.post("/api/note/transaction/transaction/",
})
.done(function () {
if (!isNaN(source.balance)) {
let newBalance = source.balance - quantity * amount;
if (newBalance <= -5000)
addMsg("Attention, la note émettrice " + source_alias + " passe en négatif sévère.",
"danger", 10000);
else if (newBalance < 0)
addMsg("Attention, la note émettrice " + source_alias + " passe en négatif.",
"warning", 10000);
}
reset();
}).fail(function (e) {
$.post("/api/note/transaction/transaction/",
{
"csrfmiddlewaretoken": CSRF_TOKEN,
"quantity": quantity,