"Fix" inconsistents amounts/balances
This commit is contained in:
parent
5ab7519c8d
commit
ba1eabe240
4 changed files with 40 additions and 19 deletions
|
@ -430,11 +430,12 @@ input[type=number]::-webkit-outer-spin-button {
|
|||
color:#FFF;
|
||||
}
|
||||
|
||||
.basket_summary table {
|
||||
.basket_summary {
|
||||
margin: 0 auto;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.basket_summary table tr td:first-child {
|
||||
.basket_summary .name {
|
||||
padding-right: 15px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
|
|
@ -945,7 +945,7 @@ class PurchaseBasket extends Purchase {
|
|||
let reduc_divisor = 1;
|
||||
if (kpsul.account_manager.account.is_cof)
|
||||
reduc_divisor += Config.get('subvention_cof') / 100;
|
||||
return amount_ukf / reduc_divisor;
|
||||
return Math.round((amount_ukf / reduc_divisor)*100)/100;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1808,7 +1808,7 @@ class ArticleFormatter extends Formatter {
|
|||
* <tt>s.price</tt> converted to UKF.
|
||||
*/
|
||||
static prop_price(s) {
|
||||
return amountToUKF(s.price, true);
|
||||
return amountToUKF(s.price);
|
||||
}
|
||||
|
||||
static get _data_stock() {
|
||||
|
@ -1895,7 +1895,7 @@ class OpegroupFormatter extends HistoryGroupFormatter {
|
|||
* <tt>a.amount</tt> displayed according to <tt>a.is_cof</tt> and <tt>a.trigramme</tt> values.
|
||||
*/
|
||||
static prop_amount(a) {
|
||||
return amountDisplay(a.amount, a.is_cof, a.trigramme);
|
||||
return amountDisplay(a.amount, a.is_cof, a.trigramme, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1943,7 +1943,7 @@ class OperationFormatter extends Formatter {
|
|||
* <tt>a.amount</tt> displayed according to <tt>a.is_cof</tt> and <tt>a.trigramme</tt> values.
|
||||
*/
|
||||
static prop_amount(a) {
|
||||
return amountDisplay(a.amount, a.opegroup.is_cof, a.opegroup.trigramme);
|
||||
return amountDisplay(a.amount, a.opegroup.is_cof, a.opegroup.trigramme, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1982,7 +1982,7 @@ class PurchaseFormatter extends OperationFormatter {
|
|||
*/
|
||||
static prop_addcost(a) {
|
||||
if (a.addcost_for) {
|
||||
return '('+amountDisplay(a.addcost_amount, a.opegroup.is_cof)
|
||||
return '('+amountDisplay(a.addcost_amount, a.opegroup.is_cof, a.addcost_for, false)
|
||||
+'UKF pour '+a.addcost_for+')';
|
||||
} else {
|
||||
return '';
|
||||
|
@ -2014,6 +2014,7 @@ class SpecialOpeFormatter extends OperationFormatter {
|
|||
static prop_infos2(a) {
|
||||
return SpecialOperation.verbose_types[a.type] || '';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2047,7 +2048,7 @@ class ItemBasketFormatter extends Formatter {
|
|||
|
||||
static prop_amount(o) {
|
||||
let account = kpsul.account_manager.account;
|
||||
return amountDisplay(o.amount, account.is_cof, account.trigramme);
|
||||
return amountDisplay(o.amount, account.is_cof, account.trigramme, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -240,10 +240,10 @@ function dateUTCToParis(date) {
|
|||
return moment.tz(date, 'UTC').tz('Europe/Paris');
|
||||
}
|
||||
|
||||
function amountDisplay(amount, is_cof=false, tri='') {
|
||||
function amountDisplay(amount, is_cof=false, tri='', account=true) {
|
||||
if (tri == 'LIQ')
|
||||
return (- amount).toFixed(2) +'€';
|
||||
return amountToUKF(amount, is_cof);
|
||||
return amountToUKF(amount, is_cof, account).toString();
|
||||
}
|
||||
|
||||
function amountToUKF(amount, is_cof=false, account=false) {
|
||||
|
|
|
@ -707,7 +707,7 @@ class BasketManager {
|
|||
let total = 0;
|
||||
for (let ope of this.data.roots)
|
||||
total += ope.amount;
|
||||
return total;
|
||||
return Number(Math.round(total*100)/100);
|
||||
}
|
||||
|
||||
add_purchase(article, nb) {
|
||||
|
@ -782,29 +782,48 @@ class BasketSummary {
|
|||
}
|
||||
|
||||
update_infos() {
|
||||
let html = '<table class="text-right">';
|
||||
let items = [];
|
||||
|
||||
if (!this.basket.is_empty() && !kpsul.account_manager.is_empty()) {
|
||||
let account = kpsul.account_manager.account;
|
||||
let amount = this.basket.total_amount();
|
||||
html += '<tr><td>Total</td><td>' + amountDisplay(amount, account.is_cof, account.trigramme) + '</td></tr>';
|
||||
|
||||
let total_str = amountDisplay(amount, account.is_cof, account.trigramme, false);
|
||||
items.push(['Total', total_str]);
|
||||
|
||||
if (account.trigramme == "LIQ") {
|
||||
let abs_amount = Math.abs(amount);
|
||||
for (let given of [5, 10, 20])
|
||||
if (abs_amount < given)
|
||||
html += this.rendu(abs_amount, given);
|
||||
items.push(this.rendu(abs_amount, given));
|
||||
} else {
|
||||
let new_balance = account.balance + amount;
|
||||
html += '<tr><td>Nouveau solde</td><td>' + amountDisplay(new_balance, account.is_cof) + '</td></tr>';
|
||||
|
||||
let new_balance_str = amountDisplay(
|
||||
new_balance, account.is_cof, account.trigramme);
|
||||
items.push(['Nouveau solde', new_balance_str]);
|
||||
|
||||
if (new_balance < 0)
|
||||
html += '<tr><td>Manque</td><td>' + (- new_balance).toFixed(2) + '€</td></tr>';
|
||||
items.push(['Manque', (- new_balance).toFixed(2)+'€']);
|
||||
}
|
||||
}
|
||||
html += '</table>';
|
||||
this._$container.html(html);
|
||||
|
||||
this._$container.html(this._$render(items));
|
||||
}
|
||||
|
||||
rendu(amount, given) {
|
||||
return '<tr><td>Sur ' + given.toString() +'€</td><td>' + (given - amount).toFixed(2) + '€</td></tr>';
|
||||
return [given.toString()+'€', (given - amount).toFixed(2)+'€'];
|
||||
}
|
||||
|
||||
_$render(items) {
|
||||
let $elt = $('<table>');
|
||||
for (let item of items)
|
||||
this._$render_item(item[0], item[1]).appendTo($elt);
|
||||
return $elt;
|
||||
}
|
||||
|
||||
_$render_item(name, value) {
|
||||
return $('<tr><td class="name">'+name+'</td><td class="value">'+value+'</td></tr>');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue