Skip to content

Commit 7a56656

Browse files
author
Jose Alberto Hernandez
committed
FINERACT-2198: Extend Manual Journal entry to support Asset Externalization
1 parent 570f44a commit 7a56656

File tree

14 files changed

+147
-20
lines changed

14 files changed

+147
-20
lines changed

fineract-accounting/src/main/java/org/apache/fineract/accounting/journalentry/JournalEntryMapper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public interface JournalEntryMapper {
7171
@Mapping(target = "debits", ignore = true)
7272
@Mapping(target = "transactionDetails", ignore = true)
7373
@Mapping(target = "savingTransactionId", ignore = true)
74+
@Mapping(target = "externalAssetOwner", ignore = true)
7475
JournalEntryData map(JournalEntry journalEntry);
7576

7677
@Named("entityType")

fineract-accounting/src/main/java/org/apache/fineract/accounting/journalentry/api/JournalEntryJsonInputParams.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public enum JournalEntryJsonInputParams {
4343
CHECK_NUMBER("checkNumber"), //
4444
ROUTING_CODE("routingCode"), //
4545
RECEIPT_NUMBER("receiptNumber"), //
46-
BANK_NUMBER("bankNumber"); //
46+
BANK_NUMBER("bankNumber"), //
47+
EXTERNAL_ASSET_OWNER("externalAssetOwner"); //
4748

4849
private final String value;
4950

fineract-accounting/src/main/java/org/apache/fineract/accounting/journalentry/command/JournalEntryCommand.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class JournalEntryCommand {
5454
private final SingleDebitOrCreditEntryCommand[] debits;
5555
private final String locale;
5656
private final String dateFormat;
57+
private final String externalAssetOwner;
5758

5859
public void validateForCreate() {
5960

@@ -75,6 +76,9 @@ public void validateForCreate() {
7576

7677
baseDataValidator.reset().parameter("paymentTypeId").value(this.paymentTypeId).ignoreIfNull().longGreaterThanZero();
7778

79+
baseDataValidator.reset().parameter(JournalEntryJsonInputParams.EXTERNAL_ASSET_OWNER.getValue()).value(this.externalAssetOwner)
80+
.ignoreIfNull().notExceedingLengthOf(100);
81+
7882
// validation for credit array elements
7983
if (this.credits != null) {
8084
if (this.credits.length == 0) {

fineract-accounting/src/main/java/org/apache/fineract/accounting/journalentry/data/JournalEntryData.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public class JournalEntryData {
9494
private String routingCode;
9595
private String receiptNumber;
9696
private String bankNumber;
97+
private String externalAssetOwner;
9798
private transient Long savingTransactionId;
9899

99100
public JournalEntryData() {}
@@ -191,7 +192,7 @@ public JournalEntryData(final Long id, final Long officeId, final String officeN
191192
final EnumOptionData entityType, final Long entityId, final Long createdByUserId, final LocalDate submittedOnDate,
192193
final String createdByUserName, final String comments, final Boolean reversed, final String referenceNumber,
193194
final BigDecimal officeRunningBalance, final BigDecimal organizationRunningBalance, final Boolean runningBalanceComputed,
194-
final TransactionDetailData transactionDetailData, final CurrencyData currency) {
195+
final TransactionDetailData transactionDetailData, final CurrencyData currency, final String externalAssetOwner) {
195196
this.id = id;
196197
this.officeId = officeId;
197198
this.officeName = officeName;
@@ -218,6 +219,7 @@ public JournalEntryData(final Long id, final Long officeId, final String officeN
218219
this.runningBalanceComputed = runningBalanceComputed;
219220
this.transactionDetails = transactionDetailData;
220221
this.currency = currency;
222+
this.externalAssetOwner = externalAssetOwner;
221223
}
222224

223225
public static JournalEntryData importInstance(Long officeId, LocalDate transactionDate, String currencyCode, Long paymentTypeId,
@@ -259,10 +261,11 @@ public static JournalEntryData fromGLAccountData(final GLAccountData glAccountDa
259261
final Boolean runningBalanceComputed = null;
260262
final TransactionDetailData transactionDetailData = null;
261263
final CurrencyData currency = null;
264+
final String externalAssetOwner = null;
262265
return new JournalEntryData(id, officeId, officeName, glAccountName, glAccountId, glAccountCode, glAccountClassification,
263266
transactionDate, entryType, amount, transactionId, manualEntry, entityType, entityId, createdByUserId, submittedOnDate,
264267
createdByUserName, comments, reversed, referenceNumber, officeRunningBalance, organizationRunningBalance,
265-
runningBalanceComputed, transactionDetailData, currency);
268+
runningBalanceComputed, transactionDetailData, currency, externalAssetOwner);
266269
}
267270

268271
public Integer getRowIndex() {
@@ -274,7 +277,6 @@ public LocalDate getTransactionDate() {
274277
}
275278

276279
public void addDebits(CreditDebit debit) {
277-
278280
this.debits.add(debit);
279281
}
280282

fineract-accounting/src/main/java/org/apache/fineract/accounting/journalentry/serialization/JournalEntryCommandFromApiJsonDeserializer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ public JournalEntryCommand commandFromApiJson(final String json) {
8484
element);
8585
final String bankNumber = this.fromApiJsonHelper.extractStringNamed(JournalEntryJsonInputParams.BANK_NUMBER.getValue(), element);
8686
final String routingCode = this.fromApiJsonHelper.extractStringNamed(JournalEntryJsonInputParams.ROUTING_CODE.getValue(), element);
87+
final String externalAssetOwner = this.fromApiJsonHelper
88+
.extractStringNamed(JournalEntryJsonInputParams.EXTERNAL_ASSET_OWNER.getValue(), element);
8789

8890
SingleDebitOrCreditEntryCommand[] credits = null;
8991
SingleDebitOrCreditEntryCommand[] debits = null;
@@ -99,7 +101,8 @@ public JournalEntryCommand commandFromApiJson(final String json) {
99101
}
100102
String dateFormat = this.fromApiJsonHelper.extractStringNamed(JournalEntryJsonInputParams.DATE_FORMAT.getValue(), element);
101103
return new JournalEntryCommand(officeId, currencyCode, transactionDate, comments, referenceNumber, accountingRuleId, amount,
102-
paymentTypeId, accountNumber, checkNumber, receiptNumber, bankNumber, routingCode, credits, debits, localeStr, dateFormat);
104+
paymentTypeId, accountNumber, checkNumber, receiptNumber, bankNumber, routingCode, credits, debits, localeStr, dateFormat,
105+
externalAssetOwner);
103106
}
104107

105108
/**

fineract-investor/src/main/java/org/apache/fineract/investor/service/AccountingService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.apache.fineract.investor.service;
2020

21+
import org.apache.fineract.accounting.journalentry.domain.JournalEntry;
2122
import org.apache.fineract.investor.domain.ExternalAssetOwner;
2223
import org.apache.fineract.investor.domain.ExternalAssetOwnerTransfer;
2324
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
@@ -27,4 +28,6 @@ public interface AccountingService {
2728
void createJournalEntriesForSaleAssetTransfer(Loan loan, ExternalAssetOwnerTransfer transfer, ExternalAssetOwner previousOwner);
2829

2930
void createJournalEntriesForBuybackAssetTransfer(Loan loan, ExternalAssetOwnerTransfer transfer);
31+
32+
void createMappingToOwner(ExternalAssetOwner owner, JournalEntry journalEntry);
3033
}

fineract-investor/src/main/java/org/apache/fineract/investor/service/AccountingServiceImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ private List<JournalEntry> createJournalEntries(final Loan loan, final ExternalA
120120
return journalEntryList;
121121
}
122122

123-
private void createMappingToOwner(final ExternalAssetOwner owner, final JournalEntry journalEntry) {
123+
@Override
124+
public void createMappingToOwner(final ExternalAssetOwner owner, final JournalEntry journalEntry) {
124125
if (owner == null) {
125126
return;
126127
}

fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/api/JournalEntriesApiResourceSwagger.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ private TransactionDetails() {}
177177
public String createdByUserName;
178178
@Schema(example = "[2022, 07, 01]")
179179
public LocalDate createdDate;
180+
@Schema(example = "qwerty1234")
181+
public String externalAssetOwner;
180182

181183
public CurrencyItem currency;
182184
public EnumOptionType glAccountType;

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ public String schema() {
9999
.append(" creatingUser.username as createdByUserName, journalEntry.description as comments, ")
100100
.append(" journalEntry.submitted_on_date as submittedOnDate, journalEntry.reversed as reversed, ")
101101
.append(" journalEntry.currency_code as currencyCode, curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, ")
102-
.append(" curr.display_symbol as currencyDisplaySymbol, curr.decimal_places as currencyDigits, curr.currency_multiplesof as inMultiplesOf ");
102+
.append(" curr.display_symbol as currencyDisplaySymbol, curr.decimal_places as currencyDigits, curr.currency_multiplesof as inMultiplesOf, ")
103+
.append(" eao.external_id as externalAssetOwner ");
103104
if (associationParametersData.isRunningBalanceRequired()) {
104105
sb.append(" ,journalEntry.is_running_balance_calculated as runningBalanceComputed, ")
105106
.append(" journalEntry.office_running_balance as officeRunningBalance, ")
@@ -117,7 +118,9 @@ public String schema() {
117118
.append(" left join acc_gl_account as glAccount on glAccount.id = journalEntry.account_id")
118119
.append(" left join m_office as office on office.id = journalEntry.office_id")
119120
.append(" left join m_appuser as creatingUser on creatingUser.id = journalEntry.created_by ")
120-
.append(" join m_currency curr on curr.code = journalEntry.currency_code ");
121+
.append(" join m_currency curr on curr.code = journalEntry.currency_code ")
122+
.append(" left join m_external_asset_owner_journal_entry_mapping eajem on eajem.journal_entry_id = journalEntry.id ")
123+
.append(" left join m_external_asset_owner eao on eao.id = eajem.owner_id ");
121124
if (associationParametersData.isTransactionDetailsRequired()) {
122125
sb.append(" left join m_loan_transaction as lt on journalEntry.loan_transaction_id = lt.id ")
123126
.append(" left join m_savings_account_transaction as st on journalEntry.savings_transaction_id = st.id ")
@@ -150,7 +153,6 @@ public JournalEntryData mapRow(final ResultSet rs, @SuppressWarnings("unused") f
150153
EnumOptionData entityType = null;
151154
if (entityTypeId != null) {
152155
entityType = AccountingEnumerations.portfolioProductType(entityTypeId);
153-
154156
}
155157

156158
final Long entityId = JdbcSupport.getLong(rs, "entityId");
@@ -224,10 +226,12 @@ public JournalEntryData mapRow(final ResultSet rs, @SuppressWarnings("unused") f
224226

225227
transactionDetailData = new TransactionDetailData(transaction, paymentDetailData, noteData, transactionTypeEnumData);
226228
}
229+
final String externalAssetOwner = rs.getString("externalAssetOwner");
230+
227231
return new JournalEntryData(id, officeId, officeName, glAccountName, glAccountId, glCode, accountType, transactionDate,
228232
entryType, amount, transactionId, manualEntry, entityType, entityId, createdByUserId, submittedOnDate,
229233
createdByUserName, comments, reversed, referenceNumber, officeRunningBalance, organizationRunningBalance,
230-
runningBalanceComputed, transactionDetailData, currency);
234+
runningBalanceComputed, transactionDetailData, currency, externalAssetOwner);
231235
}
232236
}
233237

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public JournalEntryData mapRow(final ResultSet rs, @SuppressWarnings("unused") f
278278
final EnumOptionData entryType = AccountingEnumerations.journalEntryType(entryTypeId);
279279

280280
return new JournalEntryData(id, officeId, null, null, glAccountId, null, accountType, null, entryType, amount, null, null, null,
281-
null, null, null, null, null, null, null, null, null, null, null, null);
281+
null, null, null, null, null, null, null, null, null, null, null, null, null);
282282
}
283283
}
284284

0 commit comments

Comments
 (0)