public void bookCharges()

in service/src/main/java/org/apache/fineract/cn/cheque/service/internal/service/helper/AccountingService.java [59:103]


  public void bookCharges(final String sourceAccount, final List<Charge> charges) {

    final Double totalCharges = charges.stream().mapToDouble(charge -> {
      if (charge.getProportional()) {
        this.logger.info("Charges for issuing cheques must be fixed.");
        return 0.00D;
      } else {
        return charge.getAmount();
      }
    }).sum();
    if (totalCharges == 0.00D) {
      return;
    }

    final Account account = this.findAccount(sourceAccount).orElseThrow(AccountNotFoundException::new);
    if (account.getBalance() < totalCharges) {
      throw ServiceException.conflict("Insufficient account balance.");
    }

    final JournalEntry journalEntry = new JournalEntry();
    journalEntry.setTransactionIdentifier("chq-iss-" + UUID.randomUUID().toString());
    journalEntry.setTransactionDate(DateConverter.toIsoString(LocalDateTime.now(Clock.systemUTC())));
    journalEntry.setTransactionType(ServiceConstants.TX_ISSUE_CHEQUES);
    journalEntry.setMessage(ServiceConstants.TX_ISSUE_CHEQUES);
    journalEntry.setClerk(UserContextHolder.checkedGetUser());

    final Debtor debtor = new Debtor();
    debtor.setAccountNumber(account.getIdentifier());
    debtor.setAmount(totalCharges.toString());
    journalEntry.setDebtors(Sets.newHashSet(debtor));

    journalEntry.setCreditors(
        charges
            .stream()
            .map(charge -> {
              final Creditor creditor = new Creditor();
              creditor.setAccountNumber(charge.getIncomeAccountIdentifier());
              creditor.setAmount(charge.getAmount().toString());
              return creditor;
            })
            .collect(Collectors.toSet())
    );

    this.ledgerManager.createJournalEntry(journalEntry);
  }