Skip to content

Commit

Permalink
show negative transfer amount when we are the sender
Browse files Browse the repository at this point in the history
  • Loading branch information
zefir-git committed Jul 25, 2023
1 parent a8d1efa commit eef0ddb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
9 changes: 0 additions & 9 deletions src/main/java/pro/cloudnode/smp/bankaccounts/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,6 @@ public Transaction(ResultSet rs) throws SQLException, Exception {
this(rs.getInt("id"), Account.get(rs.getString("from")).orElse(new Account.ClosedAccount()), Account.get(rs.getString("to")).orElse(new Account.ClosedAccount()), rs.getBigDecimal("amount"), rs.getTimestamp("time"), rs.getString("description"), rs.getString("instrument"));
}

/**
* Get other account
* @param account The account not to return
* @return The other account involved in the transaction
*/
public Account getOther(Account account) {
return account.id.equals(from.id) ? to : from;
}

/**
* Insert transaction in the database
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,14 +608,16 @@ public static void transactionsHeaderFooter(@NotNull CommandSender sender, @NotN
public static Component transactionPlaceholders(@NotNull CommandSender sender, @NotNull Transaction transaction, @NotNull Account account, @NotNull String message) {
final SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
boolean isSender = transaction.from.id.equals(account.id);
final BigDecimal amount = isSender ? transaction.amount.negate() : transaction.amount;
final Account other = isSender ? transaction.to : transaction.from;
message = message
.replace("<amount>", transaction.amount.toPlainString())
.replace("<amount-formatted>", BankAccounts.formatCurrency(transaction.amount))
.replace("<amount-short>", BankAccounts.formatCurrencyShort(transaction.amount))
.replace("<amount>", amount.toPlainString())
.replace("<amount-formatted>", BankAccounts.formatCurrency(amount))
.replace("<amount-short>", BankAccounts.formatCurrencyShort(amount))
.replace("<description>", transaction.description == null ? "<gray><i>no description</i></gray>" : transaction.description)
.replace("<transaction-id>", String.valueOf(transaction.getId()))
.replace("<full_date>", sdf.format(transaction.time) + " UTC");
Account other = transaction.getOther(account);
message = accountPlaceholdersString(message, new HashMap<>() {{
put("", account);
put("other", other);
Expand Down

0 comments on commit eef0ddb

Please sign in to comment.