in service/src/main/java/org/apache/fineract/cn/cheque/service/internal/command/handler/ChequeAggregate.java [135:184]
public String process(final ChequeTransactionCommand chequeTransactionCommand) {
final ChequeEntity chequeEntity = ChequeMapper.map(chequeTransactionCommand.cheque());
final MICR micr = chequeTransactionCommand.cheque().getMicr();
final JournalEntry journalEntry = new JournalEntry();
journalEntry.setTransactionIdentifier("chq-tx-" + UUID.randomUUID().toString());
final String transactionType =
chequeEntity.getOpenCheque() != null && chequeEntity.getOpenCheque() ? "OPCQ" : "ORCQ";
journalEntry.setTransactionType(transactionType);
journalEntry.setTransactionDate(DateConverter.toIsoString(chequeEntity.getCreatedOn()));
journalEntry.setMessage(transactionType);
journalEntry.setClerk(UserContextHolder.checkedGetUser());
final Debtor debtor = new Debtor();
debtor.setAmount(chequeEntity.getAmount().toString());
if (this.onUs(micr)) {
final Optional<IssuedChequeEntity> optionalIssuedCheque =
this.issuedChequeRepository.findByAccountIdentifier(micr.getAccountNumber());
if (optionalIssuedCheque.isPresent()) {
final Integer lastIssuedNumber = optionalIssuedCheque.get().getLastIssuedNumber();
if (Integer.valueOf(chequeEntity.getChequeNumber()) > lastIssuedNumber) {
throw ServiceException.conflict("Unknown cheque {0}.", MICRParser.toIdentifier(micr));
}
} else {
throw ServiceException.conflict("Account {0} never issued cheques.", micr.getAccountNumber());
}
this.accountingService.findAccount(micr.getAccountNumber())
.ifPresent(account -> debtor.setAccountNumber(account.getIdentifier()));
chequeEntity.setState(State.PROCESSED.name());
} else {
debtor.setAccountNumber(chequeTransactionCommand.chequesReceivableAccount());
chequeEntity.setState(State.PENDING.name());
}
journalEntry.setDebtors(Sets.newHashSet(debtor));
final Creditor creditor = new Creditor();
creditor.setAmount(chequeEntity.getAmount().toString());
creditor.setAccountNumber(chequeTransactionCommand.creditorAccount());
journalEntry.setCreditors(Sets.newHashSet(creditor));
this.accountingService.processJournalEntry(journalEntry);
chequeEntity.setJournalEntryIdentifier(journalEntry.getTransactionIdentifier());
this.chequeRepository.save(chequeEntity);
return MICRParser.toIdentifier(micr);
}