public void documentCreateJournalEntry()

in component-test/src/main/java/org/apache/fineract/cn/accounting/JournalEntryApiDocumentation.java [80:141]


  public void documentCreateJournalEntry ( ) throws Exception {

    final Ledger assetLedger = LedgerGenerator.createRandomLedger();
    assetLedger.setType(AccountType.ASSET.name());
    this.testSubject.createLedger(assetLedger);
    this.eventRecorder.wait(EventConstants.POST_LEDGER, assetLedger.getIdentifier());

    final Account debtorAccount = AccountGenerator.createRandomAccount(assetLedger.getIdentifier());
    debtorAccount.setIdentifier("7100");
    debtorAccount.setType(AccountType.ASSET.name());
    debtorAccount.setBalance(100.00D);
    this.testSubject.createAccount(debtorAccount);
    this.eventRecorder.wait(EventConstants.POST_ACCOUNT, debtorAccount.getIdentifier());

    final Ledger liabilityLedger = LedgerGenerator.createRandomLedger();
    liabilityLedger.setIdentifier("8120");
    liabilityLedger.setType(AccountType.LIABILITY.name());
    this.testSubject.createLedger(liabilityLedger);
    this.eventRecorder.wait(EventConstants.POST_LEDGER, liabilityLedger.getIdentifier());

    final Account creditorAccount = AccountGenerator.createRandomAccount(liabilityLedger.getIdentifier());
    creditorAccount.setType(AccountType.LIABILITY.name());
    creditorAccount.setBalance(100.00D);
    this.testSubject.createAccount(creditorAccount);
    this.eventRecorder.wait(EventConstants.POST_ACCOUNT, creditorAccount.getIdentifier());

    final JournalEntry journalEntry = JournalEntryGenerator.createRandomJournalEntry(debtorAccount, "50.00",
            creditorAccount, "50.00");
    journalEntry.setTransactionIdentifier("F14062018");
    journalEntry.setTransactionDate(LocalDate.now().toString());
    journalEntry.setTransactionType("ADBT");
    journalEntry.setClerk("Boring Clerk");
    journalEntry.setNote("Account Db");
    journalEntry.setMessage("Account Has Been Debited");

    Set <Debtor> debtorSet = new HashSet <>();
    debtorSet.add(new Debtor(debtorAccount.getIdentifier(), debtorAccount.getBalance().toString()));

    Set <Creditor> creditorSet = new HashSet <>();
    creditorSet.add(new Creditor(creditorAccount.getIdentifier(), creditorAccount.getBalance().toString()));

    journalEntry.setDebtors(debtorSet);
    journalEntry.setCreditors(creditorSet);

    Gson gson = new Gson();
    this.mockMvc.perform(post("/journal")
            .contentType(MediaType.APPLICATION_JSON_VALUE)
            .accept(MediaType.APPLICATION_JSON_VALUE)
            .content(gson.toJson(journalEntry)))
            .andExpect(status().isAccepted())
            .andDo(document("document-create-journal-entry", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
                    requestFields(
                            fieldWithPath("transactionIdentifier").description("Transaction ID"),
                            fieldWithPath("transactionDate").description("Account identifier"),
                            fieldWithPath("transactionType").description("Type of transaction"),
                            fieldWithPath("clerk").type("String").description("Clerk who initiated transaction"),
                            fieldWithPath("note").type("String").description("Transaction note"),
                            fieldWithPath("debtors").type("Set<Debtors>").description("Set of debtors"),
                            fieldWithPath("creditors").type("Set<Creditors>").description("Set of creditors"),
                            fieldWithPath("message").description("Associated ledger")
                    )));
  }