in component-test/src/main/java/org/apache/fineract/cn/accounting/JournalEntryApiDocumentation.java [144:239]
public void documentFetchJournalEntries ( ) throws Exception {
final Ledger assetLedgerOne = LedgerGenerator.createRandomLedger();
assetLedgerOne.setIdentifier("7120");
assetLedgerOne.setType(AccountType.ASSET.name());
this.testSubject.createLedger(assetLedgerOne);
this.eventRecorder.wait(EventConstants.POST_LEDGER, assetLedgerOne.getIdentifier());
final Account accountToDebitOne = AccountGenerator.createRandomAccount(assetLedgerOne.getIdentifier());
accountToDebitOne.setIdentifier("7140");
accountToDebitOne.setType(AccountType.ASSET.name());
accountToDebitOne.setBalance(1000.0);
this.testSubject.createAccount(accountToDebitOne);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, accountToDebitOne.getIdentifier());
final Ledger liabilityLedgerOne = LedgerGenerator.createRandomLedger();
liabilityLedgerOne.setIdentifier("8150");
liabilityLedgerOne.setType(AccountType.LIABILITY.name());
this.testSubject.createLedger(liabilityLedgerOne);
this.eventRecorder.wait(EventConstants.POST_LEDGER, liabilityLedgerOne.getIdentifier());
final Account accountToCreditOne = AccountGenerator.createRandomAccount(liabilityLedgerOne.getIdentifier());
accountToCreditOne.setIdentifier("8160");
accountToCreditOne.setType(AccountType.LIABILITY.name());
this.testSubject.createAccount(accountToCreditOne);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, accountToCreditOne.getIdentifier());
final JournalEntry journalEntryOne = JournalEntryGenerator.createRandomJournalEntry(accountToDebitOne, "50.00",
accountToCreditOne, "50.00");
final OffsetDateTime startOne = OffsetDateTime.of(2017, 6, 20, 1, 0, 0, 0, ZoneOffset.UTC);
journalEntryOne.setTransactionDate(startOne.format(DateTimeFormatter.ISO_ZONED_DATE_TIME));
journalEntryOne.setTransactionIdentifier("FE1");
journalEntryOne.setTransactionType("ACCT");
journalEntryOne.setClerk("Mr. " + journalEntryOne.getClerk().toUpperCase().charAt(0) + journalEntryOne.getClerk().substring(1, 5));
journalEntryOne.setNote("Noted Transfer");
journalEntryOne.setMessage("First Message Noted");
this.testSubject.createJournalEntry(journalEntryOne);
this.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, journalEntryOne.getTransactionIdentifier());
this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, journalEntryOne.getTransactionIdentifier());
final Ledger assetLedgerTwo = LedgerGenerator.createRandomLedger();
assetLedgerTwo.setIdentifier("7200");
assetLedgerTwo.setType(AccountType.ASSET.name());
this.testSubject.createLedger(assetLedgerTwo);
this.eventRecorder.wait(EventConstants.POST_LEDGER, assetLedgerTwo.getIdentifier());
final Account accountToDebitTwo = AccountGenerator.createRandomAccount(assetLedgerTwo.getIdentifier());
accountToDebitTwo.setIdentifier("7210");
accountToDebitTwo.setType(AccountType.ASSET.name());
accountToDebitTwo.setBalance(2000.0);
this.testSubject.createAccount(accountToDebitTwo);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, accountToDebitTwo.getIdentifier());
final Ledger liabilityLedgerTwo = LedgerGenerator.createRandomLedger();
liabilityLedgerTwo.setIdentifier("8200");
liabilityLedgerTwo.setType(AccountType.LIABILITY.name());
this.testSubject.createLedger(liabilityLedgerTwo);
this.eventRecorder.wait(EventConstants.POST_LEDGER, liabilityLedgerTwo.getIdentifier());
final Account accountToCreditTwo = AccountGenerator.createRandomAccount(liabilityLedgerTwo.getIdentifier());
accountToCreditTwo.setIdentifier("8210");
accountToCreditTwo.setType(AccountType.LIABILITY.name());
this.testSubject.createAccount(accountToCreditTwo);
this.eventRecorder.wait(EventConstants.POST_ACCOUNT, accountToCreditTwo.getIdentifier());
final JournalEntry journalEntryTwo = JournalEntryGenerator.createRandomJournalEntry(accountToDebitTwo, "40.00",
accountToCreditTwo, "40.00");
final OffsetDateTime startTwo = OffsetDateTime.of(2017, 6, 24, 1, 0, 0, 0, ZoneOffset.UTC);
journalEntryTwo.setTransactionDate(startTwo.format(DateTimeFormatter.ISO_ZONED_DATE_TIME));
journalEntryTwo.setTransactionIdentifier("FE2");
journalEntryTwo.setTransactionType("ACRT");
journalEntryTwo.setClerk("Mrs. " + journalEntryTwo.getClerk().toUpperCase().charAt(0) + journalEntryTwo.getClerk().substring(1, 5));
journalEntryTwo.setNote("Noted Credit");
journalEntryTwo.setMessage("Message Noted");
this.testSubject.createJournalEntry(journalEntryTwo);
this.eventRecorder.wait(EventConstants.POST_JOURNAL_ENTRY, journalEntryTwo.getTransactionIdentifier());
this.eventRecorder.wait(EventConstants.RELEASE_JOURNAL_ENTRY, journalEntryTwo.getTransactionIdentifier());
final LocalDate beginDate = LocalDate.of(2017, 6, 20);
final LocalDate endDate = LocalDate.of(2017, 6, 24);
final String dateRange = MessageFormat.format("{0}..{1}",
DateConverter.toIsoString(beginDate),
DateConverter.toIsoString(endDate));
final List <JournalEntry> journalEntriesPage =
this.testSubject.fetchJournalEntries(dateRange, accountToDebitOne.getIdentifier(), BigDecimal.valueOf(50.00D));
Gson gson = new Gson();
this.mockMvc.perform(get("/journal")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.ALL_VALUE))
.andExpect(status().isOk())
.andDo(document("document-fetch-journal-entries", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint())));
}