2 * Copyright © 2021 Damyan Ivanov.
3 * This file is part of MoLe.
4 * MoLe is free software: you can distribute it and/or modify it
5 * under the term of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your opinion), any later version.
9 * MoLe is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License terms for details.
14 * You should have received a copy of the GNU General Public License
15 * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
18 package net.ktnx.mobileledger.model;
20 import android.annotation.SuppressLint;
22 import androidx.annotation.NonNull;
24 import net.ktnx.mobileledger.dao.AccountValueDAO;
25 import net.ktnx.mobileledger.db.Account;
26 import net.ktnx.mobileledger.db.AccountValue;
27 import net.ktnx.mobileledger.db.DB;
29 public class LedgerAmount {
30 private final String currency;
31 private final float amount;
34 public LedgerAmount(float amount, @NonNull String currency) {
35 this.currency = currency;
38 public LedgerAmount(float amount) {
42 static public LedgerAmount fromDBO(AccountValue dbo) {
43 final LedgerAmount ledgerAmount = new LedgerAmount(dbo.getValue(), dbo.getCurrency());
44 ledgerAmount.dbId = dbo.getId();
47 public AccountValue toDBO(Account account) {
48 final AccountValueDAO dao = DB.get()
49 .getAccountValueDAO();
50 AccountValue obj = new AccountValue();
52 obj.setAccountId(account.getId());
54 obj.setCurrency(currency);
59 @SuppressLint("DefaultLocale")
61 public String toString() {
63 return String.format("%,1.2f", amount);
65 return String.format("%s %,1.2f", currency, amount);
67 public void propagateToAccount(@NonNull LedgerAccount acc) {
69 acc.addAmount(amount, currency);
71 acc.addAmount(amount);
73 public String getCurrency() {
76 public float getAmount() {