private Optional adjustDenominatedTellerBalance()

in service/src/main/java/org/apache/fineract/cn/teller/service/internal/command/handler/TellerAggregate.java [411:451]


  private Optional<String> adjustDenominatedTellerBalance(final TellerEntity tellerEntity,
                                              final BigDecimal expectedBalance,
                                              final BigDecimal countedTotal) {
    if (expectedBalance.compareTo(countedTotal) != 0) {
      final JournalEntry journalEntry = new JournalEntry();
      journalEntry.setTransactionIdentifier(RandomStringUtils.randomNumeric(32));
      journalEntry.setTransactionDate(DateConverter.toIsoString(LocalDateTime.now(Clock.systemUTC())));
      journalEntry.setClerk(UserContextHolder.checkedGetUser());
      journalEntry.setMessage("Teller denomination adjustment.");

      final Debtor debtor = new Debtor();
      final Creditor creditor = new Creditor();
      final BigDecimal adjustment = expectedBalance.subtract(countedTotal);
      if (adjustment.signum() == -1) {
        final BigDecimal value = adjustment.negate();
        journalEntry.setTransactionType(ServiceConstants.TX_DEPOSIT_ADJUSTMENT);

        debtor.setAccountNumber(tellerEntity.getTellerAccountIdentifier());
        debtor.setAmount(value.toString());
        journalEntry.setDebtors(Sets.newHashSet(debtor));

        creditor.setAccountNumber(tellerEntity.getCashOverShortAccount());
        creditor.setAmount(value.toString());
        journalEntry.setCreditors(Sets.newHashSet(creditor));
      } else {
        journalEntry.setTransactionType(ServiceConstants.TX_CREDIT_ADJUSTMENT);

        debtor.setAccountNumber(tellerEntity.getCashOverShortAccount());
        debtor.setAmount(adjustment.toString());
        journalEntry.setDebtors(Sets.newHashSet(debtor));

        creditor.setAccountNumber(tellerEntity.getTellerAccountIdentifier());
        creditor.setAmount(adjustment.toString());
        journalEntry.setCreditors(Sets.newHashSet(creditor));
      }

      this.accountingService.postJournalEntry(journalEntry);
      return Optional.of(journalEntry.getTransactionIdentifier());
    }
    return Optional.empty();
  }