FINERACT-1805: Fix getting details of a share transactions

This commit is contained in:
mariiaKraievska
2023-12-14 21:25:04 +01:00
committed by Adam Saghy
parent cba759533d
commit cd2f2f8102
5 changed files with 148 additions and 3 deletions
@@ -201,8 +201,11 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
noteData = new NoteData(noteId, null, null, null, null, null, null, null, note, null, null, null, null, null, null);
}
Long transaction = null;
if (entityType != null) {
transaction = Long.parseLong(transactionId.substring(1).trim());
if (entityType != null && transactionId != null) {
String numericPart = transactionId.replaceAll("[^\\d]", "");
if (!numericPart.isEmpty()) {
transaction = Long.parseLong(numericPart);
}
}
TransactionTypeEnumData transactionTypeEnumData = null;
@@ -20,6 +20,7 @@ package org.apache.fineract.integrationtests;
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.gson.Gson;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.builder.ResponseSpecBuilder;
import io.restassured.http.ContentType;
@@ -42,7 +43,9 @@ import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import org.apache.fineract.client.models.GetJournalEntriesTransactionIdResponse;
import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.CollateralManagementHelper;
import org.apache.fineract.integrationtests.common.CommonConstants;
@@ -68,6 +71,10 @@ import org.apache.fineract.integrationtests.common.recurringdeposit.RecurringDep
import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
import org.apache.fineract.integrationtests.common.savings.SavingsStatusChecker;
import org.apache.fineract.integrationtests.common.shares.ShareAccountHelper;
import org.apache.fineract.integrationtests.common.shares.ShareAccountTransactionHelper;
import org.apache.fineract.integrationtests.common.shares.ShareProductHelper;
import org.apache.fineract.integrationtests.common.shares.ShareProductTransactionHelper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -341,7 +348,7 @@ public class AccountingScenarioIntegrationTest {
this.savingsAccountHelper.addChargesForSavings(savingsID, withdrawalChargeId, false);
ArrayList<HashMap> chargesPendingState = this.savingsAccountHelper.getSavingsCharges(savingsID);
Assertions.assertEquals(1, chargesPendingState.size());
assertEquals(1, chargesPendingState.size());
HashMap savingsChargeForPay = chargesPendingState.get(0);
HashMap paidCharge = this.savingsAccountHelper.getSavingsCharge(savingsID, (Integer) savingsChargeForPay.get("id"));
Float chargeAmount = (Float) paidCharge.get("amount");
@@ -1115,4 +1122,71 @@ public class AccountingScenarioIntegrationTest {
return LocalDate.parse(dateAsString, Utils.dateFormatter);
}
@Test
public void checkAccountingWithSharingFlow() {
this.savingsAccountHelper = new SavingsAccountHelper(requestSpec, responseSpec);
final Account assetAccount = this.accountHelper.createAssetAccount();
final Account incomeAccount = this.accountHelper.createIncomeAccount();
final Account equityAccount = this.accountHelper.createEquityAccount();
final Account liabilityAccount = this.accountHelper.createLiabilityAccount();
final Integer shareProductID = createSharesProduct(assetAccount, incomeAccount, equityAccount, liabilityAccount);
final Integer clientID = ClientHelper.createClient(requestSpec, responseSpec, DATE_OF_JOINING);
Assertions.assertNotNull(clientID);
final Integer savingsAccountId = SavingsAccountHelper.openSavingsAccount(requestSpec, responseSpec, clientID, "1000");
Assertions.assertNotNull(savingsAccountId);
final Integer shareAccountId = createShareAccount(clientID, shareProductID, savingsAccountId);
Assertions.assertNotNull(shareAccountId);
final Map<String, Object> shareAccountData = ShareAccountTransactionHelper.retrieveShareAccount(shareAccountId, requestSpec,
responseSpec);
Assertions.assertNotNull(shareAccountData);
// Approve share Account
final Map<String, Object> approveMap = new HashMap<>();
approveMap.put("note", "Share Account Approval Note");
approveMap.put("dateFormat", "dd MMMM yyyy");
approveMap.put("approvedDate", "01 Jan 2016");
approveMap.put("locale", "en");
final String approve = new Gson().toJson(approveMap);
ShareAccountTransactionHelper.postCommand("approve", shareAccountId, approve, requestSpec, responseSpec);
// Activate Share Account
final Map<String, Object> activateMap = new HashMap<>();
activateMap.put("dateFormat", "dd MMMM yyyy");
activateMap.put("activatedDate", "01 Jan 2016");
activateMap.put("locale", "en");
final String activateJson = new Gson().toJson(activateMap);
ShareAccountTransactionHelper.postCommand("activate", shareAccountId, activateJson, requestSpec, responseSpec);
// Checking sharing entries.
final JournalEntry[] assetAccountEntry = { new JournalEntry(Float.parseFloat("200"), JournalEntry.TransactionType.DEBIT) };
final JournalEntry[] liabilityAccountEntry = { new JournalEntry(Float.parseFloat("200"), JournalEntry.TransactionType.CREDIT) };
final JournalEntry[] checkJournalEntryForEquityAccount = {
new JournalEntry(Float.parseFloat("200"), JournalEntry.TransactionType.CREDIT) };
this.journalEntryHelper.checkJournalEntryForAssetAccount(assetAccount, "01 Jan 2016", assetAccountEntry);
this.journalEntryHelper.checkJournalEntryForLiabilityAccount(liabilityAccount, "01 Jan 2016", liabilityAccountEntry);
this.journalEntryHelper.checkJournalEntryForEquityAccount(equityAccount, "01 Jan 2016", checkJournalEntryForEquityAccount);
final String transactionId = this.journalEntryHelper.getJournalEntryTransactionIdByAccount(assetAccount, "01 Jan 2016",
assetAccountEntry);
Assertions.assertNotEquals("", transactionId);
final GetJournalEntriesTransactionIdResponse journalEntriesTransactionIdResponse = this.journalEntryHelper
.getJournalEntries(transactionId);
Assertions.assertNotNull(journalEntriesTransactionIdResponse);
}
public static Integer createSharesProduct(final Account... accounts) {
LOG.info("------------------------------CREATING NEW SHARE PRODUCT ---------------------------------------");
final String shareProductJSON = new ShareProductHelper().withCashBasedAccounting(accounts).build();
return ShareProductTransactionHelper.createShareProduct(shareProductJSON, requestSpec, responseSpec);
}
private Integer createShareAccount(final Integer clientId, final Integer productId, final Integer savingsAccountId) {
final String shareAccountJSON = new ShareAccountHelper().withClientId(String.valueOf(clientId))
.withProductId(String.valueOf(productId)).withExternalId("External1").withSavingsAccountId(String.valueOf(savingsAccountId))
.withSubmittedDate("01 Jan 2016").withApplicationDate("01 Jan 2016").withRequestedShares("100").build();
return ShareAccountTransactionHelper.createShareAccount(shareAccountJSON, requestSpec, responseSpec);
}
}
@@ -69,6 +69,13 @@ public class AccountHelper extends IntegrationTest {
return new Account(accountID, Account.AccountType.LIABILITY);
}
public Account createEquityAccount() {
final String equityAccountJSON = new GLAccountBuilder().withAccountTypeAsAsEquity().build();
final Integer accountID = Utils.performServerPost(this.requestSpec, this.responseSpec, CREATE_GL_ACCOUNT_URL, equityAccountJSON,
GL_ACCOUNT_ID_RESPONSE);
return new Account(accountID, Account.AccountType.EQUITY);
}
public ArrayList getAccountingWithRunningBalances() {
final String GET_RUNNING_BALANCE_URL = "/fineract-provider/api/v1/glaccounts?fetchRunningBalance=true";
final ArrayList<HashMap> accountRunningBalance = Utils.performServerGet(this.requestSpec, this.responseSpec,
@@ -61,6 +61,10 @@ public class JournalEntryHelper {
checkJournalEntry(null, liabilityAccount, date, accountEntries);
}
public void checkJournalEntryForEquityAccount(final Account equityAccount, final String date, final JournalEntry... accountEntries) {
checkJournalEntry(null, equityAccount, date, accountEntries);
}
public void checkJournalEntryForLiabilityAccount(final Integer officeId, final Account liabilityAccount, final String date,
final JournalEntry... accountEntries) {
checkJournalEntry(officeId, liabilityAccount, date, accountEntries);
@@ -72,6 +76,10 @@ public class JournalEntryHelper {
}
public String getJournalEntryTransactionIdByAccount(final Account account, final String date, final JournalEntry... accountEntries) {
return getJournalEntryTransactionId(account, date, accountEntries);
}
private void checkJournalEntry(final Integer officeId, final Account account, final String date, final JournalEntry... accountEntries) {
final String url = createURLForGettingAccountEntries(account, date, officeId);
final ArrayList<HashMap> response = Utils.performServerGet(this.requestSpec, this.responseSpec, url, "pageItems");
@@ -89,6 +97,22 @@ public class JournalEntryHelper {
}
}
private String getJournalEntryTransactionId(final Account account, final String date, final JournalEntry... accountEntries) {
final String url = createURLForGettingAccountEntries(account, date, null);
final ArrayList<HashMap> response = Utils.performServerGet(this.requestSpec, this.responseSpec, url, "pageItems");
for (JournalEntry entry : accountEntries) {
for (HashMap map : response) {
final HashMap entryType = (HashMap) map.get("entryType");
if (entry.getTransactionType().equals(entryType.get("value")) && entry.getTransactionAmount().equals(map.get("amount"))) {
return map.get("transactionId").toString();
}
}
}
return "";
}
private String createURLForGettingAccountEntries(final Account account, final String date, final Integer officeId) {
String url = new String("/fineract-provider/api/v1/journalentries?glAccountId=" + account.getAccountID() + "&type="
+ account.getAccountType() + "&fromDate=" + date + "&toDate=" + date + "&tenantIdentifier=default"
@@ -28,6 +28,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.integrationtests.common.accounting.Account;
import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -62,6 +63,7 @@ public class ShareProductHelper {
private List<Map<String, String>> charges = null;
private List<Map<String, String>> marketPrices = null;
private Account[] accountList = null;
public String build() {
final HashMap<String, Object> map = new HashMap<>();
@@ -93,6 +95,10 @@ public class ShareProductHelper {
map.put("marketPricePeriods", marketPrices);
}
if (this.accountingRule.equals(CASH_BASED)) {
map.putAll(getAccountMappingForCashBased());
}
String shareProductCreateJson = new Gson().toJson(map);
LOG.info("{}", shareProductCreateJson);
return shareProductCreateJson;
@@ -103,6 +109,12 @@ public class ShareProductHelper {
return this;
}
public ShareProductHelper withCashBasedAccounting(final Account[] account_list) {
this.accountingRule = CASH_BASED;
this.accountList = account_list;
return this;
}
public ShareProductHelper withMarketPrice() {
this.marketPrices = new ArrayList<>();
LocalDate currentDate = Utils.getLocalDateOfTenant();
@@ -197,4 +209,29 @@ public class ShareProductHelper {
// String>>)shareProductData.get("marketPricePeriods") ;
}
private Map<String, String> getAccountMappingForCashBased() {
final Map<String, String> map = new HashMap<>();
if (accountList != null) {
for (int i = 0; i < this.accountList.length; i++) {
if (this.accountList[i].getAccountType().equals(Account.AccountType.ASSET)) {
final String ID = this.accountList[i].getAccountID().toString();
map.put("shareReferenceId", ID);
}
if (this.accountList[i].getAccountType().equals(Account.AccountType.LIABILITY)) {
final String ID = this.accountList[i].getAccountID().toString();
map.put("shareSuspenseId", ID);
}
if (this.accountList[i].getAccountType().equals(Account.AccountType.EQUITY)) {
final String ID = this.accountList[i].getAccountID().toString();
map.put("shareEquityId", ID);
}
if (this.accountList[i].getAccountType().equals(Account.AccountType.INCOME)) {
final String ID = this.accountList[i].getAccountID().toString();
map.put("incomeFromFeeAccountId", ID);
}
}
}
return map;
}
}