Добавил проведение приходов по строкам документа

This commit is contained in:
Kashey committed 2026-10-17 12:13:04 +03:00
1 parent 9742b55e43
commit 54723f5310
2 files changed
+25 -2

No files matched your search

+7
View File
@@ -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
View File
@@ -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<>();