From 54723f5310d1f814604069ae0447ebafc61503ac Mon Sep 17 00:00:00 2001 From: Kashey Date: Sat, 17 Oct 2026 12:13:04 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=D1=85=D0=BE=D0=B4=D0=BE=D0=B2=20=D0=BF=D0=BE?= =?UTF-8?q?=20=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0=D0=BC=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=BA=D1=83=D0=BC=D0=B5=D0=BD=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Main.java | 7 +++++++ src/service/Ledger.java | 20 ++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Main.java b/src/Main.java index fe625bf..6de23ff 100644 --- a/src/Main.java +++ b/src/Main.java @@ -31,6 +31,13 @@ public class Main { ledger.post(operation5); printAccountBalance(card, 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){ diff --git a/src/service/Ledger.java b/src/service/Ledger.java index 6d47c73..816ba37 100644 --- a/src/service/Ledger.java +++ b/src/service/Ledger.java @@ -26,13 +26,13 @@ public class Ledger { postOutflow(operation); break; case INFLOW: - //do something + postInflow(operation); break; case MOVEMENT: postMovement(operation); break; default: - //do something + throw new IllegalArgumentException("Не поддерживается тип операции: " + operationType); } } @@ -52,6 +52,22 @@ public class Ledger { entries.addAll(newEntries); } + private void postInflow(Operation operation) { + + if (operation.getLines().isEmpty()) { + throw new IllegalArgumentException("Документ прихода не содержит строк"); + } + ArrayList newEntries = new ArrayList<>(); + List 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) { ArrayList newEntries = new ArrayList<>();