in service/src/main/java/org/apache/fineract/cn/accounting/service/internal/command/handler/AccountCommandHandler.java [99:157]
public String createAccount(final CreateAccountCommand createAccountCommand) {
final Account account = createAccountCommand.account();
final AccountEntity accountEntity = new AccountEntity();
accountEntity.setIdentifier(account.getIdentifier());
accountEntity.setName(account.getName());
accountEntity.setType(account.getType());
final LedgerEntity ledger = this.ledgerRepository.findByIdentifier(account.getLedger());
accountEntity.setLedger(ledger);
AccountEntity referenceAccount = null;
if (account.getReferenceAccount() != null) {
referenceAccount = this.accountRepository.findByIdentifier(account.getReferenceAccount());
if (referenceAccount.getState().equals(Account.State.OPEN.name())) {
accountEntity.setReferenceAccount(referenceAccount);
} else {
throw ServiceException.badRequest("Reference account {0} is not valid.", referenceAccount.getIdentifier());
}
}
if (account.getHolders() != null) {
accountEntity.setHolders(
account.getHolders()
.stream()
.collect(Collectors.joining(","))
);
}
if (account.getSignatureAuthorities() != null) {
accountEntity.setSignatureAuthorities(
account.getSignatureAuthorities()
.stream()
.collect(Collectors.joining(","))
);
}
accountEntity.setBalance(account.getBalance());
accountEntity.setState(Account.State.OPEN.name());
accountEntity.setAlternativeAccountNumber(account.getAlternativeAccountNumber());
accountEntity.setCreatedBy(UserContextHolder.checkedGetUser());
accountEntity.setCreatedOn(LocalDateTime.now(Clock.systemUTC()));
final AccountEntity savedAccountEntity = this.accountRepository.save(accountEntity);
if (referenceAccount != null) {
referenceAccount.setLastModifiedBy(UserContextHolder.checkedGetUser());
referenceAccount.setLastModifiedOn(LocalDateTime.now(Clock.systemUTC()));
this.accountRepository.save(referenceAccount);
}
this.ledgerRepository.save(ledger);
if (savedAccountEntity.getBalance() != null && savedAccountEntity.getBalance() != 0.00D) {
this.adjustLedgerTotals(
savedAccountEntity.getLedger().getIdentifier(), BigDecimal.valueOf(savedAccountEntity.getBalance()));
}
return account.getIdentifier();
}