06/03 Optimize code, fix account sync the current balances instead of credit lines
This commit is contained in:
@@ -224,15 +224,23 @@ function refreshBalance(taId, btn) {
|
||||
btn.disabled = false;
|
||||
btn.innerHTML = '<i class="bi bi-arrow-clockwise"></i>';
|
||||
|
||||
if (data.available != null) {
|
||||
if (data.balance != null || data.available != null) {
|
||||
const sym = '{{ current_user.currency_symbol }}';
|
||||
const fmt = v => sym + parseFloat(v).toLocaleString(undefined, {minimumFractionDigits:2, maximumFractionDigits:2});
|
||||
const fmt = v => {
|
||||
const n = parseFloat(v);
|
||||
const abs = Math.abs(n).toLocaleString(undefined, {minimumFractionDigits:2, maximumFractionDigits:2});
|
||||
return (n < 0 ? '-' : '') + sym + abs;
|
||||
};
|
||||
|
||||
// 'balance' is the correct value for the account type (ledger for credit cards,
|
||||
// available for bank accounts). Fall back to 'available' for older responses.
|
||||
const displayVal = data.balance != null ? data.balance : data.available;
|
||||
|
||||
// Update inline balance display
|
||||
const balEl = document.getElementById('bal-' + taId);
|
||||
if (balEl) {
|
||||
balEl.textContent = fmt(data.available);
|
||||
balEl.style.color = '#10b981';
|
||||
balEl.textContent = fmt(displayVal);
|
||||
balEl.style.color = displayVal < 0 ? '#ef4444' : '#10b981';
|
||||
setTimeout(() => balEl.style.color = '', 2500);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user