Skip to content

Commit cd2f2f8

Browse files
mariiaKraievskaadamsaghy
authored andcommitted
FINERACT-1805: Fix getting details of a share transactions
1 parent cba7595 commit cd2f2f8

5 files changed

Lines changed: 148 additions & 3 deletions

File tree

fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryReadPlatformServiceImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,11 @@ public JournalEntryData mapRow(final ResultSet rs, @SuppressWarnings("unused") f
201201
noteData = new NoteData(noteId, null, null, null, null, null, null, null, note, null, null, null, null, null, null);
202202
}
203203
Long transaction = null;
204-
if (entityType != null) {
205-
transaction = Long.parseLong(transactionId.substring(1).trim());
204+
if (entityType != null && transactionId != null) {
205+
String numericPart = transactionId.replaceAll("[^\\d]", "");
206+
if (!numericPart.isEmpty()) {
207+
transaction = Long.parseLong(numericPart);
208+
}
206209
}
207210

208211
TransactionTypeEnumData transactionTypeEnumData = null;

integration-tests/src/test/java/org/apache/fineract/integrationtests/AccountingScenarioIntegrationTest.java

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import static org.junit.jupiter.api.Assertions.assertEquals;
2222

23+
import com.google.gson.Gson;
2324
import io.restassured.builder.RequestSpecBuilder;
2425
import io.restassured.builder.ResponseSpecBuilder;
2526
import io.restassured.http.ContentType;
@@ -42,7 +43,9 @@
4243
import java.util.HashMap;
4344
import java.util.List;
4445
import java.util.Locale;
46+
import java.util.Map;
4547
import java.util.TimeZone;
48+
import org.apache.fineract.client.models.GetJournalEntriesTransactionIdResponse;
4649
import org.apache.fineract.integrationtests.common.ClientHelper;
4750
import org.apache.fineract.integrationtests.common.CollateralManagementHelper;
4851
import org.apache.fineract.integrationtests.common.CommonConstants;
@@ -68,6 +71,10 @@
6871
import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
6972
import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
7073
import org.apache.fineract.integrationtests.common.savings.SavingsStatusChecker;
74+
import org.apache.fineract.integrationtests.common.shares.ShareAccountHelper;
75+
import org.apache.fineract.integrationtests.common.shares.ShareAccountTransactionHelper;
76+
import org.apache.fineract.integrationtests.common.shares.ShareProductHelper;
77+
import org.apache.fineract.integrationtests.common.shares.ShareProductTransactionHelper;
7178
import org.junit.jupiter.api.Assertions;
7279
import org.junit.jupiter.api.BeforeEach;
7380
import org.junit.jupiter.api.Test;
@@ -341,7 +348,7 @@ public void checkAccountingWithSavingsFlow() {
341348

342349
this.savingsAccountHelper.addChargesForSavings(savingsID, withdrawalChargeId, false);
343350
ArrayList<HashMap> chargesPendingState = this.savingsAccountHelper.getSavingsCharges(savingsID);
344-
Assertions.assertEquals(1, chargesPendingState.size());
351+
assertEquals(1, chargesPendingState.size());
345352
HashMap savingsChargeForPay = chargesPendingState.get(0);
346353
HashMap paidCharge = this.savingsAccountHelper.getSavingsCharge(savingsID, (Integer) savingsChargeForPay.get("id"));
347354
Float chargeAmount = (Float) paidCharge.get("amount");
@@ -1115,4 +1122,71 @@ private LocalDate getDateAsLocalDate(String dateAsString) {
11151122
return LocalDate.parse(dateAsString, Utils.dateFormatter);
11161123
}
11171124

1125+
@Test
1126+
public void checkAccountingWithSharingFlow() {
1127+
this.savingsAccountHelper = new SavingsAccountHelper(requestSpec, responseSpec);
1128+
1129+
final Account assetAccount = this.accountHelper.createAssetAccount();
1130+
final Account incomeAccount = this.accountHelper.createIncomeAccount();
1131+
final Account equityAccount = this.accountHelper.createEquityAccount();
1132+
final Account liabilityAccount = this.accountHelper.createLiabilityAccount();
1133+
1134+
final Integer shareProductID = createSharesProduct(assetAccount, incomeAccount, equityAccount, liabilityAccount);
1135+
1136+
final Integer clientID = ClientHelper.createClient(requestSpec, responseSpec, DATE_OF_JOINING);
1137+
Assertions.assertNotNull(clientID);
1138+
final Integer savingsAccountId = SavingsAccountHelper.openSavingsAccount(requestSpec, responseSpec, clientID, "1000");
1139+
Assertions.assertNotNull(savingsAccountId);
1140+
final Integer shareAccountId = createShareAccount(clientID, shareProductID, savingsAccountId);
1141+
Assertions.assertNotNull(shareAccountId);
1142+
final Map<String, Object> shareAccountData = ShareAccountTransactionHelper.retrieveShareAccount(shareAccountId, requestSpec,
1143+
responseSpec);
1144+
Assertions.assertNotNull(shareAccountData);
1145+
// Approve share Account
1146+
final Map<String, Object> approveMap = new HashMap<>();
1147+
approveMap.put("note", "Share Account Approval Note");
1148+
approveMap.put("dateFormat", "dd MMMM yyyy");
1149+
approveMap.put("approvedDate", "01 Jan 2016");
1150+
approveMap.put("locale", "en");
1151+
final String approve = new Gson().toJson(approveMap);
1152+
ShareAccountTransactionHelper.postCommand("approve", shareAccountId, approve, requestSpec, responseSpec);
1153+
// Activate Share Account
1154+
final Map<String, Object> activateMap = new HashMap<>();
1155+
activateMap.put("dateFormat", "dd MMMM yyyy");
1156+
activateMap.put("activatedDate", "01 Jan 2016");
1157+
activateMap.put("locale", "en");
1158+
final String activateJson = new Gson().toJson(activateMap);
1159+
ShareAccountTransactionHelper.postCommand("activate", shareAccountId, activateJson, requestSpec, responseSpec);
1160+
1161+
// Checking sharing entries.
1162+
final JournalEntry[] assetAccountEntry = { new JournalEntry(Float.parseFloat("200"), JournalEntry.TransactionType.DEBIT) };
1163+
final JournalEntry[] liabilityAccountEntry = { new JournalEntry(Float.parseFloat("200"), JournalEntry.TransactionType.CREDIT) };
1164+
final JournalEntry[] checkJournalEntryForEquityAccount = {
1165+
new JournalEntry(Float.parseFloat("200"), JournalEntry.TransactionType.CREDIT) };
1166+
this.journalEntryHelper.checkJournalEntryForAssetAccount(assetAccount, "01 Jan 2016", assetAccountEntry);
1167+
this.journalEntryHelper.checkJournalEntryForLiabilityAccount(liabilityAccount, "01 Jan 2016", liabilityAccountEntry);
1168+
this.journalEntryHelper.checkJournalEntryForEquityAccount(equityAccount, "01 Jan 2016", checkJournalEntryForEquityAccount);
1169+
1170+
final String transactionId = this.journalEntryHelper.getJournalEntryTransactionIdByAccount(assetAccount, "01 Jan 2016",
1171+
assetAccountEntry);
1172+
Assertions.assertNotEquals("", transactionId);
1173+
1174+
final GetJournalEntriesTransactionIdResponse journalEntriesTransactionIdResponse = this.journalEntryHelper
1175+
.getJournalEntries(transactionId);
1176+
Assertions.assertNotNull(journalEntriesTransactionIdResponse);
1177+
}
1178+
1179+
public static Integer createSharesProduct(final Account... accounts) {
1180+
LOG.info("------------------------------CREATING NEW SHARE PRODUCT ---------------------------------------");
1181+
final String shareProductJSON = new ShareProductHelper().withCashBasedAccounting(accounts).build();
1182+
return ShareProductTransactionHelper.createShareProduct(shareProductJSON, requestSpec, responseSpec);
1183+
}
1184+
1185+
private Integer createShareAccount(final Integer clientId, final Integer productId, final Integer savingsAccountId) {
1186+
final String shareAccountJSON = new ShareAccountHelper().withClientId(String.valueOf(clientId))
1187+
.withProductId(String.valueOf(productId)).withExternalId("External1").withSavingsAccountId(String.valueOf(savingsAccountId))
1188+
.withSubmittedDate("01 Jan 2016").withApplicationDate("01 Jan 2016").withRequestedShares("100").build();
1189+
return ShareAccountTransactionHelper.createShareAccount(shareAccountJSON, requestSpec, responseSpec);
1190+
}
1191+
11181192
}

integration-tests/src/test/java/org/apache/fineract/integrationtests/common/accounting/AccountHelper.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ public Account createLiabilityAccount() {
6969
return new Account(accountID, Account.AccountType.LIABILITY);
7070
}
7171

72+
public Account createEquityAccount() {
73+
final String equityAccountJSON = new GLAccountBuilder().withAccountTypeAsAsEquity().build();
74+
final Integer accountID = Utils.performServerPost(this.requestSpec, this.responseSpec, CREATE_GL_ACCOUNT_URL, equityAccountJSON,
75+
GL_ACCOUNT_ID_RESPONSE);
76+
return new Account(accountID, Account.AccountType.EQUITY);
77+
}
78+
7279
public ArrayList getAccountingWithRunningBalances() {
7380
final String GET_RUNNING_BALANCE_URL = "/fineract-provider/api/v1/glaccounts?fetchRunningBalance=true";
7481
final ArrayList<HashMap> accountRunningBalance = Utils.performServerGet(this.requestSpec, this.responseSpec,

integration-tests/src/test/java/org/apache/fineract/integrationtests/common/accounting/JournalEntryHelper.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public void checkJournalEntryForLiabilityAccount(final Account liabilityAccount,
6161
checkJournalEntry(null, liabilityAccount, date, accountEntries);
6262
}
6363

64+
public void checkJournalEntryForEquityAccount(final Account equityAccount, final String date, final JournalEntry... accountEntries) {
65+
checkJournalEntry(null, equityAccount, date, accountEntries);
66+
}
67+
6468
public void checkJournalEntryForLiabilityAccount(final Integer officeId, final Account liabilityAccount, final String date,
6569
final JournalEntry... accountEntries) {
6670
checkJournalEntry(officeId, liabilityAccount, date, accountEntries);
@@ -72,6 +76,10 @@ public void ensureNoAccountingTransactionsWithTransactionId(final String transac
7276

7377
}
7478

79+
public String getJournalEntryTransactionIdByAccount(final Account account, final String date, final JournalEntry... accountEntries) {
80+
return getJournalEntryTransactionId(account, date, accountEntries);
81+
}
82+
7583
private void checkJournalEntry(final Integer officeId, final Account account, final String date, final JournalEntry... accountEntries) {
7684
final String url = createURLForGettingAccountEntries(account, date, officeId);
7785
final ArrayList<HashMap> response = Utils.performServerGet(this.requestSpec, this.responseSpec, url, "pageItems");
@@ -89,6 +97,22 @@ private void checkJournalEntry(final Integer officeId, final Account account, fi
8997
}
9098
}
9199

100+
private String getJournalEntryTransactionId(final Account account, final String date, final JournalEntry... accountEntries) {
101+
final String url = createURLForGettingAccountEntries(account, date, null);
102+
final ArrayList<HashMap> response = Utils.performServerGet(this.requestSpec, this.responseSpec, url, "pageItems");
103+
104+
for (JournalEntry entry : accountEntries) {
105+
for (HashMap map : response) {
106+
final HashMap entryType = (HashMap) map.get("entryType");
107+
if (entry.getTransactionType().equals(entryType.get("value")) && entry.getTransactionAmount().equals(map.get("amount"))) {
108+
return map.get("transactionId").toString();
109+
}
110+
}
111+
}
112+
113+
return "";
114+
}
115+
92116
private String createURLForGettingAccountEntries(final Account account, final String date, final Integer officeId) {
93117
String url = new String("/fineract-provider/api/v1/journalentries?glAccountId=" + account.getAccountID() + "&type="
94118
+ account.getAccountType() + "&fromDate=" + date + "&toDate=" + date + "&tenantIdentifier=default"

integration-tests/src/test/java/org/apache/fineract/integrationtests/common/shares/ShareProductHelper.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Locale;
2929
import java.util.Map;
3030
import org.apache.fineract.integrationtests.common.Utils;
31+
import org.apache.fineract.integrationtests.common.accounting.Account;
3132
import org.junit.jupiter.api.Assertions;
3233
import org.slf4j.Logger;
3334
import org.slf4j.LoggerFactory;
@@ -62,6 +63,7 @@ public class ShareProductHelper {
6263

6364
private List<Map<String, String>> charges = null;
6465
private List<Map<String, String>> marketPrices = null;
66+
private Account[] accountList = null;
6567

6668
public String build() {
6769
final HashMap<String, Object> map = new HashMap<>();
@@ -93,6 +95,10 @@ public String build() {
9395
map.put("marketPricePeriods", marketPrices);
9496
}
9597

98+
if (this.accountingRule.equals(CASH_BASED)) {
99+
map.putAll(getAccountMappingForCashBased());
100+
}
101+
96102
String shareProductCreateJson = new Gson().toJson(map);
97103
LOG.info("{}", shareProductCreateJson);
98104
return shareProductCreateJson;
@@ -103,6 +109,12 @@ public ShareProductHelper withCashBasedAccounting() {
103109
return this;
104110
}
105111

112+
public ShareProductHelper withCashBasedAccounting(final Account[] account_list) {
113+
this.accountingRule = CASH_BASED;
114+
this.accountList = account_list;
115+
return this;
116+
}
117+
106118
public ShareProductHelper withMarketPrice() {
107119
this.marketPrices = new ArrayList<>();
108120
LocalDate currentDate = Utils.getLocalDateOfTenant();
@@ -197,4 +209,29 @@ public void verifyShareProduct(Map<String, Object> shareProductData) {
197209
// String>>)shareProductData.get("marketPricePeriods") ;
198210

199211
}
212+
213+
private Map<String, String> getAccountMappingForCashBased() {
214+
final Map<String, String> map = new HashMap<>();
215+
if (accountList != null) {
216+
for (int i = 0; i < this.accountList.length; i++) {
217+
if (this.accountList[i].getAccountType().equals(Account.AccountType.ASSET)) {
218+
final String ID = this.accountList[i].getAccountID().toString();
219+
map.put("shareReferenceId", ID);
220+
}
221+
if (this.accountList[i].getAccountType().equals(Account.AccountType.LIABILITY)) {
222+
final String ID = this.accountList[i].getAccountID().toString();
223+
map.put("shareSuspenseId", ID);
224+
}
225+
if (this.accountList[i].getAccountType().equals(Account.AccountType.EQUITY)) {
226+
final String ID = this.accountList[i].getAccountID().toString();
227+
map.put("shareEquityId", ID);
228+
}
229+
if (this.accountList[i].getAccountType().equals(Account.AccountType.INCOME)) {
230+
final String ID = this.accountList[i].getAccountID().toString();
231+
map.put("incomeFromFeeAccountId", ID);
232+
}
233+
}
234+
}
235+
return map;
236+
}
200237
}

0 commit comments

Comments
 (0)