Добавил проведение перемещений и перенес проверки операций в модель
This commit is contained in:
1 parent
a1c4990243
commit
0775fef034
5 files changed
+85
-33
No files matched your search
+11
-31
@@ -15,10 +15,6 @@ public class Ledger {
|
||||
throw new IllegalArgumentException("Не указан документ");
|
||||
}
|
||||
|
||||
if (operation.getType() == null) {
|
||||
throw new IllegalArgumentException("Не указан тип операции");
|
||||
}
|
||||
|
||||
OperationType operationType = operation.getType();
|
||||
|
||||
switch (operationType) {
|
||||
@@ -35,7 +31,7 @@ public class Ledger {
|
||||
break;
|
||||
|
||||
case MOVEMENT:
|
||||
//do something
|
||||
postMovement(operation);
|
||||
break;
|
||||
default:
|
||||
//do something
|
||||
@@ -44,7 +40,6 @@ public class Ledger {
|
||||
|
||||
private void postOpeningBalance(Operation operation) {
|
||||
|
||||
validateOpeningBalance(operation);
|
||||
ArrayList<LedgerEntry> newEntries = new ArrayList<>();
|
||||
LedgerEntry ledgerEntry = new LedgerEntry(operation.getDate(), operation.getId(),
|
||||
operation.getDestinationAccount(), null, operation.getTotal());
|
||||
@@ -53,33 +48,18 @@ public class Ledger {
|
||||
entries.addAll(newEntries);
|
||||
}
|
||||
|
||||
private void validateOpeningBalance(Operation operation) {
|
||||
private void postMovement(Operation operation) {
|
||||
|
||||
if (operation == null) {
|
||||
throw new IllegalArgumentException("Не указан документ");
|
||||
}
|
||||
ArrayList<LedgerEntry> newEntries = new ArrayList<>();
|
||||
LedgerEntry ledgerEntryExpense = new LedgerEntry(operation.getDate(), operation.getId(),
|
||||
operation.getSourceAccount(), null, operation.getTotal().negate());
|
||||
newEntries.add(ledgerEntryExpense);
|
||||
LedgerEntry ledgerEntryIncome = new LedgerEntry(operation.getDate(), operation.getId(),
|
||||
operation.getDestinationAccount(), null, operation.getTotal());
|
||||
newEntries.add(ledgerEntryIncome);
|
||||
|
||||
if (operation.getId() == null) {
|
||||
throw new IllegalArgumentException("Не указан ID документа");
|
||||
}
|
||||
|
||||
if (operation.getDate() == null) {
|
||||
throw new IllegalArgumentException("Не указана дата документа");
|
||||
}
|
||||
|
||||
if (operation.getType() != OperationType.OPENING_BALANCE) {
|
||||
throw new IllegalArgumentException(
|
||||
"Ожидается документ ввода начального остатка"
|
||||
);
|
||||
}
|
||||
|
||||
if (operation.getDestinationAccount() == null) {
|
||||
throw new IllegalArgumentException("Не указан счёт-приёмник");
|
||||
}
|
||||
|
||||
if (operation.getTotal() == null) {
|
||||
throw new IllegalArgumentException("Не указана сумма документа");
|
||||
}
|
||||
entries.removeIf(entry -> entry.getOperationId().equals(operation.getId()));
|
||||
entries.addAll(newEntries);
|
||||
}
|
||||
|
||||
public BigDecimal balance(Account account, LocalDate date) {
|
||||
|
||||
Reference in new issue
Block a user