Добавил проведение приходов по строкам документа
This commit is contained in:
1 parent
9742b55e43
commit
54723f5310
2 files changed
+25
-2
No files matched your search
@@ -31,6 +31,13 @@ public class Main {
|
|||||||
ledger.post(operation5);
|
ledger.post(operation5);
|
||||||
printAccountBalance(card, ledger);
|
printAccountBalance(card, ledger);
|
||||||
printAccountBalance(cash, ledger);
|
printAccountBalance(cash, ledger);
|
||||||
|
Operation operation6 = Operation.income(LocalDate.now(), 504L, card);
|
||||||
|
operationLine = new OperationLine(new Category(4L,"Salary"), new BigDecimal(20000));
|
||||||
|
operation6.addLine(operationLine);
|
||||||
|
ledger.post(operation6);
|
||||||
|
printAccountBalance(card, ledger);
|
||||||
|
printAccountBalance(cash, ledger);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void printAccountBalance(Account account, Ledger ledger){
|
public static void printAccountBalance(Account account, Ledger ledger){
|
||||||
|
|||||||
+18
-2
@@ -26,13 +26,13 @@ public class Ledger {
|
|||||||
postOutflow(operation);
|
postOutflow(operation);
|
||||||
break;
|
break;
|
||||||
case INFLOW:
|
case INFLOW:
|
||||||
//do something
|
postInflow(operation);
|
||||||
break;
|
break;
|
||||||
case MOVEMENT:
|
case MOVEMENT:
|
||||||
postMovement(operation);
|
postMovement(operation);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
//do something
|
throw new IllegalArgumentException("Не поддерживается тип операции: " + operationType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,6 +52,22 @@ public class Ledger {
|
|||||||
entries.addAll(newEntries);
|
entries.addAll(newEntries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void postInflow(Operation operation) {
|
||||||
|
|
||||||
|
if (operation.getLines().isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Документ прихода не содержит строк");
|
||||||
|
}
|
||||||
|
ArrayList<LedgerEntry> newEntries = new ArrayList<>();
|
||||||
|
List<OperationLine> operationLines = operation.getLines();
|
||||||
|
for (OperationLine operationLine : operationLines) {
|
||||||
|
LedgerEntry ledgerEntry = new LedgerEntry(operation.getDate(), operation.getId(),
|
||||||
|
operation.getDestinationAccount(), operationLine.getCategory(), operationLine.getAmount());
|
||||||
|
newEntries.add(ledgerEntry);
|
||||||
|
}
|
||||||
|
entries.removeIf(entry -> entry.getOperationId().equals(operation.getId()));
|
||||||
|
entries.addAll(newEntries);
|
||||||
|
}
|
||||||
|
|
||||||
private void postOpeningBalance(Operation operation) {
|
private void postOpeningBalance(Operation operation) {
|
||||||
|
|
||||||
ArrayList<LedgerEntry> newEntries = new ArrayList<>();
|
ArrayList<LedgerEntry> newEntries = new ArrayList<>();
|
||||||
|
|||||||
Reference in new issue
Block a user