Initial commit
This commit is contained in:
commit
357f494a56
14 files changed
+230
No files matched your search
@@ -0,0 +1,33 @@
|
||||
package service;
|
||||
|
||||
import model.Account;
|
||||
import model.LedgerEntry;
|
||||
import model.Operation;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class Ledger {
|
||||
private final ArrayList<LedgerEntry> entries = new ArrayList<>();
|
||||
|
||||
public void post(Operation operation) {
|
||||
|
||||
}
|
||||
|
||||
public BigDecimal balance(Account account, LocalDate date) {
|
||||
|
||||
BigDecimal result = BigDecimal.ZERO;
|
||||
|
||||
for (LedgerEntry entry: entries) {
|
||||
boolean sameAccount = entry.getAccount().equals(account);
|
||||
boolean withinPeriod = !entry.getDate().isAfter(date);
|
||||
|
||||
if (sameAccount && withinPeriod) {
|
||||
result = result.add(entry.getDeltaAmount());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user