-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.js
61 lines (58 loc) · 2.3 KB
/
ui.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* Number.prototype.format(n, x, s, c)
*
* @param integer n: length of decimal
* @param integer x: length of whole part
* @param mixed s: sections delimiter
* @param mixed c: decimal delimiter
*/
Number.prototype.format = function(n, x, s, c) {
var re = '\\d(?=(\\d{' + (x || 3) + '})+' + (n > 0 ? '\\D' : '$') + ')',
num = this.toFixed(Math.max(0, ~~n));
return (c ? num.replace('.', c) : num).replace(new RegExp(re, 'g'), '$&' + (s || ','));
};
// UI formatting
module.exports = {
shortCardInfo(card)
{
return card.productI18N + ' / ' + card.number + " - " + card.state + " - " + card.type;
},
cardDetail: function(card)
{
var result = "";
result += 'Owner: ' + card.owner + '\n\r';
result += 'Number: ' + card.number + '\n\r';
result += 'Expire: ' + card.expiryDate + '\n\r';
result += 'Type: ' + card.productI18N + '\n\r';
result += 'Credit Card: ' + card.creditCard + '\n\r';
return result;
},
accountNumber: function(account)
{
return account.accountno.number + '/' + account.accountno.bankCode + " - " + account.productI18N
},
transactionDetail: function(transaction)
{
return transaction.amount.value.format(2, 3, '.', ',') + " " + transaction.amount.currency + " - " + transaction.description + "\n\r";
},
cardBalance: function(card){
var result = module.exports.shortCardInfo(card) + "\n\r";
if(card.balance)
{
result += 'Balance: ' + card.balance.value.format(2, 3, '.', ',') + ' ' + card.balance.currency + '\n\r';
}
if(card.outstandingAmount)
{
result += 'Oustanding ammount: ' + card.outstandingAmount.value.format(2, 3, '.', ',') + ' ' + card.outstandingAmount.currency + '\n\r';
}
if(card.limit)
{
result += 'Limit: ' + card.limit.value.format(2, 3, '.', ',') + ' ' + card.limit.currency + '\n\r';
}
result += 'Account: ' + card.mainAccount.accountno.number + '/' + card.mainAccount.accountno.bankCode +'\n\r';
return result;
},
accountBalance(account){
return account.balance.value.format(2, 3, '.', ',') + " " + account.balance.currency
}
};