Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
99ef5edfd8 | ||
|
|
9df8e924a1 | ||
|
|
1922455996 | ||
|
|
cca4ae583f | ||
|
|
99a7e04872 | ||
|
|
ac7873a51e | ||
|
|
643427bd1a | ||
|
|
6c7c0f8445 | ||
|
|
88157ee9d6 | ||
|
|
760fff8d3e | ||
|
|
d7ff4e4a7b | ||
|
|
7068d65422 | ||
|
|
fd827dec27 | ||
|
|
aa264097e7 | ||
|
|
16c67f6701 | ||
|
|
e846892e9f | ||
|
|
56d98bac8d | ||
|
|
0d6066e0b6 | ||
|
|
4499b8afad | ||
|
|
11a206f42a | ||
|
|
11a0d502be | ||
|
|
2afd4aaf83 | ||
|
|
e5dd6af366 | ||
|
|
ce8bb7e5ca | ||
|
|
82336cbe98 | ||
|
|
9436eab129 | ||
|
|
1408bddf58 | ||
|
|
e02ab51ee1 | ||
|
|
3a37a5f90f | ||
|
|
e7417d16a6 | ||
|
|
24d3bf83bb | ||
|
|
af052dcb4f | ||
|
|
b12268e740 | ||
|
|
6ee3bbe67c | ||
|
|
d8f6c25875 | ||
|
|
2155c94161 | ||
|
|
87f3e591ce | ||
|
|
1e903232f0 | ||
|
|
2c49d6f637 | ||
|
|
331c553164 | ||
|
|
3fb008a22a | ||
|
|
8b2fb052d4 | ||
|
|
cebba87864 | ||
|
|
ea39c8e82a | ||
|
|
32411c924b | ||
|
|
f696499102 | ||
|
|
7eabaf2542 | ||
|
|
4b9093007f | ||
|
|
9beae3df28 | ||
|
|
d2e13cc7b9 | ||
|
|
ecfe8aa76a | ||
|
|
a7cb09f15c | ||
|
|
26d4c241c7 | ||
|
|
dbc2737ada | ||
|
|
f457b9b8c7 | ||
|
|
23ee4f1063 | ||
|
|
bc38216ca3 | ||
|
|
fde2699957 | ||
|
|
dd4bb4a1c0 | ||
|
|
6046134b51 | ||
|
|
e4fad8b648 | ||
|
|
e206536a6b | ||
|
|
bf52c2cda1 | ||
|
|
934c11bf87 | ||
|
|
c1e6e036d0 | ||
|
|
4c0512f154 | ||
|
|
b779d04571 | ||
|
|
184d1b8cf8 | ||
|
|
521d61d6b7 |
+1
-1
@@ -154,7 +154,7 @@ gitVersioning.apply {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
rev {
|
rev {
|
||||||
version = '${describe.tag.version.major}.${describe.tag.version.minor.next}.0-SNAPSHOT'
|
version = '1.15.0-SNAPSHOT'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-1
@@ -279,9 +279,15 @@ public final class ProductToGLAccountMappingFromApiJsonDeserializer {
|
|||||||
|
|
||||||
if (AccountingValidations.isCashBasedAccounting(accountingRuleType)) {
|
if (AccountingValidations.isCashBasedAccounting(accountingRuleType)) {
|
||||||
|
|
||||||
|
// Optional, not mandatory like the three below: it names an account for cash physically
|
||||||
|
// received at the counter for a share purchase, which every register in this bank now
|
||||||
|
// books against the account the money actually reached instead. Left absent, a product
|
||||||
|
// simply carries no such mapping, and any code path that still needs one (a genuine
|
||||||
|
// over-the-counter collection) fails with a named "GL not mapped" error rather than
|
||||||
|
// silently assuming the till.
|
||||||
final Long shareReferenceId = this.fromApiJsonHelper.extractLongNamed(SharesProductAccountingParams.SHARES_REFERENCE.getValue(),
|
final Long shareReferenceId = this.fromApiJsonHelper.extractLongNamed(SharesProductAccountingParams.SHARES_REFERENCE.getValue(),
|
||||||
element);
|
element);
|
||||||
baseDataValidator.reset().parameter(SharesProductAccountingParams.SHARES_REFERENCE.getValue()).value(shareReferenceId).notNull()
|
baseDataValidator.reset().parameter(SharesProductAccountingParams.SHARES_REFERENCE.getValue()).value(shareReferenceId)
|
||||||
.integerGreaterThanZero();
|
.integerGreaterThanZero();
|
||||||
|
|
||||||
final Long shareSuspenseId = this.fromApiJsonHelper.extractLongNamed(SharesProductAccountingParams.SHARES_SUSPENSE.getValue(),
|
final Long shareSuspenseId = this.fromApiJsonHelper.extractLongNamed(SharesProductAccountingParams.SHARES_SUSPENSE.getValue(),
|
||||||
|
|||||||
+2
@@ -38,6 +38,8 @@ public interface ProductToGLAccountMappingReadPlatformService {
|
|||||||
|
|
||||||
Map<String, Object> fetchAccountMappingDetailsForSavingsProduct(Long savingsProductId, Integer accountingType);
|
Map<String, Object> fetchAccountMappingDetailsForSavingsProduct(Long savingsProductId, Integer accountingType);
|
||||||
|
|
||||||
|
Map<String, Object> fetchAccountMappingDetailsForCurrentProduct(Long currentProductId, Integer accountingType);
|
||||||
|
|
||||||
List<PaymentTypeToGLAccountMapper> fetchPaymentTypeToFundSourceMappingsForSavingsProduct(Long savingsProductId);
|
List<PaymentTypeToGLAccountMapper> fetchPaymentTypeToFundSourceMappingsForSavingsProduct(Long savingsProductId);
|
||||||
|
|
||||||
List<ChargeToGLAccountMapper> fetchFeeToIncomeAccountMappingsForSavingsProduct(Long savingsProductId);
|
List<ChargeToGLAccountMapper> fetchFeeToIncomeAccountMappingsForSavingsProduct(Long savingsProductId);
|
||||||
|
|||||||
+16
@@ -202,6 +202,20 @@ public class ProductToGLAccountMappingReadPlatformServiceImpl implements Product
|
|||||||
return accountMappingDetails;
|
return accountMappingDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A current product's mappings, which live under their own CURRENT product type, laid out as a savings product's. */
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> fetchAccountMappingDetailsForCurrentProduct(final Long currentProductId, final Integer accountingType) {
|
||||||
|
final List<ProductToGLAccountMapping> mappings = productToGLAccountMappingRepository.findAllRegularMappings(currentProductId,
|
||||||
|
PortfolioProductType.CURRENT.getValue());
|
||||||
|
if (AccountingValidations.isCashBasedAccounting(accountingType)) {
|
||||||
|
return setCashSavingsProductToGLAccountMaps(mappings);
|
||||||
|
}
|
||||||
|
if (AccountingValidations.isAccrualPeriodicBasedAccounting(accountingType)) {
|
||||||
|
return setAccrualPeriodicSavingsProductToGLAccountMaps(mappings);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PaymentTypeToGLAccountMapper> fetchPaymentTypeToFundSourceMappingsForLoanProduct(final Long loanProductId) {
|
public List<PaymentTypeToGLAccountMapper> fetchPaymentTypeToFundSourceMappingsForLoanProduct(final Long loanProductId) {
|
||||||
return fetchPaymentTypeToFundSourceMappings(PortfolioProductType.LOAN, loanProductId);
|
return fetchPaymentTypeToFundSourceMappings(PortfolioProductType.LOAN, loanProductId);
|
||||||
@@ -463,6 +477,8 @@ public class ProductToGLAccountMappingReadPlatformServiceImpl implements Product
|
|||||||
accountMappingDetails.put(SavingProductAccountingDataParams.SAVINGS_CONTROL.getValue(), glAccountData);
|
accountMappingDetails.put(SavingProductAccountingDataParams.SAVINGS_CONTROL.getValue(), glAccountData);
|
||||||
} else if (glAccountForSavings.equals(CashAccountsForSavings.TRANSFERS_SUSPENSE)) {
|
} else if (glAccountForSavings.equals(CashAccountsForSavings.TRANSFERS_SUSPENSE)) {
|
||||||
accountMappingDetails.put(SavingProductAccountingDataParams.TRANSFERS_SUSPENSE.getValue(), glAccountData);
|
accountMappingDetails.put(SavingProductAccountingDataParams.TRANSFERS_SUSPENSE.getValue(), glAccountData);
|
||||||
|
} else if (glAccountForSavings.equals(CashAccountsForSavings.INTEREST_PAYABLE)) {
|
||||||
|
accountMappingDetails.put(SavingProductAccountingDataParams.INTEREST_PAYABLE.getValue(), glAccountData);
|
||||||
// Income
|
// Income
|
||||||
} else if (glAccountForSavings.equals(CashAccountsForSavings.INCOME_FROM_FEES)) {
|
} else if (glAccountForSavings.equals(CashAccountsForSavings.INCOME_FROM_FEES)) {
|
||||||
accountMappingDetails.put(SavingProductAccountingDataParams.INCOME_FROM_FEES.getValue(), glAccountData);
|
accountMappingDetails.put(SavingProductAccountingDataParams.INCOME_FROM_FEES.getValue(), glAccountData);
|
||||||
|
|||||||
+7
@@ -264,6 +264,13 @@ public class SavingsProductToGLAccountMappingHelper extends ProductToGLAccountMa
|
|||||||
savingsProductId, CashAccountsForSavings.ESCHEAT_LIABILITY.getValue(), changes);
|
savingsProductId, CashAccountsForSavings.ESCHEAT_LIABILITY.getValue(), changes);
|
||||||
createOrmergeSavingsToExpenseAccountMappingChanges(element, SavingProductAccountingParams.ROUNDING_ADJUSTMENT.getValue(),
|
createOrmergeSavingsToExpenseAccountMappingChanges(element, SavingProductAccountingParams.ROUNDING_ADJUSTMENT.getValue(),
|
||||||
savingsProductId, CashAccountsForSavings.ROUNDING_ADJUSTMENT.getValue(), changes);
|
savingsProductId, CashAccountsForSavings.ROUNDING_ADJUSTMENT.getValue(), changes);
|
||||||
|
// Interest Payable is editable on cash too, and optional. Interest posting routes
|
||||||
|
// through it on either basis, so a product can name one to carry interest declared
|
||||||
|
// but not yet credited; a product that names none still posts straight to Savings
|
||||||
|
// Control. Created-or-merged because a product configured before this row existed
|
||||||
|
// has no mapping to merge into.
|
||||||
|
createOrmergeSavingsToLiabilityAccountMappingChanges(element, SavingProductAccountingParams.INTEREST_PAYABLE.getValue(),
|
||||||
|
savingsProductId, AccrualAccountsForSavings.INTEREST_PAYABLE.getValue(), changes);
|
||||||
break;
|
break;
|
||||||
case ACCRUAL_PERIODIC:
|
case ACCRUAL_PERIODIC:
|
||||||
// asset
|
// asset
|
||||||
|
|||||||
+35
-3
@@ -27,6 +27,7 @@ import org.apache.fineract.accounting.common.AccountingRuleType;
|
|||||||
import org.apache.fineract.accounting.glaccount.domain.GLAccountRepository;
|
import org.apache.fineract.accounting.glaccount.domain.GLAccountRepository;
|
||||||
import org.apache.fineract.accounting.glaccount.domain.GLAccountRepositoryWrapper;
|
import org.apache.fineract.accounting.glaccount.domain.GLAccountRepositoryWrapper;
|
||||||
import org.apache.fineract.accounting.glaccount.domain.GLAccountType;
|
import org.apache.fineract.accounting.glaccount.domain.GLAccountType;
|
||||||
|
import org.apache.fineract.accounting.producttoaccountmapping.domain.ProductToGLAccountMapping;
|
||||||
import org.apache.fineract.accounting.producttoaccountmapping.domain.ProductToGLAccountMappingRepository;
|
import org.apache.fineract.accounting.producttoaccountmapping.domain.ProductToGLAccountMappingRepository;
|
||||||
import org.apache.fineract.infrastructure.codes.domain.CodeValueRepository;
|
import org.apache.fineract.infrastructure.codes.domain.CodeValueRepository;
|
||||||
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
||||||
@@ -166,9 +167,9 @@ public class ShareProductToGLAccountMappingHelper extends ProductToGLAccountMapp
|
|||||||
case NONE:
|
case NONE:
|
||||||
break;
|
break;
|
||||||
case CASH_BASED:
|
case CASH_BASED:
|
||||||
// asset
|
// asset -- the one optional mapping here, so unlike the three below it needs its own
|
||||||
mergeSharesToAssetAccountMappingChanges(element, SharesProductAccountingParams.SHARES_REFERENCE.getValue(), sharesProductId,
|
// handling for the case the field is now absent (see mergeOrRemoveSharesReferenceMapping).
|
||||||
CashAccountsForShares.SHARES_REFERENCE.getValue(), CashAccountsForShares.SHARES_REFERENCE.toString(), changes);
|
mergeOrRemoveSharesReferenceMapping(element, sharesProductId, changes);
|
||||||
|
|
||||||
// income
|
// income
|
||||||
mergeSharesToIncomeAccountMappingChanges(element, SharesProductAccountingParams.INCOME_FROM_FEES.getValue(),
|
mergeSharesToIncomeAccountMappingChanges(element, SharesProductAccountingParams.INCOME_FROM_FEES.getValue(),
|
||||||
@@ -194,4 +195,35 @@ public class ShareProductToGLAccountMappingHelper extends ProductToGLAccountMapp
|
|||||||
public void deleteSharesProductToGLAccountMapping(final Long sharesProductId) {
|
public void deleteSharesProductToGLAccountMapping(final Long sharesProductId) {
|
||||||
deleteProductToGLAccountMapping(sharesProductId, PortfolioProductType.SHARES);
|
deleteProductToGLAccountMapping(sharesProductId, PortfolioProductType.SHARES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the one optional share-product mapping, Shares Reference, on an edit that does not change
|
||||||
|
* the accounting rule.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* The other three mappings (Suspense, Income From Fees, Equity) are mandatory, so
|
||||||
|
* {@code mergeProductToAccountMappingChanges} only ever needs to handle "present and possibly
|
||||||
|
* changed" for them -- a null value there cannot happen without failing validation first. Shares
|
||||||
|
* Reference can legitimately be absent, and the shared merge helper (used across loan, savings and
|
||||||
|
* share products alike) only handles "present": it silently leaves an existing mapping row alone
|
||||||
|
* when the incoming value is null, rather than clearing it. Editing this one field out of an
|
||||||
|
* existing product would otherwise leave the product still carrying its old GL underneath, invisible
|
||||||
|
* on the edit form but still resolvable by any code path that looks it up directly.
|
||||||
|
*/
|
||||||
|
private void mergeOrRemoveSharesReferenceMapping(final JsonElement element, final Long sharesProductId,
|
||||||
|
final Map<String, Object> changes) {
|
||||||
|
final Long shareReferenceId = this.fromApiJsonHelper.extractLongNamed(SharesProductAccountingParams.SHARES_REFERENCE.getValue(),
|
||||||
|
element);
|
||||||
|
if (shareReferenceId != null) {
|
||||||
|
mergeSharesToAssetAccountMappingChanges(element, SharesProductAccountingParams.SHARES_REFERENCE.getValue(), sharesProductId,
|
||||||
|
CashAccountsForShares.SHARES_REFERENCE.getValue(), CashAccountsForShares.SHARES_REFERENCE.toString(), changes);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final ProductToGLAccountMapping existing = this.accountMappingRepository.findCoreProductToFinAccountMapping(sharesProductId,
|
||||||
|
PortfolioProductType.SHARES.getValue(), CashAccountsForShares.SHARES_REFERENCE.getValue());
|
||||||
|
if (existing != null) {
|
||||||
|
this.accountMappingRepository.delete(existing);
|
||||||
|
changes.put(SharesProductAccountingParams.SHARES_REFERENCE.getValue(), null);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -33,4 +33,6 @@ public interface TellerRepository extends JpaRepository<Teller, Long>, JpaSpecif
|
|||||||
Collection<Teller> findTellerByOfficeId(Long officeId);
|
Collection<Teller> findTellerByOfficeId(Long officeId);
|
||||||
|
|
||||||
long countByDeletedFalse();
|
long countByDeletedFalse();
|
||||||
|
|
||||||
|
long countByOfficeIdAndDeletedFalse(Long officeId);
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -58,4 +58,9 @@ public class TellerRepositoryWrapper {
|
|||||||
public boolean existsAny() {
|
public boolean existsAny() {
|
||||||
return this.repository.countByDeletedFalse() > 0;
|
return this.repository.countByDeletedFalse() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Whether the branch already has a (not deleted) teller — each branch keeps one vault of its own. */
|
||||||
|
public boolean existsInOffice(final Long officeId) {
|
||||||
|
return this.repository.countByOfficeIdAndDeletedFalse(officeId) > 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -28,4 +28,9 @@ public class TellerAlreadyExistsException extends AbstractPlatformDomainRuleExce
|
|||||||
public TellerAlreadyExistsException() {
|
public TellerAlreadyExistsException() {
|
||||||
super(ERROR_MESSAGE_CODE, DEFAULT_ERROR_MESSAGE);
|
super(ERROR_MESSAGE_CODE, DEFAULT_ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TellerAlreadyExistsException(final String officeName) {
|
||||||
|
super(ERROR_MESSAGE_CODE, "Cannot create teller: " + officeName + " already has a teller. Each branch has one teller.",
|
||||||
|
officeName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -270,6 +270,7 @@ public final class AccountingConstants {
|
|||||||
INCOME_FROM_INTEREST(12), //
|
INCOME_FROM_INTEREST(12), //
|
||||||
LOSSES_WRITTEN_OFF(13), //
|
LOSSES_WRITTEN_OFF(13), //
|
||||||
ESCHEAT_LIABILITY(14), //
|
ESCHEAT_LIABILITY(14), //
|
||||||
|
INTEREST_PAYABLE(17), //
|
||||||
/**
|
/**
|
||||||
* Where the paise dropped from a cash closure are absorbed.
|
* Where the paise dropped from a cash closure are absorbed.
|
||||||
*
|
*
|
||||||
|
|||||||
+1
@@ -163,6 +163,7 @@ public class CommandSourceService {
|
|||||||
|| "CURRENTPRODUCT".equalsIgnoreCase(commandSource.getEntityName())
|
|| "CURRENTPRODUCT".equalsIgnoreCase(commandSource.getEntityName())
|
||||||
|| "SHAREPRODUCT".equalsIgnoreCase(commandSource.getEntityName())
|
|| "SHAREPRODUCT".equalsIgnoreCase(commandSource.getEntityName())
|
||||||
|| "FIXEDDEPOSITPRODUCT".equalsIgnoreCase(commandSource.getEntityName())
|
|| "FIXEDDEPOSITPRODUCT".equalsIgnoreCase(commandSource.getEntityName())
|
||||||
|
|| "RECURRINGDEPOSITPRODUCT".equalsIgnoreCase(commandSource.getEntityName())
|
||||||
|| "USER".equalsIgnoreCase(commandSource.getEntityName())
|
|| "USER".equalsIgnoreCase(commandSource.getEntityName())
|
||||||
|| "ROLE".equalsIgnoreCase(commandSource.getEntityName())) {
|
|| "ROLE".equalsIgnoreCase(commandSource.getEntityName())) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
+120
@@ -756,6 +756,14 @@ public class CommandWrapperBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder deleteFund(final Long fundId) {
|
||||||
|
this.actionName = "DELETE";
|
||||||
|
this.entityName = "FUND";
|
||||||
|
this.entityId = fundId;
|
||||||
|
this.href = "/funds/" + fundId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public CommandWrapperBuilder createReport() {
|
public CommandWrapperBuilder createReport() {
|
||||||
this.actionName = "CREATE";
|
this.actionName = "CREATE";
|
||||||
this.entityName = "REPORT";
|
this.entityName = "REPORT";
|
||||||
@@ -884,6 +892,70 @@ public class CommandWrapperBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder createPaymentType() {
|
||||||
|
this.actionName = "CREATE";
|
||||||
|
this.entityName = "PAYMENTTYPE";
|
||||||
|
this.entityId = null;
|
||||||
|
this.href = "/paymenttypes/template";
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder updatePaymentType(final Long paymentTypeId) {
|
||||||
|
this.actionName = "UPDATE";
|
||||||
|
this.entityName = "PAYMENTTYPE";
|
||||||
|
this.entityId = paymentTypeId;
|
||||||
|
this.href = "/paymenttypes/" + paymentTypeId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder deletePaymentType(final Long paymentTypeId) {
|
||||||
|
this.actionName = "DELETE";
|
||||||
|
this.entityName = "PAYMENTTYPE";
|
||||||
|
this.entityId = paymentTypeId;
|
||||||
|
this.href = "/paymenttypes/" + paymentTypeId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder createSponsorBank() {
|
||||||
|
this.actionName = "CREATE";
|
||||||
|
this.entityName = "SPONSORBANK";
|
||||||
|
this.entityId = null;
|
||||||
|
this.href = "/sponsorbanks";
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder updateSponsorBank(final Long sponsorBankId) {
|
||||||
|
this.actionName = "UPDATE";
|
||||||
|
this.entityName = "SPONSORBANK";
|
||||||
|
this.entityId = sponsorBankId;
|
||||||
|
this.href = "/sponsorbanks/" + sponsorBankId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder updateSponsorDdGlMapping() {
|
||||||
|
this.actionName = "UPDATE";
|
||||||
|
this.entityName = "SPONSORDDGLMAPPING";
|
||||||
|
this.entityId = null;
|
||||||
|
this.href = "/sponsordd/gl-mapping";
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder updateInstitutionProfile() {
|
||||||
|
this.actionName = "UPDATE";
|
||||||
|
this.entityName = "INSTITUTIONPROFILE";
|
||||||
|
this.entityId = null;
|
||||||
|
this.href = "/institutionprofile";
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder updateBranchProfile(final Long officeId) {
|
||||||
|
this.actionName = "UPDATE";
|
||||||
|
this.entityName = "BRANCHPROFILE";
|
||||||
|
this.entityId = officeId;
|
||||||
|
this.href = "/branchprofile/" + officeId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public CommandWrapperBuilder createLoanProduct() {
|
public CommandWrapperBuilder createLoanProduct() {
|
||||||
this.actionName = "CREATE";
|
this.actionName = "CREATE";
|
||||||
this.entityName = "LOANPRODUCT";
|
this.entityName = "LOANPRODUCT";
|
||||||
@@ -3085,6 +3157,15 @@ public class CommandWrapperBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder extendTenureRecurringDepositAccount(final Long accountId) {
|
||||||
|
this.actionName = "EXTENDTENURE";
|
||||||
|
this.entityName = "RECURRINGDEPOSITACCOUNT";
|
||||||
|
this.entityId = accountId;
|
||||||
|
this.savingsId = accountId;
|
||||||
|
this.href = "/recurringdepositaccounts/" + accountId + "?command=extendTenure";
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public CommandWrapperBuilder prematureCloseRecurringDepositAccount(final Long accountId) {
|
public CommandWrapperBuilder prematureCloseRecurringDepositAccount(final Long accountId) {
|
||||||
this.actionName = "PREMATURECLOSE";
|
this.actionName = "PREMATURECLOSE";
|
||||||
this.entityName = "RECURRINGDEPOSITACCOUNT";
|
this.entityName = "RECURRINGDEPOSITACCOUNT";
|
||||||
@@ -3390,6 +3471,13 @@ public class CommandWrapperBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder updateCurrency() {
|
||||||
|
this.actionName = "UPDATE";
|
||||||
|
this.entityName = "CURRENCY";
|
||||||
|
this.href = "/currencies";
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public CommandWrapperBuilder updateExternalServiceProperties(final String externalServiceName) {
|
public CommandWrapperBuilder updateExternalServiceProperties(final String externalServiceName) {
|
||||||
this.actionName = "UPDATE";
|
this.actionName = "UPDATE";
|
||||||
this.entityName = "EXTERNALSERVICES";
|
this.entityName = "EXTERNALSERVICES";
|
||||||
@@ -4730,4 +4818,36 @@ public class CommandWrapperBuilder {
|
|||||||
this.href = "/loans/" + loanId + "/originators/" + originatorId;
|
this.href = "/loans/" + loanId + "/originators/" + originatorId;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder createSurvey() {
|
||||||
|
this.actionName = "CREATE";
|
||||||
|
this.entityName = "SURVEY";
|
||||||
|
this.entityId = null;
|
||||||
|
this.href = "/surveys";
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder updateSurvey(final Long surveyId) {
|
||||||
|
this.actionName = "UPDATE";
|
||||||
|
this.entityName = "SURVEY";
|
||||||
|
this.entityId = surveyId;
|
||||||
|
this.href = "/surveys/" + surveyId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder activateSurvey(final Long surveyId) {
|
||||||
|
this.actionName = "ACTIVATE";
|
||||||
|
this.entityName = "SURVEY";
|
||||||
|
this.entityId = surveyId;
|
||||||
|
this.href = "/surveys/" + surveyId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandWrapperBuilder deactivateSurvey(final Long surveyId) {
|
||||||
|
this.actionName = "DEACTIVATE";
|
||||||
|
this.entityName = "SURVEY";
|
||||||
|
this.entityId = surveyId;
|
||||||
|
this.href = "/surveys/" + surveyId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -43,6 +43,7 @@ public enum JobName {
|
|||||||
UPDATE_SAVINGS_DORMANT_ACCOUNTS("Update Savings Dormant Accounts"), //
|
UPDATE_SAVINGS_DORMANT_ACCOUNTS("Update Savings Dormant Accounts"), //
|
||||||
APPLY_KYC_EXPIRY_RESTRICTIONS("Apply KYC Expiry Restrictions"), //
|
APPLY_KYC_EXPIRY_RESTRICTIONS("Apply KYC Expiry Restrictions"), //
|
||||||
SAVINGS_DAILY_INTEREST("Savings Daily Interest Accrual And Posting"), //
|
SAVINGS_DAILY_INTEREST("Savings Daily Interest Accrual And Posting"), //
|
||||||
|
SAVINGS_INTEREST_POSTING_REPORT("Generate Savings Interest Posting Report"), //
|
||||||
ADD_PERIODIC_ACCRUAL_ENTRIES_FOR_LOANS_WITH_INCOME_POSTED_AS_TRANSACTIONS(
|
ADD_PERIODIC_ACCRUAL_ENTRIES_FOR_LOANS_WITH_INCOME_POSTED_AS_TRANSACTIONS(
|
||||||
"Add Accrual Transactions For Loans With Income Posted As Transactions"), //
|
"Add Accrual Transactions For Loans With Income Posted As Transactions"), //
|
||||||
EXECUTE_REPORT_MAILING_JOBS("Execute Report Mailing Jobs"), //
|
EXECUTE_REPORT_MAILING_JOBS("Execute Report Mailing Jobs"), //
|
||||||
@@ -72,6 +73,10 @@ public enum JobName {
|
|||||||
OUTWARD_CLEARING_BATCH_SEND("CTS Outward Clearing Batch Send"), //
|
OUTWARD_CLEARING_BATCH_SEND("CTS Outward Clearing Batch Send"), //
|
||||||
CTR_REPORT_GENERATION("AML Monthly CTR Report Generation"), //
|
CTR_REPORT_GENERATION("AML Monthly CTR Report Generation"), //
|
||||||
AML_STR_WEEKLY_DIGEST("AML STR Weekly Digest"), //
|
AML_STR_WEEKLY_DIGEST("AML STR Weekly Digest"), //
|
||||||
|
CLIENT_BEHAVIOUR_WINDOW("Client Behaviour Window Computation"), //
|
||||||
|
SAVE_RBI_FORM_A_RETURN("Save RBI Form A Return"), //
|
||||||
|
EXECUTE_RD_AUTO_DEBIT("Execute RD Auto Debit"), //
|
||||||
|
APPLY_RD_MISSED_INSTALLMENT_PENALTY("Apply RD Missed Installment Penalty"), //
|
||||||
; //
|
; //
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|||||||
+12
-11
@@ -27,13 +27,14 @@ import jakarta.ws.rs.PUT;
|
|||||||
import jakarta.ws.rs.Path;
|
import jakarta.ws.rs.Path;
|
||||||
import jakarta.ws.rs.Produces;
|
import jakarta.ws.rs.Produces;
|
||||||
import jakarta.ws.rs.core.MediaType;
|
import jakarta.ws.rs.core.MediaType;
|
||||||
import java.util.function.Supplier;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.fineract.command.core.CommandPipeline;
|
import org.apache.fineract.commands.domain.CommandWrapper;
|
||||||
import org.apache.fineract.organisation.monetary.command.CurrencyUpdateCommand;
|
import org.apache.fineract.commands.service.CommandWrapperBuilder;
|
||||||
|
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||||
|
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||||
import org.apache.fineract.organisation.monetary.data.CurrencyConfigurationData;
|
import org.apache.fineract.organisation.monetary.data.CurrencyConfigurationData;
|
||||||
import org.apache.fineract.organisation.monetary.data.CurrencyUpdateRequest;
|
import org.apache.fineract.organisation.monetary.data.CurrencyUpdateRequest;
|
||||||
import org.apache.fineract.organisation.monetary.data.CurrencyUpdateResponse;
|
|
||||||
import org.apache.fineract.organisation.monetary.service.OrganisationCurrencyReadPlatformService;
|
import org.apache.fineract.organisation.monetary.service.OrganisationCurrencyReadPlatformService;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -44,7 +45,8 @@ import org.springframework.stereotype.Component;
|
|||||||
public class CurrenciesApiResource {
|
public class CurrenciesApiResource {
|
||||||
|
|
||||||
private final OrganisationCurrencyReadPlatformService readPlatformService;
|
private final OrganisationCurrencyReadPlatformService readPlatformService;
|
||||||
private final CommandPipeline commandPipeline;
|
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||||
|
private final DefaultToApiJsonSerializer<CurrencyUpdateRequest> toApiJsonSerializer;
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@@ -65,13 +67,12 @@ public class CurrenciesApiResource {
|
|||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
@Operation(summary = "Update Currency Configuration", description = "Updates the list of currencies permitted for use.")
|
@Operation(summary = "Update Currency Configuration", description = "Updates the list of currencies permitted for use.")
|
||||||
public CurrencyUpdateResponse updateCurrencies(@Valid CurrencyUpdateRequest request) {
|
public String updateCurrencies(@Valid final CurrencyUpdateRequest request) {
|
||||||
final var command = new CurrencyUpdateCommand();
|
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateCurrency()
|
||||||
|
.withJson(toApiJsonSerializer.serialize(request)).build();
|
||||||
|
|
||||||
command.setPayload(request);
|
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||||
|
|
||||||
final Supplier<CurrencyUpdateResponse> response = commandPipeline.send(command);
|
return toApiJsonSerializer.serialize(result);
|
||||||
|
|
||||||
return response.get();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+63
@@ -0,0 +1,63 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.organisation.monetary.handler;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.apache.fineract.commands.annotation.CommandType;
|
||||||
|
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
|
||||||
|
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
||||||
|
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
|
||||||
|
import org.apache.fineract.organisation.monetary.data.CurrencyUpdateRequest;
|
||||||
|
import org.apache.fineract.organisation.monetary.data.CurrencyUpdateResponse;
|
||||||
|
import org.apache.fineract.organisation.monetary.service.CurrencyWritePlatformService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@CommandType(entity = "CURRENCY", action = "UPDATE")
|
||||||
|
public class UpdateCurrencyCommandHandler implements NewCommandSourceHandler {
|
||||||
|
|
||||||
|
private final CurrencyWritePlatformService writePlatformService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public UpdateCurrencyCommandHandler(final CurrencyWritePlatformService writePlatformService) {
|
||||||
|
this.writePlatformService = writePlatformService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
@Override
|
||||||
|
public CommandProcessingResult processCommand(final JsonCommand command) {
|
||||||
|
|
||||||
|
final String[] currencyCodes = command.arrayValueOfParameterNamed("currencies");
|
||||||
|
final List<String> currencies = currencyCodes == null ? List.of() : Arrays.asList(currencyCodes);
|
||||||
|
|
||||||
|
final CurrencyUpdateRequest request = CurrencyUpdateRequest.builder().currencies(currencies).build();
|
||||||
|
|
||||||
|
final CurrencyUpdateResponse response = this.writePlatformService.updateAllowedCurrencies(request);
|
||||||
|
|
||||||
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withCommandId(command.commandId()) //
|
||||||
|
.with(Map.of("currencies", response.getCurrencies())) //
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
+15
-4
@@ -24,7 +24,10 @@ public enum PortfolioProductType {
|
|||||||
SAVING(2, "productType.saving"), //
|
SAVING(2, "productType.saving"), //
|
||||||
CLIENT(5, "productType.client"), //
|
CLIENT(5, "productType.client"), //
|
||||||
PROVISIONING(3, "productType.provisioning"), //
|
PROVISIONING(3, "productType.provisioning"), //
|
||||||
SHARES(4, "productType.shares"); //
|
SHARES(4, "productType.shares"), //
|
||||||
|
// Current products map their GLs under their own type: sharing SAVING with savings products let a savings
|
||||||
|
// product and a current product with the same id read each other's GL rows.
|
||||||
|
CURRENT(6, "productType.current"); //
|
||||||
|
|
||||||
private final Integer value;
|
private final Integer value;
|
||||||
private final String code;
|
private final String code;
|
||||||
@@ -52,17 +55,25 @@ public enum PortfolioProductType {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Matched against each constant's own declared value above, not its declaration position --
|
||||||
|
// those two orderings diverge (CLIENT is declared 3rd but its value is 5), so a switch written
|
||||||
|
// by position silently mapped every id past SAVING to the wrong type: 3 (really PROVISIONING)
|
||||||
|
// returned CLIENT, 4 (really SHARES) returned PROVISIONING, 5 (really CLIENT) returned SHARES,
|
||||||
|
// and 6 (CURRENT) fell through to null -- a live NPE the moment a Current-product GL entry
|
||||||
|
// (entity_type_enum=6) reached this on the Journal Entries screen.
|
||||||
switch (v) {
|
switch (v) {
|
||||||
case 1:
|
case 1:
|
||||||
return LOAN;
|
return LOAN;
|
||||||
case 2:
|
case 2:
|
||||||
return SAVING;
|
return SAVING;
|
||||||
case 3:
|
case 3:
|
||||||
return CLIENT;
|
|
||||||
case 4:
|
|
||||||
return PROVISIONING;
|
return PROVISIONING;
|
||||||
case 5:
|
case 4:
|
||||||
return SHARES;
|
return SHARES;
|
||||||
|
case 5:
|
||||||
|
return CLIENT;
|
||||||
|
case 6:
|
||||||
|
return CURRENT;
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,30 @@ public class AmlAlert extends AbstractAuditableWithUTCDateTimeCustom<Long> {
|
|||||||
@Column(name = "disposition", length = 20)
|
@Column(name = "disposition", length = 20)
|
||||||
private String disposition;
|
private String disposition;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The other rules this same transaction matched, comma-separated.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* One transaction raises one alert, under the rule that most warrants attention - otherwise a
|
||||||
|
* single deposit arrives as several alerts and an officer has to dispose of each, with nothing
|
||||||
|
* stopping them clearing one while escalating another. The rules that did not win are kept here
|
||||||
|
* so the case file still shows everything that fired.
|
||||||
|
*/
|
||||||
|
@Column(name = "also_matched_rules", length = 500)
|
||||||
|
private String alsoMatchedRules;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The worst severity band across every rule this transaction matched — 1 Low, 2 Medium, 3 High.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Not the same as the governing rule's own severity. A statutory CTR outranks everything when
|
||||||
|
* the alert is raised, so a high-severity rule can end up recorded in {@link #alsoMatchedRules}
|
||||||
|
* and vanish from the screen. An officer disposing of low and medium alerts in a batch would
|
||||||
|
* then be handed a transaction that had tripped a high-severity rule with nothing to show it.
|
||||||
|
*/
|
||||||
|
@Column(name = "highest_severity")
|
||||||
|
private Integer highestSeverity;
|
||||||
|
|
||||||
protected AmlAlert() {}
|
protected AmlAlert() {}
|
||||||
|
|
||||||
public static AmlAlert raise(AmlTransactionType transactionType, Long transactionId, Client client, AmlTransactionRule rule,
|
public static AmlAlert raise(AmlTransactionType transactionType, Long transactionId, Client client, AmlTransactionRule rule,
|
||||||
@@ -94,6 +118,58 @@ public class AmlAlert extends AbstractAuditableWithUTCDateTimeCustom<Long> {
|
|||||||
return alert;
|
return alert;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getAlsoMatchedRules() {
|
||||||
|
return this.alsoMatchedRules;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getHighestSeverity() {
|
||||||
|
return this.highestSeverity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void recordHighestSeverity(final Integer severity) {
|
||||||
|
this.highestSeverity = severity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Truncated to the column width: the record is a convenience, never a reason to fail a save. */
|
||||||
|
public void recordAlsoMatchedRules(final String ruleCodes) {
|
||||||
|
this.alsoMatchedRules = ruleCodes == null || ruleCodes.isBlank() ? null
|
||||||
|
: (ruleCodes.length() > 500 ? ruleCodes.substring(0, 500) : ruleCodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether this alert is being worked by somebody other than the given officer.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* An alert under review belongs to whoever opened it until they decide it or hand it back. A second officer
|
||||||
|
* reading the same case and reaching their own verdict is the failure this exists to prevent: the transaction
|
||||||
|
* would carry two reviews, and whichever was written last would be the one on file.
|
||||||
|
*/
|
||||||
|
public boolean isHeldByAnother(final AppUser officer) {
|
||||||
|
return AmlAlertStatus.UNDER_REVIEW.name().equals(this.status) && this.reviewedBy != null && officer != null
|
||||||
|
&& !this.reviewedBy.getId().equals(officer.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Brings the alert into line with the Principal Officer's conclusion on the case it opened.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* An escalation is a referral, not a verdict: it says the AML Officer wanted the case looked at. The verdict is
|
||||||
|
* the Principal Officer's, and when they conclude the case clear the alert has to say so too. Left as ESCALATED,
|
||||||
|
* the feed would go on showing a transaction as suspicious after the bank had decided it was not - and the officer
|
||||||
|
* who cleared it would have no way to see their own conclusion reflected where the alert is worked.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Distinct from {@link #whitelist}: this does not pass the alert's own immutability guard, because it is not a
|
||||||
|
* second officer overturning a decision. It is the case this alert was referred into, coming back with its answer.
|
||||||
|
*/
|
||||||
|
public void applyStrConclusion(final boolean suspicious, final AppUser principalOfficer, final String notes) {
|
||||||
|
this.reviewedBy = principalOfficer;
|
||||||
|
this.reviewedOn = LocalDateTime.now();
|
||||||
|
this.reviewNotes = notes;
|
||||||
|
this.disposition = (suspicious ? AmlAlertDisposition.ESCALATE : AmlAlertDisposition.WHITELIST).name();
|
||||||
|
this.status = (suspicious ? AmlAlertStatus.ESCALATED : AmlAlertStatus.WHITELISTED).name();
|
||||||
|
}
|
||||||
|
|
||||||
public void whitelist(AppUser reviewer, String notes) {
|
public void whitelist(AppUser reviewer, String notes) {
|
||||||
this.reviewedBy = reviewer;
|
this.reviewedBy = reviewer;
|
||||||
this.reviewedOn = LocalDateTime.now();
|
this.reviewedOn = LocalDateTime.now();
|
||||||
|
|||||||
+14
@@ -44,4 +44,18 @@ public interface AmlAlertRepository extends JpaRepository<AmlAlert, Long> {
|
|||||||
* twice, which would put two STR cases in front of the Principal Officer for a single transaction.
|
* twice, which would put two STR cases in front of the Principal Officer for a single transaction.
|
||||||
*/
|
*/
|
||||||
List<AmlAlert> findByRule_IdAndTransactionId(Long ruleId, Long transactionId);
|
List<AmlAlert> findByRule_IdAndTransactionId(Long ruleId, Long transactionId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A customer's still-open alerts inside the observation window, oldest first.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* What a recurring-behaviour review acts on. Open is defined as not yet decided rather than by naming the statuses
|
||||||
|
* that are open, so a status this query does not know about is still treated as work: an alert wrongly included
|
||||||
|
* costs a reviewer a glance, one wrongly excluded is a pattern the bank never looked at. A decision about the
|
||||||
|
* customer's pattern must not reopen alerts an officer has already disposed of individually - and oldest first so
|
||||||
|
* that a partial failure leaves the longest-standing ones dealt with.
|
||||||
|
*/
|
||||||
|
@Query("SELECT a FROM AmlAlert a WHERE a.client.id = :clientId AND a.raisedOn >= :since "
|
||||||
|
+ "AND a.status NOT IN ('WHITELISTED', 'ESCALATED') ORDER BY a.raisedOn ASC")
|
||||||
|
List<AmlAlert> findOpenAlertsForClientSince(@Param("clientId") Long clientId, @Param("since") LocalDateTime since);
|
||||||
}
|
}
|
||||||
|
|||||||
+163
@@ -0,0 +1,163 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.portfolio.aml.domain;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import org.apache.fineract.useradministration.domain.AppUser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One rule a transaction matched, and what the officer decided about that rule.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* The alert is the case; this is a finding within it. A single deposit can trip six rules where five are explained by
|
||||||
|
* the customer's declared business and the sixth is not - one verdict over the whole alert either loses that sixth
|
||||||
|
* observation or sends the other five to an STR they do not belong in.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* The rule is held by code rather than by a foreign key to {@link AmlTransactionRule}, and the severity is copied in
|
||||||
|
* rather than read back through it. An alert records what was detected at the time; re-banding or retiring a rule
|
||||||
|
* afterwards must not rewrite what the officer was looking at when they decided.
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "m_aml_alert_rule")
|
||||||
|
public class AmlAlertRule {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "alert_id", nullable = false)
|
||||||
|
private AmlAlert alert;
|
||||||
|
|
||||||
|
@Column(name = "rule_code", nullable = false, length = 100)
|
||||||
|
private String ruleCode;
|
||||||
|
|
||||||
|
@Column(name = "risk_category")
|
||||||
|
private Integer riskCategory;
|
||||||
|
|
||||||
|
@Column(name = "is_governing", nullable = false)
|
||||||
|
private boolean governing;
|
||||||
|
|
||||||
|
@Column(name = "disposition", length = 20)
|
||||||
|
private String disposition;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "reviewed_by")
|
||||||
|
private AppUser reviewedBy;
|
||||||
|
|
||||||
|
@Column(name = "reviewed_on")
|
||||||
|
private LocalDateTime reviewedOn;
|
||||||
|
|
||||||
|
@Column(name = "review_notes", length = 1000)
|
||||||
|
private String reviewNotes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the officer named this rule, as against it being closed to keep the case consistent.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Marking one rule suspicious escalates the transaction and closes every other rule under the same escalation -
|
||||||
|
* nothing may stay open behind a filed STR. Without this the record would read as though all of them had been
|
||||||
|
* examined and condemned, and on a transaction that tripped six rules, which one the officer put their name to is
|
||||||
|
* the substance of the finding.
|
||||||
|
*/
|
||||||
|
@Column(name = "directly_decided", nullable = false)
|
||||||
|
private boolean directlyDecided;
|
||||||
|
|
||||||
|
protected AmlAlertRule() {}
|
||||||
|
|
||||||
|
public static AmlAlertRule of(final AmlAlert alert, final String ruleCode, final Integer riskCategory,
|
||||||
|
final boolean governing) {
|
||||||
|
final AmlAlertRule finding = new AmlAlertRule();
|
||||||
|
finding.alert = alert;
|
||||||
|
finding.ruleCode = ruleCode;
|
||||||
|
finding.riskCategory = riskCategory;
|
||||||
|
finding.governing = governing;
|
||||||
|
return finding;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param directlyDecided
|
||||||
|
* true when the officer named this rule; false when it was closed alongside one they named
|
||||||
|
*/
|
||||||
|
public void decide(final AmlAlertDisposition disposition, final AppUser reviewer, final String notes,
|
||||||
|
final boolean directlyDecided) {
|
||||||
|
this.disposition = disposition.name();
|
||||||
|
this.reviewedBy = reviewer;
|
||||||
|
this.reviewedOn = LocalDateTime.now();
|
||||||
|
this.reviewNotes = notes;
|
||||||
|
this.directlyDecided = directlyDecided;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDirectlyDecided() {
|
||||||
|
return this.directlyDecided;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDecided() {
|
||||||
|
return this.disposition != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEscalated() {
|
||||||
|
return AmlAlertDisposition.ESCALATE.name().equals(this.disposition);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AmlAlert getAlert() {
|
||||||
|
return this.alert;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRuleCode() {
|
||||||
|
return this.ruleCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getRiskCategory() {
|
||||||
|
return this.riskCategory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isGoverning() {
|
||||||
|
return this.governing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDisposition() {
|
||||||
|
return this.disposition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AppUser getReviewedBy() {
|
||||||
|
return this.reviewedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getReviewedOn() {
|
||||||
|
return this.reviewedOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getReviewNotes() {
|
||||||
|
return this.reviewNotes;
|
||||||
|
}
|
||||||
|
}
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.portfolio.aml.domain;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface AmlAlertRuleRepository extends JpaRepository<AmlAlertRule, Long> {
|
||||||
|
|
||||||
|
List<AmlAlertRule> findByAlertId(Long alertId);
|
||||||
|
|
||||||
|
/** Every finding across a page of alerts, in one read rather than one query per alert. */
|
||||||
|
List<AmlAlertRule> findByAlertIdIn(Collection<Long> alertIds);
|
||||||
|
}
|
||||||
+106
@@ -0,0 +1,106 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.portfolio.aml.domain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How far a customer's repetition has gone, and what the bank's answer to it has to be.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* A customer who surfaces once is a question; one who surfaces for the fortieth time is an answer the bank has not
|
||||||
|
* acted on. Without a ladder every review looked the same - same screen, same three buttons, same outcome - so the
|
||||||
|
* fortieth review cost an officer the same effort as the first and changed as little.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Each tier does two things: it sets how long a review holds the customer out of the queue, and it says what the
|
||||||
|
* reviewer is expected to do. The windows shorten as the tier rises, because a customer the bank is more worried
|
||||||
|
* about should come back sooner, not later.
|
||||||
|
*/
|
||||||
|
public enum AmlRecurringEscalationTier {
|
||||||
|
|
||||||
|
/** Ordinary repetition. A review stands for a quarter unless the count climbs into the next tier. */
|
||||||
|
ROUTINE(0, 90),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enough repetition that the customer's risk rating is no longer just a KYC-time judgement. Reviewed monthly, and
|
||||||
|
* the reviewer is asked to consider whether the rating still fits.
|
||||||
|
*/
|
||||||
|
ELEVATED(7, 30),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Beyond what a branch officer should be closing on their own. Reviewed fortnightly, and the review is expected
|
||||||
|
* to be taken by someone senior.
|
||||||
|
*/
|
||||||
|
SENIOR(15, 14),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repetition at a level that is itself the suspicion. An STR is the expected outcome, and clearing at this tier
|
||||||
|
* is a decision that has to be defensible on its own - so the review stands for a week only.
|
||||||
|
*/
|
||||||
|
MANDATORY_STR(30, 7);
|
||||||
|
|
||||||
|
private final int minimumAlertCount;
|
||||||
|
private final int reviewValidityDays;
|
||||||
|
|
||||||
|
AmlRecurringEscalationTier(final int minimumAlertCount, final int reviewValidityDays) {
|
||||||
|
this.minimumAlertCount = minimumAlertCount;
|
||||||
|
this.reviewValidityDays = reviewValidityDays;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The tier a customer sitting on this many alerts falls into. */
|
||||||
|
public static AmlRecurringEscalationTier forAlertCount(final int alertCount) {
|
||||||
|
AmlRecurringEscalationTier tier = ROUTINE;
|
||||||
|
for (final AmlRecurringEscalationTier candidate : values()) {
|
||||||
|
if (alertCount >= candidate.minimumAlertCount) {
|
||||||
|
tier = candidate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMinimumAlertCount() {
|
||||||
|
return minimumAlertCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getReviewValidityDays() {
|
||||||
|
return reviewValidityDays;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How far the alert count may climb before a standing review is set aside and the customer returns early.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* A validity window alone would hold a customer out while their behaviour changed underneath it: reviewed at four
|
||||||
|
* alerts and then trips forty more the same week, the review would still stand for the full quarter. Allowing the
|
||||||
|
* count to grow by the tier's own span before forcing a return keeps ordinary repetition quiet while letting a
|
||||||
|
* genuine change in behaviour break through. Tighter at the higher tiers, where less change should be tolerated.
|
||||||
|
*/
|
||||||
|
public int alertGrowthBeforeEarlyReturn() {
|
||||||
|
return switch (this) {
|
||||||
|
case ROUTINE -> 5;
|
||||||
|
case ELEVATED -> 4;
|
||||||
|
case SENIOR -> 3;
|
||||||
|
case MANDATORY_STR -> 2;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Whether a review at this tier is expected to raise an STR rather than close the customer off. */
|
||||||
|
public boolean expectsStr() {
|
||||||
|
return this == MANDATORY_STR;
|
||||||
|
}
|
||||||
|
}
|
||||||
+59
@@ -26,6 +26,7 @@ import jakarta.persistence.Id;
|
|||||||
import jakarta.persistence.JoinColumn;
|
import jakarta.persistence.JoinColumn;
|
||||||
import jakarta.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import org.apache.fineract.portfolio.client.domain.Client;
|
import org.apache.fineract.portfolio.client.domain.Client;
|
||||||
import org.apache.fineract.useradministration.domain.AppUser;
|
import org.apache.fineract.useradministration.domain.AppUser;
|
||||||
@@ -65,6 +66,20 @@ public class AmlRecurringReview {
|
|||||||
@Column(name = "reviewed_on", nullable = false)
|
@Column(name = "reviewed_on", nullable = false)
|
||||||
private LocalDateTime reviewedOn;
|
private LocalDateTime reviewedOn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The date this review stops standing. Null on reviews taken before validity existed, which keep the older
|
||||||
|
* behaviour of lapsing the moment one more alert lands.
|
||||||
|
*/
|
||||||
|
@Column(name = "valid_until")
|
||||||
|
private LocalDate validUntil;
|
||||||
|
|
||||||
|
@Column(name = "escalation_tier", length = 20)
|
||||||
|
private String escalationTier;
|
||||||
|
|
||||||
|
/** How many of the customer's open alerts this review actually disposed of. */
|
||||||
|
@Column(name = "alerts_actioned")
|
||||||
|
private Integer alertsActioned;
|
||||||
|
|
||||||
protected AmlRecurringReview() {}
|
protected AmlRecurringReview() {}
|
||||||
|
|
||||||
public static AmlRecurringReview record(final Client client, final int alertCountAtReview,
|
public static AmlRecurringReview record(final Client client, final int alertCountAtReview,
|
||||||
@@ -76,9 +91,22 @@ public class AmlRecurringReview {
|
|||||||
review.notes = notes;
|
review.notes = notes;
|
||||||
review.reviewedBy = reviewedBy;
|
review.reviewedBy = reviewedBy;
|
||||||
review.reviewedOn = LocalDateTime.now();
|
review.reviewedOn = LocalDateTime.now();
|
||||||
|
|
||||||
|
// The tier follows from the count, not from what the reviewer picked: how often a customer has surfaced is a
|
||||||
|
// fact about them, and letting the outcome set it would let a customer be held at ROUTINE indefinitely by
|
||||||
|
// always being cleared.
|
||||||
|
final AmlRecurringEscalationTier tier = AmlRecurringEscalationTier.forAlertCount(alertCountAtReview);
|
||||||
|
review.escalationTier = tier.name();
|
||||||
|
review.validUntil = LocalDate.now().plusDays(tier.getReviewValidityDays());
|
||||||
|
review.alertsActioned = 0;
|
||||||
return review;
|
return review;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Records how many open alerts the review disposed of, once the caller has acted on them. */
|
||||||
|
public void recordAlertsActioned(final int count) {
|
||||||
|
this.alertsActioned = count;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@@ -106,4 +134,35 @@ public class AmlRecurringReview {
|
|||||||
public LocalDateTime getReviewedOn() {
|
public LocalDateTime getReviewedOn() {
|
||||||
return reviewedOn;
|
return reviewedOn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LocalDate getValidUntil() {
|
||||||
|
return validUntil;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AmlRecurringEscalationTier getEscalationTier() {
|
||||||
|
return escalationTier == null ? AmlRecurringEscalationTier.ROUTINE : AmlRecurringEscalationTier.valueOf(escalationTier);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getAlertsActioned() {
|
||||||
|
return alertsActioned;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether this review still holds the customer out of the review queue.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Two ways it stops standing. Its window runs out, or the customer's behaviour moves on far enough that the
|
||||||
|
* review no longer describes them - judged by how much the alert count has grown since, against the allowance for
|
||||||
|
* the tier it was taken at. A review with no window at all is a pre-existing one, and keeps the original rule of
|
||||||
|
* lapsing as soon as one more alert arrives.
|
||||||
|
*/
|
||||||
|
public boolean stillStands(final int currentAlertCount) {
|
||||||
|
if (validUntil == null) {
|
||||||
|
return currentAlertCount <= alertCountAtReview;
|
||||||
|
}
|
||||||
|
if (LocalDate.now().isAfter(validUntil)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return currentAlertCount - alertCountAtReview < getEscalationTier().alertGrowthBeforeEarlyReturn();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+83
@@ -0,0 +1,83 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.portfolio.aml.domain;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One alert covered by an STR case.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* A case escalated from a single transaction covers that one alert. A case raised off a customer's repeated behaviour
|
||||||
|
* covers all the alerts that make up the pattern - which is what an STR to FIU-IND actually describes, and what the
|
||||||
|
* Principal Officer has to be able to read in one place.
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "m_aml_str_case_alert")
|
||||||
|
public class AmlStrCaseAlert {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@ManyToOne(optional = false)
|
||||||
|
@JoinColumn(name = "str_case_id", nullable = false)
|
||||||
|
private AmlStrCase strCase;
|
||||||
|
|
||||||
|
@ManyToOne(optional = false)
|
||||||
|
@JoinColumn(name = "alert_id", nullable = false)
|
||||||
|
private AmlAlert alert;
|
||||||
|
|
||||||
|
@Column(name = "added_on_utc", nullable = false)
|
||||||
|
private LocalDateTime addedOn;
|
||||||
|
|
||||||
|
protected AmlStrCaseAlert() {}
|
||||||
|
|
||||||
|
public static AmlStrCaseAlert link(final AmlStrCase strCase, final AmlAlert alert) {
|
||||||
|
final AmlStrCaseAlert link = new AmlStrCaseAlert();
|
||||||
|
link.strCase = strCase;
|
||||||
|
link.alert = alert;
|
||||||
|
link.addedOn = LocalDateTime.now();
|
||||||
|
return link;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AmlStrCase getStrCase() {
|
||||||
|
return strCase;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AmlAlert getAlert() {
|
||||||
|
return alert;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getAddedOn() {
|
||||||
|
return addedOn;
|
||||||
|
}
|
||||||
|
}
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.portfolio.aml.domain;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface AmlStrCaseAlertRepository extends JpaRepository<AmlStrCaseAlert, Long> {
|
||||||
|
|
||||||
|
/** The alerts one case covers, oldest first - the order the pattern happened in. */
|
||||||
|
List<AmlStrCaseAlert> findByStrCase_IdOrderByAlert_RaisedOnAsc(Long strCaseId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The case already covering an alert, if any.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* What stops a transaction reaching FIU-IND twice: an alert already inside a case is not attached to a second
|
||||||
|
* one, however it comes to be escalated again.
|
||||||
|
*/
|
||||||
|
Optional<AmlStrCaseAlert> findByAlert_Id(Long alertId);
|
||||||
|
|
||||||
|
long countByStrCase_Id(Long strCaseId);
|
||||||
|
}
|
||||||
+4
@@ -20,6 +20,7 @@ package org.apache.fineract.portfolio.aml.domain;
|
|||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
@@ -28,6 +29,9 @@ public interface AmlStrCaseRepository extends JpaRepository<AmlStrCase, Long> {
|
|||||||
|
|
||||||
long countByClient_Id(Long clientId);
|
long countByClient_Id(Long clientId);
|
||||||
|
|
||||||
|
/** The case already open for a transaction, so escalating it again does not open a second one. */
|
||||||
|
Optional<AmlStrCase> findByAlertId(Long alertId);
|
||||||
|
|
||||||
List<AmlStrCase> findByStatus(String status);
|
List<AmlStrCase> findByStatus(String status);
|
||||||
|
|
||||||
@Query("SELECT c FROM AmlStrCase c WHERE c.status = 'CONCLUDED_SUSPICIOUS' AND c.concludedOn BETWEEN :from AND :to")
|
@Query("SELECT c FROM AmlStrCase c WHERE c.status = 'CONCLUDED_SUSPICIOUS' AND c.concludedOn BETWEEN :from AND :to")
|
||||||
|
|||||||
+7
@@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.fineract.portfolio.aml.domain;
|
package org.apache.fineract.portfolio.aml.domain;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
@@ -32,4 +33,10 @@ public interface AmlTransactionRuleRepository extends JpaRepository<AmlTransacti
|
|||||||
* by hand from the ledger.
|
* by hand from the ledger.
|
||||||
*/
|
*/
|
||||||
Optional<AmlTransactionRule> findByRuleCode(String ruleCode);
|
Optional<AmlTransactionRule> findByRuleCode(String ruleCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Every rule named in the given codes, in one read. The alert screen resolves the rules each transaction matched
|
||||||
|
* into descriptions and severities; doing that a code at a time would be one query per rule per alert.
|
||||||
|
*/
|
||||||
|
List<AmlTransactionRule> findByRuleCodeIn(Collection<String> ruleCodes);
|
||||||
}
|
}
|
||||||
|
|||||||
+219
@@ -0,0 +1,219 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.portfolio.client.domain;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What one customer's money actually did over a period, and what that says about their rating.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* A risk rating describes behaviour, and behaviour is a period rather than an event. Judging it from the alert feed
|
||||||
|
* meant a customer appeared the moment one transaction tripped a rule and was recommended for re-rating on that alone
|
||||||
|
* - a single shop purchase could argue for lowering a High rating, and a single large deposit for raising a Low one.
|
||||||
|
* Neither is a pattern.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* One row is one window for one customer, computed nightly. Upgrades and downgrades read different windows, because
|
||||||
|
* the questions are not symmetric: a concern is about what the customer is doing now, and confidence needs a year of
|
||||||
|
* it. The suggestion is stored with the figures it was drawn from, so an officer reviewing it months later sees what
|
||||||
|
* the system was looking at rather than a conclusion with no working.
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "m_client_behaviour_window")
|
||||||
|
public class ClientBehaviourWindow {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "client_id", nullable = false)
|
||||||
|
private Long clientId;
|
||||||
|
|
||||||
|
@Column(name = "window_from", nullable = false)
|
||||||
|
private LocalDate windowFrom;
|
||||||
|
|
||||||
|
@Column(name = "window_to", nullable = false)
|
||||||
|
private LocalDate windowTo;
|
||||||
|
|
||||||
|
@Column(name = "txn_count")
|
||||||
|
private Integer txnCount;
|
||||||
|
|
||||||
|
@Column(name = "distinct_months")
|
||||||
|
private Integer distinctMonths;
|
||||||
|
|
||||||
|
@Column(name = "credit_total", precision = 19, scale = 6)
|
||||||
|
private BigDecimal creditTotal;
|
||||||
|
|
||||||
|
@Column(name = "debit_total", precision = 19, scale = 6)
|
||||||
|
private BigDecimal debitTotal;
|
||||||
|
|
||||||
|
@Column(name = "largest_txn", precision = 19, scale = 6)
|
||||||
|
private BigDecimal largestTxn;
|
||||||
|
|
||||||
|
@Column(name = "cash_txn_count")
|
||||||
|
private Integer cashTxnCount;
|
||||||
|
|
||||||
|
@Column(name = "cash_total", precision = 19, scale = 6)
|
||||||
|
private BigDecimal cashTotal;
|
||||||
|
|
||||||
|
@Column(name = "large_txn_count")
|
||||||
|
private Integer largeTxnCount;
|
||||||
|
|
||||||
|
@Column(name = "declared_annual_income", precision = 19, scale = 6)
|
||||||
|
private BigDecimal declaredAnnualIncome;
|
||||||
|
|
||||||
|
@Column(name = "declared_annual_turnover", precision = 19, scale = 6)
|
||||||
|
private BigDecimal declaredAnnualTurnover;
|
||||||
|
|
||||||
|
@Column(name = "income_ratio", precision = 19, scale = 6)
|
||||||
|
private BigDecimal incomeRatio;
|
||||||
|
|
||||||
|
@Column(name = "alert_count")
|
||||||
|
private Integer alertCount;
|
||||||
|
|
||||||
|
@Column(name = "str_case_count")
|
||||||
|
private Integer strCaseCount;
|
||||||
|
|
||||||
|
@Column(name = "risk_category_at_review")
|
||||||
|
private Integer riskCategoryAtReview;
|
||||||
|
|
||||||
|
/** UP, DOWN or HOLD. */
|
||||||
|
@Column(name = "suggested_direction", length = 10)
|
||||||
|
private String suggestedDirection;
|
||||||
|
|
||||||
|
@Column(name = "suggested_category")
|
||||||
|
private Integer suggestedCategory;
|
||||||
|
|
||||||
|
@Column(name = "suggestion_reason", length = 500)
|
||||||
|
private String suggestionReason;
|
||||||
|
|
||||||
|
@Column(name = "computed_on")
|
||||||
|
private LocalDateTime computedOn;
|
||||||
|
|
||||||
|
protected ClientBehaviourWindow() {}
|
||||||
|
|
||||||
|
public static ClientBehaviourWindow of(final Long clientId, final LocalDate windowFrom, final LocalDate windowTo) {
|
||||||
|
final ClientBehaviourWindow window = new ClientBehaviourWindow();
|
||||||
|
window.clientId = clientId;
|
||||||
|
window.windowFrom = windowFrom;
|
||||||
|
window.windowTo = windowTo;
|
||||||
|
window.computedOn = LocalDateTime.now();
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void recordDistinctMonths(final Integer months) {
|
||||||
|
this.distinctMonths = months;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getDistinctMonths() {
|
||||||
|
return this.distinctMonths;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void recordActivity(final Integer txnCount, final BigDecimal creditTotal, final BigDecimal debitTotal,
|
||||||
|
final BigDecimal largestTxn, final Integer cashTxnCount, final BigDecimal cashTotal, final Integer largeTxnCount) {
|
||||||
|
this.txnCount = txnCount;
|
||||||
|
this.creditTotal = creditTotal;
|
||||||
|
this.debitTotal = debitTotal;
|
||||||
|
this.largestTxn = largestTxn;
|
||||||
|
this.cashTxnCount = cashTxnCount;
|
||||||
|
this.cashTotal = cashTotal;
|
||||||
|
this.largeTxnCount = largeTxnCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void recordMonitoring(final Integer alertCount, final Integer strCaseCount, final Integer riskCategoryAtReview) {
|
||||||
|
this.alertCount = alertCount;
|
||||||
|
this.strCaseCount = strCaseCount;
|
||||||
|
this.riskCategoryAtReview = riskCategoryAtReview;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turnover measured against what the customer said to expect.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Null rather than zero when no income was declared: the ratio is unknown, not nil, and a rule that treats an
|
||||||
|
* unknown as a benign zero would clear every customer the bank never asked.
|
||||||
|
*/
|
||||||
|
public void recordDeclared(final BigDecimal income, final BigDecimal turnover, final BigDecimal periodTurnover) {
|
||||||
|
this.declaredAnnualIncome = income;
|
||||||
|
this.declaredAnnualTurnover = turnover;
|
||||||
|
final BigDecimal basis = income != null && income.signum() > 0 ? income
|
||||||
|
: (turnover != null && turnover.signum() > 0 ? turnover : null);
|
||||||
|
this.incomeRatio = basis == null || periodTurnover == null ? null
|
||||||
|
: periodTurnover.divide(basis, 6, java.math.RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void recordSuggestion(final String direction, final Integer category, final String reason) {
|
||||||
|
this.suggestedDirection = direction;
|
||||||
|
this.suggestedCategory = category;
|
||||||
|
this.suggestionReason = reason == null || reason.length() <= 500 ? reason : reason.substring(0, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getClientId() {
|
||||||
|
return this.clientId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDate getWindowFrom() {
|
||||||
|
return this.windowFrom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDate getWindowTo() {
|
||||||
|
return this.windowTo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getTxnCount() {
|
||||||
|
return this.txnCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getCashTotal() {
|
||||||
|
return this.cashTotal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getLargeTxnCount() {
|
||||||
|
return this.largeTxnCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getAlertCount() {
|
||||||
|
return this.alertCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getStrCaseCount() {
|
||||||
|
return this.strCaseCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getRiskCategoryAtReview() {
|
||||||
|
return this.riskCategoryAtReview;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSuggestedDirection() {
|
||||||
|
return this.suggestedDirection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getSuggestedCategory() {
|
||||||
|
return this.suggestedCategory;
|
||||||
|
}
|
||||||
|
}
|
||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.portfolio.client.domain;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
|
public interface ClientBehaviourWindowRepository extends JpaRepository<ClientBehaviourWindow, Long> {
|
||||||
|
|
||||||
|
List<ClientBehaviourWindow> findByClientId(Long clientId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the windows computed for a given day before the job writes that day's.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* The job is a recomputation, not an append. Re-running it - after a failure, or twice in a night - must leave one
|
||||||
|
* set of windows rather than a customer appearing several times on the review screen with slightly different
|
||||||
|
* figures.
|
||||||
|
*/
|
||||||
|
@Modifying
|
||||||
|
@Query("DELETE FROM ClientBehaviourWindow w WHERE w.windowTo = :windowTo")
|
||||||
|
void deleteByWindowTo(@Param("windowTo") LocalDate windowTo);
|
||||||
|
}
|
||||||
+58
@@ -291,6 +291,31 @@ public class ClientKyc extends AbstractAuditableWithUTCDateTimeCustom<Long> {
|
|||||||
@Column(name = "form15_fy", length = 10)
|
@Column(name = "form15_fy", length = 10)
|
||||||
private String form15Fy;
|
private String form15Fy;
|
||||||
|
|
||||||
|
// ── Risk profile ─────────────────────────────────────────────────────────
|
||||||
|
/**
|
||||||
|
* Customer facts the risk re-rating policy tests against, as against anything the customer transacted.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* A politically exposed person is not downgraded because their activity looks ordinary — that is precisely the
|
||||||
|
* risk — and the same holds for a sanctions or adverse-media match. False means "not recorded as such", which is
|
||||||
|
* the correct reading for a book where nobody was ever asked; it is not an assertion that the customer is clean.
|
||||||
|
*/
|
||||||
|
@Column(name = "is_pep", nullable = false)
|
||||||
|
private boolean isPep;
|
||||||
|
|
||||||
|
@Column(name = "sanctions_match", nullable = false)
|
||||||
|
private boolean sanctionsMatch;
|
||||||
|
|
||||||
|
@Column(name = "adverse_media_match", nullable = false)
|
||||||
|
private boolean adverseMediaMatch;
|
||||||
|
|
||||||
|
/** What the customer told the bank to expect, which their actual turnover is measured against. */
|
||||||
|
@Column(name = "declared_annual_income", precision = 19, scale = 6)
|
||||||
|
private BigDecimal declaredAnnualIncome;
|
||||||
|
|
||||||
|
@Column(name = "declared_annual_turnover", precision = 19, scale = 6)
|
||||||
|
private BigDecimal declaredAnnualTurnover;
|
||||||
|
|
||||||
// ── CKYCRR ───────────────────────────────────────────────────────────────
|
// ── CKYCRR ───────────────────────────────────────────────────────────────
|
||||||
/** Central KYC Records Registry number issued by CERSAI */
|
/** Central KYC Records Registry number issued by CERSAI */
|
||||||
@Column(name = "ckyc_number", length = 14)
|
@Column(name = "ckyc_number", length = 14)
|
||||||
@@ -527,6 +552,19 @@ public class ClientKyc extends AbstractAuditableWithUTCDateTimeCustom<Long> {
|
|||||||
v -> this.aadhaarReceiptRemarks = v);
|
v -> this.aadhaarReceiptRemarks = v);
|
||||||
updateDateField(command, "aadhaarReceiptTakenOn", this.aadhaarReceiptTakenOn, actualChanges,
|
updateDateField(command, "aadhaarReceiptTakenOn", this.aadhaarReceiptTakenOn, actualChanges,
|
||||||
v -> this.aadhaarReceiptTakenOn = v);
|
v -> this.aadhaarReceiptTakenOn = v);
|
||||||
|
// Risk profile. These are determinations about the customer rather than about a transaction, and the
|
||||||
|
// re-rating policy reads them directly: a PEP or a sanctions match holds a rating at High however ordinary the
|
||||||
|
// period's activity looks.
|
||||||
|
updateBooleanField(command, "isPep", this.isPep, actualChanges, v -> this.isPep = v != null ? v : false);
|
||||||
|
updateBooleanField(command, "sanctionsMatch", this.sanctionsMatch, actualChanges,
|
||||||
|
v -> this.sanctionsMatch = v != null ? v : false);
|
||||||
|
updateBooleanField(command, "adverseMediaMatch", this.adverseMediaMatch, actualChanges,
|
||||||
|
v -> this.adverseMediaMatch = v != null ? v : false);
|
||||||
|
updateBigDecimalField(command, "declaredAnnualIncome", this.declaredAnnualIncome, actualChanges,
|
||||||
|
v -> this.declaredAnnualIncome = v);
|
||||||
|
updateBigDecimalField(command, "declaredAnnualTurnover", this.declaredAnnualTurnover, actualChanges,
|
||||||
|
v -> this.declaredAnnualTurnover = v);
|
||||||
|
|
||||||
updateStringField(command, "enterprisePan", this.enterprisePan, actualChanges, v -> this.enterprisePan = v);
|
updateStringField(command, "enterprisePan", this.enterprisePan, actualChanges, v -> this.enterprisePan = v);
|
||||||
updateStringField(command, "cinNumber", this.cinNumber, actualChanges, v -> this.cinNumber = v);
|
updateStringField(command, "cinNumber", this.cinNumber, actualChanges, v -> this.cinNumber = v);
|
||||||
updateStringField(command, "dinNumber", this.dinNumber, actualChanges, v -> this.dinNumber = v);
|
updateStringField(command, "dinNumber", this.dinNumber, actualChanges, v -> this.dinNumber = v);
|
||||||
@@ -898,6 +936,26 @@ public class ClientKyc extends AbstractAuditableWithUTCDateTimeCustom<Long> {
|
|||||||
recalculateExpiryForRiskCategory();
|
recalculateExpiryForRiskCategory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isPep() {
|
||||||
|
return this.isPep;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSanctionsMatch() {
|
||||||
|
return this.sanctionsMatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAdverseMediaMatch() {
|
||||||
|
return this.adverseMediaMatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getDeclaredAnnualIncome() {
|
||||||
|
return this.declaredAnnualIncome;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getDeclaredAnnualTurnover() {
|
||||||
|
return this.declaredAnnualTurnover;
|
||||||
|
}
|
||||||
|
|
||||||
public String getPanNumber() {
|
public String getPanNumber() {
|
||||||
return panNumber;
|
return panNumber;
|
||||||
}
|
}
|
||||||
|
|||||||
+74
@@ -0,0 +1,74 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.portfolio.client.domain;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One number the risk re-rating policy is made of - a window length, a minimum transaction count, a cash threshold.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Held as data because these are the bank's risk appetite rather than engineering constants. How long a customer must
|
||||||
|
* behave before a High rating comes down is a compliance judgement, and a co-operative bank whose members transact
|
||||||
|
* three times a month needs different figures from one lending to traders.
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "m_risk_policy_parameter")
|
||||||
|
public class RiskPolicyParameter {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "parameter_key", nullable = false, length = 80)
|
||||||
|
private String parameterKey;
|
||||||
|
|
||||||
|
@Column(name = "parameter_value", nullable = false, precision = 19, scale = 2)
|
||||||
|
private BigDecimal parameterValue;
|
||||||
|
|
||||||
|
@Column(name = "description", length = 500)
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@Column(name = "last_modified_by")
|
||||||
|
private Long lastModifiedBy;
|
||||||
|
|
||||||
|
@Column(name = "last_modified_on")
|
||||||
|
private LocalDateTime lastModifiedOn;
|
||||||
|
|
||||||
|
protected RiskPolicyParameter() {}
|
||||||
|
|
||||||
|
public String getParameterKey() {
|
||||||
|
return this.parameterKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getParameterValue() {
|
||||||
|
return this.parameterValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return this.description;
|
||||||
|
}
|
||||||
|
}
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.portfolio.client.domain;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface RiskPolicyParameterRepository extends JpaRepository<RiskPolicyParameter, Long> {}
|
||||||
+19
-29
@@ -31,20 +31,15 @@ import jakarta.ws.rs.Produces;
|
|||||||
import jakarta.ws.rs.QueryParam;
|
import jakarta.ws.rs.QueryParam;
|
||||||
import jakarta.ws.rs.core.MediaType;
|
import jakarta.ws.rs.core.MediaType;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Supplier;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.fineract.command.core.CommandPipeline;
|
import org.apache.fineract.commands.domain.CommandWrapper;
|
||||||
|
import org.apache.fineract.commands.service.CommandWrapperBuilder;
|
||||||
|
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||||
|
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
||||||
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||||
import org.apache.fineract.portfolio.paymenttype.command.PaymentTypeCreateCommand;
|
|
||||||
import org.apache.fineract.portfolio.paymenttype.command.PaymentTypeDeleteCommand;
|
|
||||||
import org.apache.fineract.portfolio.paymenttype.command.PaymentTypeUpdateCommand;
|
|
||||||
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeCreateRequest;
|
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeCreateRequest;
|
||||||
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeCreateResponse;
|
|
||||||
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeData;
|
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeData;
|
||||||
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeDeleteRequest;
|
|
||||||
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeDeleteResponse;
|
|
||||||
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeUpdateRequest;
|
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeUpdateRequest;
|
||||||
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeUpdateResponse;
|
|
||||||
import org.apache.fineract.portfolio.paymenttype.service.PaymentTypeReadService;
|
import org.apache.fineract.portfolio.paymenttype.service.PaymentTypeReadService;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -55,7 +50,7 @@ import org.springframework.stereotype.Component;
|
|||||||
public class PaymentTypeApiResource {
|
public class PaymentTypeApiResource {
|
||||||
|
|
||||||
private final PaymentTypeReadService readPlatformService;
|
private final PaymentTypeReadService readPlatformService;
|
||||||
private final CommandPipeline commandPipeline;
|
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||||
private final DefaultToApiJsonSerializer<PaymentTypeData> jsonSerializer;
|
private final DefaultToApiJsonSerializer<PaymentTypeData> jsonSerializer;
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@@ -79,14 +74,13 @@ public class PaymentTypeApiResource {
|
|||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
@Operation(summary = "Create a Payment Type", description = "Creates a new Payment type")
|
@Operation(summary = "Create a Payment Type", description = "Creates a new Payment type")
|
||||||
public PaymentTypeCreateResponse createPaymentType(PaymentTypeCreateRequest request) {
|
public String createPaymentType(final PaymentTypeCreateRequest request) {
|
||||||
final var command = new PaymentTypeCreateCommand();
|
final CommandWrapper commandRequest = new CommandWrapperBuilder().createPaymentType()
|
||||||
|
.withJson(jsonSerializer.serialize(request)).build();
|
||||||
|
|
||||||
command.setPayload(request);
|
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||||
|
|
||||||
final Supplier<PaymentTypeCreateResponse> response = commandPipeline.send(command);
|
return jsonSerializer.serialize(result);
|
||||||
|
|
||||||
return response.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@@ -94,18 +88,16 @@ public class PaymentTypeApiResource {
|
|||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
@Operation(summary = "Update a Payment Type", description = "Updates a Payment Type")
|
@Operation(summary = "Update a Payment Type", description = "Updates a Payment Type")
|
||||||
public PaymentTypeUpdateResponse updatePaymentType(@PathParam("paymentTypeId") final Long paymentTypeId,
|
public String updatePaymentType(@PathParam("paymentTypeId") final Long paymentTypeId, final PaymentTypeUpdateRequest request) {
|
||||||
final PaymentTypeUpdateRequest request) {
|
|
||||||
|
|
||||||
request.setId(paymentTypeId);
|
request.setId(paymentTypeId);
|
||||||
|
|
||||||
final var command = new PaymentTypeUpdateCommand();
|
final CommandWrapper commandRequest = new CommandWrapperBuilder().updatePaymentType(paymentTypeId)
|
||||||
|
.withJson(jsonSerializer.serialize(request)).build();
|
||||||
|
|
||||||
command.setPayload(request);
|
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||||
|
|
||||||
final Supplier<PaymentTypeUpdateResponse> response = commandPipeline.send(command);
|
return jsonSerializer.serialize(result);
|
||||||
|
|
||||||
return response.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@@ -113,14 +105,12 @@ public class PaymentTypeApiResource {
|
|||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
@Operation(summary = "Delete a Payment Type", description = "Deletes payment type")
|
@Operation(summary = "Delete a Payment Type", description = "Deletes payment type")
|
||||||
public PaymentTypeDeleteResponse deleteCode(@PathParam("paymentTypeId") final Long paymentTypeId) {
|
public String deleteCode(@PathParam("paymentTypeId") final Long paymentTypeId) {
|
||||||
|
|
||||||
final var command = new PaymentTypeDeleteCommand();
|
final CommandWrapper commandRequest = new CommandWrapperBuilder().deletePaymentType(paymentTypeId).build();
|
||||||
|
|
||||||
command.setPayload(PaymentTypeDeleteRequest.builder().id(paymentTypeId).build());
|
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||||
|
|
||||||
final Supplier<PaymentTypeDeleteResponse> response = commandPipeline.send(command);
|
return jsonSerializer.serialize(result);
|
||||||
|
|
||||||
return response.get();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-17
@@ -18,33 +18,50 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.fineract.portfolio.paymenttype.handler;
|
package org.apache.fineract.portfolio.paymenttype.handler;
|
||||||
|
|
||||||
import io.github.resilience4j.retry.annotation.Retry;
|
import org.apache.fineract.commands.annotation.CommandType;
|
||||||
import lombok.RequiredArgsConstructor;
|
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
||||||
import org.apache.fineract.command.core.Command;
|
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
||||||
import org.apache.fineract.command.core.CommandHandler;
|
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
|
||||||
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeCreateRequest;
|
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeCreateRequest;
|
||||||
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeCreateResponse;
|
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeCreateResponse;
|
||||||
import org.apache.fineract.portfolio.paymenttype.service.PaymentTypeWriteService;
|
import org.apache.fineract.portfolio.paymenttype.service.PaymentTypeWriteService;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@Slf4j
|
@Service
|
||||||
@Component
|
@CommandType(entity = "PAYMENTTYPE", action = "CREATE")
|
||||||
@RequiredArgsConstructor
|
public class PaymentTypeCreateCommandHandler implements NewCommandSourceHandler {
|
||||||
public class PaymentTypeCreateCommandHandler implements CommandHandler<PaymentTypeCreateRequest, PaymentTypeCreateResponse> {
|
|
||||||
|
|
||||||
private final PaymentTypeWriteService paymentTypeWriteService;
|
private final PaymentTypeWriteService paymentTypeWriteService;
|
||||||
|
|
||||||
@Retry(name = "commandPaymentTypeCreate", fallbackMethod = "fallback")
|
@Autowired
|
||||||
@Override
|
public PaymentTypeCreateCommandHandler(final PaymentTypeWriteService paymentTypeWriteService) {
|
||||||
@Transactional
|
this.paymentTypeWriteService = paymentTypeWriteService;
|
||||||
public PaymentTypeCreateResponse handle(Command<PaymentTypeCreateRequest> command) {
|
|
||||||
return paymentTypeWriteService.createPaymentType(command.getPayload());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public PaymentTypeCreateResponse fallback(Command<PaymentTypeCreateRequest> command, Throwable t) {
|
public CommandProcessingResult processCommand(final JsonCommand command) {
|
||||||
return CommandHandler.super.fallback(command, t);
|
|
||||||
|
final Boolean isSystemDefined = command.booleanObjectValueOfParameterNamed("isSystemDefined");
|
||||||
|
|
||||||
|
final PaymentTypeCreateRequest request = PaymentTypeCreateRequest.builder()
|
||||||
|
.name(command.stringValueOfParameterNamed("name"))
|
||||||
|
.description(command.stringValueOfParameterNamed("description"))
|
||||||
|
.isCashPayment(command.booleanObjectValueOfParameterNamed("isCashPayment"))
|
||||||
|
.position(command.longValueOfParameterNamed("position"))
|
||||||
|
.codeName(command.stringValueOfParameterNamed("codeName"))
|
||||||
|
.isSystemDefined(isSystemDefined != null ? isSystemDefined : Boolean.FALSE)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
final PaymentTypeCreateResponse response = this.paymentTypeWriteService.createPaymentType(request);
|
||||||
|
|
||||||
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withCommandId(command.commandId()) //
|
||||||
|
.withEntityId(response.getResourceId()) //
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-17
@@ -18,33 +18,41 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.fineract.portfolio.paymenttype.handler;
|
package org.apache.fineract.portfolio.paymenttype.handler;
|
||||||
|
|
||||||
import io.github.resilience4j.retry.annotation.Retry;
|
import org.apache.fineract.commands.annotation.CommandType;
|
||||||
import lombok.RequiredArgsConstructor;
|
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
||||||
import org.apache.fineract.command.core.Command;
|
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
||||||
import org.apache.fineract.command.core.CommandHandler;
|
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
|
||||||
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeDeleteRequest;
|
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeDeleteRequest;
|
||||||
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeDeleteResponse;
|
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeDeleteResponse;
|
||||||
import org.apache.fineract.portfolio.paymenttype.service.PaymentTypeWriteService;
|
import org.apache.fineract.portfolio.paymenttype.service.PaymentTypeWriteService;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@Slf4j
|
@Service
|
||||||
@Component
|
@CommandType(entity = "PAYMENTTYPE", action = "DELETE")
|
||||||
@RequiredArgsConstructor
|
public class PaymentTypeDeleteCommandHandler implements NewCommandSourceHandler {
|
||||||
public class PaymentTypeDeleteCommandHandler implements CommandHandler<PaymentTypeDeleteRequest, PaymentTypeDeleteResponse> {
|
|
||||||
|
|
||||||
private final PaymentTypeWriteService paymentTypeWriteService;
|
private final PaymentTypeWriteService paymentTypeWriteService;
|
||||||
|
|
||||||
@Retry(name = "commandPaymentTypeDelete", fallbackMethod = "fallback")
|
@Autowired
|
||||||
@Override
|
public PaymentTypeDeleteCommandHandler(final PaymentTypeWriteService paymentTypeWriteService) {
|
||||||
@Transactional
|
this.paymentTypeWriteService = paymentTypeWriteService;
|
||||||
public PaymentTypeDeleteResponse handle(Command<PaymentTypeDeleteRequest> command) {
|
|
||||||
return paymentTypeWriteService.deletePaymentType(command.getPayload());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public PaymentTypeDeleteResponse fallback(Command<PaymentTypeDeleteRequest> command, Throwable t) {
|
public CommandProcessingResult processCommand(final JsonCommand command) {
|
||||||
return CommandHandler.super.fallback(command, t);
|
|
||||||
|
final PaymentTypeDeleteRequest request = PaymentTypeDeleteRequest.builder().id(command.entityId()).build();
|
||||||
|
|
||||||
|
final PaymentTypeDeleteResponse response = this.paymentTypeWriteService.deletePaymentType(request);
|
||||||
|
|
||||||
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withCommandId(command.commandId()) //
|
||||||
|
.withEntityId(response.getResourceId()) //
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+35
-17
@@ -18,33 +18,51 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.fineract.portfolio.paymenttype.handler;
|
package org.apache.fineract.portfolio.paymenttype.handler;
|
||||||
|
|
||||||
import io.github.resilience4j.retry.annotation.Retry;
|
import org.apache.fineract.commands.annotation.CommandType;
|
||||||
import lombok.RequiredArgsConstructor;
|
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
||||||
import org.apache.fineract.command.core.Command;
|
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
||||||
import org.apache.fineract.command.core.CommandHandler;
|
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
|
||||||
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeUpdateRequest;
|
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeUpdateRequest;
|
||||||
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeUpdateResponse;
|
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeUpdateResponse;
|
||||||
import org.apache.fineract.portfolio.paymenttype.service.PaymentTypeWriteService;
|
import org.apache.fineract.portfolio.paymenttype.service.PaymentTypeWriteService;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@Slf4j
|
@Service
|
||||||
@Component
|
@CommandType(entity = "PAYMENTTYPE", action = "UPDATE")
|
||||||
@RequiredArgsConstructor
|
public class PaymentTypeUpdateCommandHandler implements NewCommandSourceHandler {
|
||||||
public class PaymentTypeUpdateCommandHandler implements CommandHandler<PaymentTypeUpdateRequest, PaymentTypeUpdateResponse> {
|
|
||||||
|
|
||||||
private final PaymentTypeWriteService paymentTypeWriteService;
|
private final PaymentTypeWriteService paymentTypeWriteService;
|
||||||
|
|
||||||
@Retry(name = "commandPaymentTypeUpdate", fallbackMethod = "fallback")
|
@Autowired
|
||||||
@Override
|
public PaymentTypeUpdateCommandHandler(final PaymentTypeWriteService paymentTypeWriteService) {
|
||||||
@Transactional
|
this.paymentTypeWriteService = paymentTypeWriteService;
|
||||||
public PaymentTypeUpdateResponse handle(Command<PaymentTypeUpdateRequest> command) {
|
|
||||||
return paymentTypeWriteService.updatePaymentType(command.getPayload());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public PaymentTypeUpdateResponse fallback(Command<PaymentTypeUpdateRequest> command, Throwable t) {
|
public CommandProcessingResult processCommand(final JsonCommand command) {
|
||||||
return CommandHandler.super.fallback(command, t);
|
|
||||||
|
final Boolean isSystemDefined = command.booleanObjectValueOfParameterNamed("isSystemDefined");
|
||||||
|
|
||||||
|
final PaymentTypeUpdateRequest request = PaymentTypeUpdateRequest.builder()
|
||||||
|
.id(command.entityId())
|
||||||
|
.name(command.stringValueOfParameterNamed("name"))
|
||||||
|
.description(command.stringValueOfParameterNamed("description"))
|
||||||
|
.isCashPayment(command.booleanObjectValueOfParameterNamed("isCashPayment"))
|
||||||
|
.position(command.longValueOfParameterNamed("position"))
|
||||||
|
.codeName(command.stringValueOfParameterNamed("codeName"))
|
||||||
|
.isSystemDefined(isSystemDefined != null ? isSystemDefined : Boolean.FALSE)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
final PaymentTypeUpdateResponse response = this.paymentTypeWriteService.updatePaymentType(request);
|
||||||
|
|
||||||
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withCommandId(command.commandId()) //
|
||||||
|
.withEntityId(response.getResourceId()) //
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-1
@@ -32,7 +32,8 @@ public enum DepositAccountOnClosureType {
|
|||||||
TRANSFER_TO_SAVINGS(200, "depositAccountClosureType.transferToSavings"), //
|
TRANSFER_TO_SAVINGS(200, "depositAccountClosureType.transferToSavings"), //
|
||||||
REINVEST_PRINCIPAL_AND_INTEREST(300, "depositAccountClosureType.reinvestPrincipalAndInterest"), //
|
REINVEST_PRINCIPAL_AND_INTEREST(300, "depositAccountClosureType.reinvestPrincipalAndInterest"), //
|
||||||
REINVEST_PRINCIPAL_ONLY(400, "depositAccountClosureType.reinvestPrincipalOnly"), //
|
REINVEST_PRINCIPAL_ONLY(400, "depositAccountClosureType.reinvestPrincipalOnly"), //
|
||||||
PARTIAL_REINVEST(500, "depositAccountClosureType.partialReinvest"); //
|
PARTIAL_REINVEST(500, "depositAccountClosureType.partialReinvest"), //
|
||||||
|
TRANSFER_TO_GL(600, "depositAccountClosureType.transferToGl"); //
|
||||||
|
|
||||||
private final Integer value;
|
private final Integer value;
|
||||||
private final String code;
|
private final String code;
|
||||||
@@ -53,6 +54,7 @@ public enum DepositAccountOnClosureType {
|
|||||||
case 300 -> REINVEST_PRINCIPAL_AND_INTEREST;
|
case 300 -> REINVEST_PRINCIPAL_AND_INTEREST;
|
||||||
case 400 -> REINVEST_PRINCIPAL_ONLY;
|
case 400 -> REINVEST_PRINCIPAL_ONLY;
|
||||||
case 500 -> PARTIAL_REINVEST;
|
case 500 -> PARTIAL_REINVEST;
|
||||||
|
case 600 -> TRANSFER_TO_GL;
|
||||||
default -> INVALID;
|
default -> INVALID;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -91,6 +93,17 @@ public enum DepositAccountOnClosureType {
|
|||||||
return this.equals(PARTIAL_REINVEST);
|
return this.equals(PARTIAL_REINVEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pays the closure proceeds into a GL account the maker picks, instead of a savings account or cash.
|
||||||
|
* Only the fixed-deposit premature-closure handler implements it -- see
|
||||||
|
* DepositAccountDomainServiceJpa#handleFDAccountPreMatureClosure; every other closure path rejects it
|
||||||
|
* in DepositAccountTransactionDataValidator#validateClosing rather than falling through to the
|
||||||
|
* terminal "pay the balance out in cash" branch.
|
||||||
|
*/
|
||||||
|
public boolean isTransferToGl() {
|
||||||
|
return this.equals(TRANSFER_TO_GL);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: do we really need this?!?
|
// TODO: do we really need this?!?
|
||||||
public static Object[] integerValues() {
|
public static Object[] integerValues() {
|
||||||
return Arrays.stream(values()).filter(value -> !INVALID.equals(value)).map(value -> value.value).toList().toArray();
|
return Arrays.stream(values()).filter(value -> !INVALID.equals(value)).map(value -> value.value).toList().toArray();
|
||||||
|
|||||||
+35
-3
@@ -123,6 +123,7 @@ public final class DepositsApiConstants {
|
|||||||
public static final String isSeniorCitizenParamName = "isSeniorCitizen";
|
public static final String isSeniorCitizenParamName = "isSeniorCitizen";
|
||||||
public static final String seniorCitizenInterestRateParamName = "seniorCitizenInterestRate";
|
public static final String seniorCitizenInterestRateParamName = "seniorCitizenInterestRate";
|
||||||
public static final String tenureInMonthsParamName = "tenureInMonths";
|
public static final String tenureInMonthsParamName = "tenureInMonths";
|
||||||
|
public static final String tenureInDaysParamName = "tenureInDays";
|
||||||
public static final String interestCompoundingPeriodInMonthsParamName = "interestCompoundingPeriodInMonths";
|
public static final String interestCompoundingPeriodInMonthsParamName = "interestCompoundingPeriodInMonths";
|
||||||
|
|
||||||
// Preclosure parameters
|
// Preclosure parameters
|
||||||
@@ -142,6 +143,9 @@ public final class DepositsApiConstants {
|
|||||||
public static final String inMultiplesOfDepositTermParamName = "inMultiplesOfDepositTerm";
|
public static final String inMultiplesOfDepositTermParamName = "inMultiplesOfDepositTerm";
|
||||||
public static final String inMultiplesOfDepositTermTypeIdParamName = "inMultiplesOfDepositTermTypeId";
|
public static final String inMultiplesOfDepositTermTypeIdParamName = "inMultiplesOfDepositTermTypeId";
|
||||||
public static final String inMultiplesOfDepositTermType = "inMultiplesOfDepositTermType";
|
public static final String inMultiplesOfDepositTermType = "inMultiplesOfDepositTermType";
|
||||||
|
// Days after maturity a depositor still has to walk in and renew at the original maturity date --
|
||||||
|
// null/0 means this product keeps the instant, same-night auto-renewal every FD product had before.
|
||||||
|
public static final String renewalGracePeriodDaysParamName = "renewalGracePeriodDays";
|
||||||
|
|
||||||
public static final String depositAmountParamName = "depositAmount";
|
public static final String depositAmountParamName = "depositAmount";
|
||||||
public static final String depositMinAmountParamName = "minDepositAmount";
|
public static final String depositMinAmountParamName = "minDepositAmount";
|
||||||
@@ -208,7 +212,18 @@ public final class DepositsApiConstants {
|
|||||||
public static final String onAccountClosureIdParamName = "onAccountClosureId";
|
public static final String onAccountClosureIdParamName = "onAccountClosureId";
|
||||||
public static final String transferDescriptionParamName = "transferDescription";
|
public static final String transferDescriptionParamName = "transferDescription";
|
||||||
public static final String toSavingsAccountIdParamName = "toSavingsAccountId";
|
public static final String toSavingsAccountIdParamName = "toSavingsAccountId";
|
||||||
|
// Destination GL account for DepositAccountOnClosureType.TRANSFER_TO_GL -- the closure proceeds are
|
||||||
|
// credited straight to this GL instead of a savings account or cash.
|
||||||
|
public static final String toGlAccountIdParamName = "toGlAccountId";
|
||||||
public static final String reinvestAmountParamName = "reinvestAmount";
|
public static final String reinvestAmountParamName = "reinvestAmount";
|
||||||
|
// Lets a maker waive the product's configured pre-closure penalty for one premature closure --
|
||||||
|
// see FixedDepositAccount#waivePreClosurePenaltyForThisRequest for why this is a transient
|
||||||
|
// per-request flag rather than a stored account field.
|
||||||
|
public static final String waivePreClosurePenaltyParamName = "waivePreClosurePenalty";
|
||||||
|
// Why the deposit was closed before maturity -- see PrematureClosureReasonType. Persisted (unlike
|
||||||
|
// waivePreClosurePenaltyParamName above) as the RBI audit trail of which closures waived their
|
||||||
|
// penalty and why.
|
||||||
|
public static final String prematureClosureReasonIdParamName = "prematureClosureReasonId";
|
||||||
public static final String savingsAccounts = "savingsAccounts";
|
public static final String savingsAccounts = "savingsAccounts";
|
||||||
public static final String maturityInstructionIdParamName = "maturityInstructionId";
|
public static final String maturityInstructionIdParamName = "maturityInstructionId";
|
||||||
public static final String transferToSavingsIdParamName = "transferToSavingsId";
|
public static final String transferToSavingsIdParamName = "transferToSavingsId";
|
||||||
@@ -237,7 +252,7 @@ public final class DepositsApiConstants {
|
|||||||
SavingProductAccountingParams.PENALTY_INCOME_ACCOUNT_MAPPING.getValue(),
|
SavingProductAccountingParams.PENALTY_INCOME_ACCOUNT_MAPPING.getValue(),
|
||||||
SavingProductAccountingParams.INTEREST_PAYABLE.getValue(), SavingProductAccountingParams.PENALTIES_RECEIVABLE.getValue(),
|
SavingProductAccountingParams.INTEREST_PAYABLE.getValue(), SavingProductAccountingParams.PENALTIES_RECEIVABLE.getValue(),
|
||||||
SavingProductAccountingParams.FEES_RECEIVABLE.getValue(), chartsParamName, SavingsApiConstants.withHoldTaxParamName,
|
SavingProductAccountingParams.FEES_RECEIVABLE.getValue(), chartsParamName, SavingsApiConstants.withHoldTaxParamName,
|
||||||
SavingsApiConstants.taxGroupIdParamName));
|
SavingsApiConstants.taxGroupIdParamName, SavingsApiConstants.otherGlMappingsParamName));
|
||||||
|
|
||||||
private static final Set<String> PRECLOSURE_REQUEST_DATA_PARAMETERS = new HashSet<>(
|
private static final Set<String> PRECLOSURE_REQUEST_DATA_PARAMETERS = new HashSet<>(
|
||||||
Arrays.asList(preClosurePenalApplicableParamName, preClosurePenalInterestParamName, preClosurePenalInterestOnTypeIdParamName));
|
Arrays.asList(preClosurePenalApplicableParamName, preClosurePenalInterestParamName, preClosurePenalInterestOnTypeIdParamName));
|
||||||
@@ -247,11 +262,13 @@ public final class DepositsApiConstants {
|
|||||||
|
|
||||||
private static final Set<String> DEPOSIT_TERM_REQUEST_DATA_PARAMETERS = new HashSet<>(Arrays.asList(minDepositTermParamName,
|
private static final Set<String> DEPOSIT_TERM_REQUEST_DATA_PARAMETERS = new HashSet<>(Arrays.asList(minDepositTermParamName,
|
||||||
maxDepositTermParamName, minDepositTermTypeIdParamName, maxDepositTermTypeIdParamName, inMultiplesOfDepositTermParamName,
|
maxDepositTermParamName, minDepositTermTypeIdParamName, maxDepositTermTypeIdParamName, inMultiplesOfDepositTermParamName,
|
||||||
inMultiplesOfDepositTermTypeIdParamName, depositAmountParamName, depositMinAmountParamName, depositMaxAmountParamName));
|
inMultiplesOfDepositTermTypeIdParamName, depositAmountParamName, depositMinAmountParamName, depositMaxAmountParamName,
|
||||||
|
renewalGracePeriodDaysParamName));
|
||||||
|
|
||||||
private static final Set<String> DEPOSIT_TERM_RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList(minDepositTermParamName,
|
private static final Set<String> DEPOSIT_TERM_RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList(minDepositTermParamName,
|
||||||
maxDepositTermParamName, minDepositTermType, maxDepositTermType, inMultiplesOfDepositTermParamName,
|
maxDepositTermParamName, minDepositTermType, maxDepositTermType, inMultiplesOfDepositTermParamName,
|
||||||
inMultiplesOfDepositTermType, depositAmountParamName, depositMinAmountParamName, depositMaxAmountParamName));
|
inMultiplesOfDepositTermType, depositAmountParamName, depositMinAmountParamName, depositMaxAmountParamName,
|
||||||
|
renewalGracePeriodDaysParamName));
|
||||||
|
|
||||||
private static final Set<String> RECURRING_DETAILS_REQUEST_DATA_PARAMETERS = new HashSet<>(
|
private static final Set<String> RECURRING_DETAILS_REQUEST_DATA_PARAMETERS = new HashSet<>(
|
||||||
Arrays.asList(mandatoryRecommendedDepositAmountParamName, isMandatoryDepositParamName, allowWithdrawalParamName,
|
Arrays.asList(mandatoryRecommendedDepositAmountParamName, isMandatoryDepositParamName, allowWithdrawalParamName,
|
||||||
@@ -373,6 +390,8 @@ public final class DepositsApiConstants {
|
|||||||
fixedDepositRequestData.add("paymentChannelToFundSourceMappings");
|
fixedDepositRequestData.add("paymentChannelToFundSourceMappings");
|
||||||
fixedDepositRequestData.add("feeToIncomeAccountMappings");
|
fixedDepositRequestData.add("feeToIncomeAccountMappings");
|
||||||
fixedDepositRequestData.add("penaltyToIncomeAccountMappings");
|
fixedDepositRequestData.add("penaltyToIncomeAccountMappings");
|
||||||
|
fixedDepositRequestData.add(SavingsApiConstants.otherGlMappingsParamName);
|
||||||
|
fixedDepositRequestData.add("otherGlMappingsMap");
|
||||||
return fixedDepositRequestData;
|
return fixedDepositRequestData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -413,6 +432,10 @@ public final class DepositsApiConstants {
|
|||||||
recurringDepositRequestData.add("prematureWithdrawalOption");
|
recurringDepositRequestData.add("prematureWithdrawalOption");
|
||||||
recurringDepositRequestData.add("tenureFlexibility");
|
recurringDepositRequestData.add("tenureFlexibility");
|
||||||
recurringDepositRequestData.add("lienMarked");
|
recurringDepositRequestData.add("lienMarked");
|
||||||
|
recurringDepositRequestData.add("lienPercentage");
|
||||||
|
recurringDepositRequestData.add("missedInstallmentGraceDays");
|
||||||
|
recurringDepositRequestData.add("missedInstallmentPenaltyType");
|
||||||
|
recurringDepositRequestData.add("missedInstallmentPenaltyAmount");
|
||||||
recurringDepositRequestData.add("withdrawalFeeForTransfers");
|
recurringDepositRequestData.add("withdrawalFeeForTransfers");
|
||||||
recurringDepositRequestData.add("enableLockinPeriod");
|
recurringDepositRequestData.add("enableLockinPeriod");
|
||||||
recurringDepositRequestData.add("maturityInstructions");
|
recurringDepositRequestData.add("maturityInstructions");
|
||||||
@@ -472,6 +495,10 @@ public final class DepositsApiConstants {
|
|||||||
recurringDepositRequestData.add("prematureWithdrawalOption");
|
recurringDepositRequestData.add("prematureWithdrawalOption");
|
||||||
recurringDepositRequestData.add("tenureFlexibility");
|
recurringDepositRequestData.add("tenureFlexibility");
|
||||||
recurringDepositRequestData.add("lienMarked");
|
recurringDepositRequestData.add("lienMarked");
|
||||||
|
recurringDepositRequestData.add("lienPercentage");
|
||||||
|
recurringDepositRequestData.add("missedInstallmentGraceDays");
|
||||||
|
recurringDepositRequestData.add("missedInstallmentPenaltyType");
|
||||||
|
recurringDepositRequestData.add("missedInstallmentPenaltyAmount");
|
||||||
recurringDepositRequestData.add("maturityInstructions");
|
recurringDepositRequestData.add("maturityInstructions");
|
||||||
recurringDepositRequestData.add("creditMaturityProceeds");
|
recurringDepositRequestData.add("creditMaturityProceeds");
|
||||||
recurringDepositRequestData.add("penaltyGracePeriodMissedInstallments");
|
recurringDepositRequestData.add("penaltyGracePeriodMissedInstallments");
|
||||||
@@ -484,6 +511,8 @@ public final class DepositsApiConstants {
|
|||||||
recurringDepositRequestData.add("paymentChannelToFundSourceMappings");
|
recurringDepositRequestData.add("paymentChannelToFundSourceMappings");
|
||||||
recurringDepositRequestData.add("feeToIncomeAccountMappings");
|
recurringDepositRequestData.add("feeToIncomeAccountMappings");
|
||||||
recurringDepositRequestData.add("penaltyToIncomeAccountMappings");
|
recurringDepositRequestData.add("penaltyToIncomeAccountMappings");
|
||||||
|
recurringDepositRequestData.add(SavingsApiConstants.otherGlMappingsParamName);
|
||||||
|
recurringDepositRequestData.add("otherGlMappingsMap");
|
||||||
return recurringDepositRequestData;
|
return recurringDepositRequestData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -511,6 +540,7 @@ public final class DepositsApiConstants {
|
|||||||
fixedDepositInterestCalculationData.add(principalAmountParamName);
|
fixedDepositInterestCalculationData.add(principalAmountParamName);
|
||||||
fixedDepositInterestCalculationData.add(annualInterestRateParamName);
|
fixedDepositInterestCalculationData.add(annualInterestRateParamName);
|
||||||
fixedDepositInterestCalculationData.add(tenureInMonthsParamName);
|
fixedDepositInterestCalculationData.add(tenureInMonthsParamName);
|
||||||
|
fixedDepositInterestCalculationData.add(tenureInDaysParamName);
|
||||||
fixedDepositInterestCalculationData.add(interestPostingPeriodInMonthsParamName);
|
fixedDepositInterestCalculationData.add(interestPostingPeriodInMonthsParamName);
|
||||||
fixedDepositInterestCalculationData.add(interestCompoundingPeriodInMonthsParamName);
|
fixedDepositInterestCalculationData.add(interestCompoundingPeriodInMonthsParamName);
|
||||||
// Exact calendar-based calculation params
|
// Exact calendar-based calculation params
|
||||||
@@ -626,6 +656,8 @@ public final class DepositsApiConstants {
|
|||||||
recurringDepositRequestData.add(SavingsApiConstants.balanceSwapOptionParamName);
|
recurringDepositRequestData.add(SavingsApiConstants.balanceSwapOptionParamName);
|
||||||
recurringDepositRequestData.add(SavingsApiConstants.msmeParamName);
|
recurringDepositRequestData.add(SavingsApiConstants.msmeParamName);
|
||||||
recurringDepositRequestData.add(SavingsApiConstants.autoDebitFacilityParamName);
|
recurringDepositRequestData.add(SavingsApiConstants.autoDebitFacilityParamName);
|
||||||
|
// Lien Marked: how much of this deposit may be given as loan, capped by its product's percentage.
|
||||||
|
recurringDepositRequestData.add("lienPercentage");
|
||||||
recurringDepositRequestData.add(isSeniorCitizenParamName);
|
recurringDepositRequestData.add(isSeniorCitizenParamName);
|
||||||
recurringDepositRequestData.add(seniorCitizenInterestRateParamName);
|
recurringDepositRequestData.add(seniorCitizenInterestRateParamName);
|
||||||
return recurringDepositRequestData;
|
return recurringDepositRequestData;
|
||||||
|
|||||||
+70
@@ -0,0 +1,70 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.portfolio.savings;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Why a Fixed/Recurring Deposit was closed before maturity -- captured on every premature closure, not
|
||||||
|
* just the ones that waive the penalty, so the audit trail always shows a reason rather than only
|
||||||
|
* recording one when it happens to matter. {@link #isAutoWaived()} is the RBI-driven business rule this
|
||||||
|
* type exists to encode: a maker cannot leave the platform's own penalty-waiver decision to memory or a
|
||||||
|
* free-text note for these four reasons -- picking the reason IS the waiver decision, enforced on the
|
||||||
|
* server regardless of what a client happened to also send for the plain waive-penalty flag.
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum PrematureClosureReasonType {
|
||||||
|
|
||||||
|
INVALID(0, "prematureClosureReasonType.invalid", false), //
|
||||||
|
NORMAL(100, "prematureClosureReasonType.normal", false), //
|
||||||
|
PREMATURE_EXTENSION(200, "prematureClosureReasonType.prematureExtension", true), //
|
||||||
|
CONVERSION_TO_ANOTHER_TD(300, "prematureClosureReasonType.conversionToAnotherTd", true), //
|
||||||
|
DECEASED_SETTLEMENT(400, "prematureClosureReasonType.deceasedSettlement", true), //
|
||||||
|
NOMINEE_LEGAL_HEIR_CLOSURE(500, "prematureClosureReasonType.nomineeLegalHeirClosure", true); //
|
||||||
|
|
||||||
|
private final Integer value;
|
||||||
|
private final String code;
|
||||||
|
/** True when this reason, by itself, waives the pre-closure penalty regardless of any manual
|
||||||
|
* waive-penalty flag also sent -- see the class javadoc. */
|
||||||
|
private final boolean autoWaived;
|
||||||
|
|
||||||
|
PrematureClosureReasonType(final Integer value, final String code, final boolean autoWaived) {
|
||||||
|
this.value = value;
|
||||||
|
this.code = code;
|
||||||
|
this.autoWaived = autoWaived;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PrematureClosureReasonType fromInt(final Integer v) {
|
||||||
|
if (v == null) {
|
||||||
|
return INVALID;
|
||||||
|
}
|
||||||
|
return switch (v) {
|
||||||
|
case 100 -> NORMAL;
|
||||||
|
case 200 -> PREMATURE_EXTENSION;
|
||||||
|
case 300 -> CONVERSION_TO_ANOTHER_TD;
|
||||||
|
case 400 -> DECEASED_SETTLEMENT;
|
||||||
|
case 500 -> NOMINEE_LEGAL_HEIR_CLOSURE;
|
||||||
|
default -> INVALID;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInvalid() {
|
||||||
|
return this.equals(INVALID);
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
@@ -286,6 +286,15 @@ public class SavingsApiConstants {
|
|||||||
public static final String avgBalanceCalcPeriodParamName = "avgBalanceCalcPeriod";
|
public static final String avgBalanceCalcPeriodParamName = "avgBalanceCalcPeriod";
|
||||||
public static final String validForPeriodParamName = "validForPeriod";
|
public static final String validForPeriodParamName = "validForPeriod";
|
||||||
public static final String odAccountClosedZeroBalanceInDayClosingParamName = "odAccountClosedZeroBalanceInDayClosing";
|
public static final String odAccountClosedZeroBalanceInDayClosingParamName = "odAccountClosedZeroBalanceInDayClosing";
|
||||||
|
// Overdraft scheme rules a sanction on an account is held to: overdraftLimit is the ceiling (an
|
||||||
|
// amount), odMinLimit the floor, odSecurityType whether the limit may be clean, secured, or either.
|
||||||
|
public static final String odMinLimitParamName = "odMinLimit";
|
||||||
|
public static final String odSecurityTypeParamName = "odSecurityType";
|
||||||
|
// Excess drawing: whether an account may go past its sanctioned limit, by how much (a percentage of the
|
||||||
|
// limit), and the penal charge (% p.a.) levied on the excess alone for the days it stays excess.
|
||||||
|
public static final String odExcessAllowedParamName = "odExcessAllowed";
|
||||||
|
public static final String odExcessLimitPercentParamName = "odExcessLimitPercent";
|
||||||
|
public static final String odPenalRateParamName = "odPenalRate";
|
||||||
|
|
||||||
// Status of Account fields
|
// Status of Account fields
|
||||||
public static final String accountStatusParamName = "accountStatus";
|
public static final String accountStatusParamName = "accountStatus";
|
||||||
|
|||||||
+14
@@ -234,6 +234,20 @@ public final class SavingsAccountData implements Serializable {
|
|||||||
return this.transferInterestToLinkedAccount;
|
return this.transferInterestToLinkedAccount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True for a recurring deposit opened under a product whose Interest Calculation Type is "Simple": its interest
|
||||||
|
* never compounds. Transient because it is only read by the batch interest-posting engine.
|
||||||
|
*/
|
||||||
|
private transient boolean simpleInterest;
|
||||||
|
|
||||||
|
public void setSimpleInterest(final boolean simpleInterest) {
|
||||||
|
this.simpleInterest = simpleInterest;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSimpleInterest() {
|
||||||
|
return this.simpleInterest;
|
||||||
|
}
|
||||||
|
|
||||||
public static SavingsAccountData importInstanceIndividual(Long clientId, Long productId, Long fieldOfficerId, LocalDate submittedOnDate,
|
public static SavingsAccountData importInstanceIndividual(Long clientId, Long productId, Long fieldOfficerId, LocalDate submittedOnDate,
|
||||||
BigDecimal nominalAnnualInterestRate, EnumOptionData interestCompoundingPeriodTypeEnum,
|
BigDecimal nominalAnnualInterestRate, EnumOptionData interestCompoundingPeriodTypeEnum,
|
||||||
EnumOptionData interestPostingPeriodTypeEnum, EnumOptionData interestCalculationTypeEnum,
|
EnumOptionData interestPostingPeriodTypeEnum, EnumOptionData interestCalculationTypeEnum,
|
||||||
|
|||||||
+10
@@ -152,6 +152,11 @@ public final class SavingsProductData implements Serializable {
|
|||||||
@Getter @Setter private String avgBalanceCalcPeriod;
|
@Getter @Setter private String avgBalanceCalcPeriod;
|
||||||
@Getter @Setter private String validForPeriod;
|
@Getter @Setter private String validForPeriod;
|
||||||
@Getter @Setter private Boolean odAccountClosedZeroBalanceInDayClosing;
|
@Getter @Setter private Boolean odAccountClosedZeroBalanceInDayClosing;
|
||||||
|
@Getter @Setter private BigDecimal odMinLimit;
|
||||||
|
@Getter @Setter private String odSecurityType;
|
||||||
|
@Getter @Setter private Boolean odExcessAllowed;
|
||||||
|
@Getter @Setter private BigDecimal odExcessLimitPercent;
|
||||||
|
@Getter @Setter private BigDecimal odPenalRate;
|
||||||
|
|
||||||
// Complex objects wrapped as Maps/Lists so Jackson converts them into the exact JSON your UI expects
|
// Complex objects wrapped as Maps/Lists so Jackson converts them into the exact JSON your UI expects
|
||||||
@Getter @Setter private Map<String, Object> accountFacilityConfig;
|
@Getter @Setter private Map<String, Object> accountFacilityConfig;
|
||||||
@@ -382,6 +387,11 @@ public final class SavingsProductData implements Serializable {
|
|||||||
target.setAvgBalanceCalcPeriod(source.getAvgBalanceCalcPeriod());
|
target.setAvgBalanceCalcPeriod(source.getAvgBalanceCalcPeriod());
|
||||||
target.setValidForPeriod(source.getValidForPeriod());
|
target.setValidForPeriod(source.getValidForPeriod());
|
||||||
target.setOdAccountClosedZeroBalanceInDayClosing(source.getOdAccountClosedZeroBalanceInDayClosing());
|
target.setOdAccountClosedZeroBalanceInDayClosing(source.getOdAccountClosedZeroBalanceInDayClosing());
|
||||||
|
target.setOdMinLimit(source.getOdMinLimit());
|
||||||
|
target.setOdSecurityType(source.getOdSecurityType());
|
||||||
|
target.setOdExcessAllowed(source.getOdExcessAllowed());
|
||||||
|
target.setOdExcessLimitPercent(source.getOdExcessLimitPercent());
|
||||||
|
target.setOdPenalRate(source.getOdPenalRate());
|
||||||
target.setOtherGlMappingsMap(source.getOtherGlMappingsMap());
|
target.setOtherGlMappingsMap(source.getOtherGlMappingsMap());
|
||||||
target.setAccountFacilityConfig(source.getAccountFacilityConfig());
|
target.setAccountFacilityConfig(source.getAccountFacilityConfig());
|
||||||
target.setAccountFacilityLimits(source.getAccountFacilityLimits());
|
target.setAccountFacilityLimits(source.getAccountFacilityLimits());
|
||||||
|
|||||||
+6
@@ -180,6 +180,12 @@ public final class SavingsHelper {
|
|||||||
immediateWithdrawalOfInterest);
|
immediateWithdrawalOfInterest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Money calculateInterestForAllPostingPeriods(final MonetaryCurrency currency, final List<PostingPeriod> allPeriods,
|
||||||
|
LocalDate accountLockedUntil, Boolean immediateWithdrawalOfInterest, final boolean simpleInterest) {
|
||||||
|
return COMPOUND_INTEREST_HELPER.calculateInterestForAllPostingPeriods(currency, allPeriods, accountLockedUntil,
|
||||||
|
immediateWithdrawalOfInterest, simpleInterest);
|
||||||
|
}
|
||||||
|
|
||||||
public Collection<Long> fetchPostInterestTransactionIds(Long accountId) {
|
public Collection<Long> fetchPostInterestTransactionIds(Long accountId) {
|
||||||
return this.accountTransfersReadPlatformService.fetchPostInterestTransactionIds(accountId);
|
return this.accountTransfersReadPlatformService.fetchPostInterestTransactionIds(accountId);
|
||||||
}
|
}
|
||||||
|
|||||||
+35
-1
@@ -40,6 +40,18 @@ public class CompoundInterestHelper {
|
|||||||
*/
|
*/
|
||||||
public Money calculateInterestForAllPostingPeriods(final MonetaryCurrency currency, final List<PostingPeriod> allPeriods,
|
public Money calculateInterestForAllPostingPeriods(final MonetaryCurrency currency, final List<PostingPeriod> allPeriods,
|
||||||
LocalDate lockUntil, Boolean interestTransferEnabled) {
|
LocalDate lockUntil, Boolean interestTransferEnabled) {
|
||||||
|
return calculateInterestForAllPostingPeriods(currency, allPeriods, lockUntil, interestTransferEnabled, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param simpleInterest
|
||||||
|
* - when true, earned interest is never added back to the balance it is earned on, so every period
|
||||||
|
* earns on the principal alone (a recurring deposit whose product's Interest Calculation Type is
|
||||||
|
* "Simple"). Compounding and posting periods still decide when interest is recognised and posted;
|
||||||
|
* they just stop changing how much is earned.
|
||||||
|
*/
|
||||||
|
public Money calculateInterestForAllPostingPeriods(final MonetaryCurrency currency, final List<PostingPeriod> allPeriods,
|
||||||
|
LocalDate lockUntil, Boolean interestTransferEnabled, final boolean simpleInterest) {
|
||||||
|
|
||||||
// sum up the 'rounded' values that are posted each posting period
|
// sum up the 'rounded' values that are posted each posting period
|
||||||
Money interestEarned = Money.zero(currency);
|
Money interestEarned = Money.zero(currency);
|
||||||
@@ -47,7 +59,8 @@ public class CompoundInterestHelper {
|
|||||||
// total interest earned in previous periods but not yet recognised
|
// total interest earned in previous periods but not yet recognised
|
||||||
BigDecimal compoundedInterest = BigDecimal.ZERO;
|
BigDecimal compoundedInterest = BigDecimal.ZERO;
|
||||||
BigDecimal unCompoundedInterest = BigDecimal.ZERO;
|
BigDecimal unCompoundedInterest = BigDecimal.ZERO;
|
||||||
final CompoundInterestValues compoundInterestValues = new CompoundInterestValues(compoundedInterest, unCompoundedInterest);
|
final CompoundInterestValues compoundInterestValues = simpleInterest ? new SimpleInterestValues()
|
||||||
|
: new CompoundInterestValues(compoundedInterest, unCompoundedInterest);
|
||||||
for (final PostingPeriod postingPeriod : allPeriods) {
|
for (final PostingPeriod postingPeriod : allPeriods) {
|
||||||
|
|
||||||
final BigDecimal interestEarnedThisPeriod = postingPeriod.calculateInterest(compoundInterestValues);
|
final BigDecimal interestEarnedThisPeriod = postingPeriod.calculateInterest(compoundInterestValues);
|
||||||
@@ -67,4 +80,25 @@ public class CompoundInterestHelper {
|
|||||||
|
|
||||||
return interestEarned;
|
return interestEarned;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interest values that refuse to compound: whatever a compounding period hands over to be compounded is dropped,
|
||||||
|
* so the balance interest is earned on never includes interest already earned.
|
||||||
|
*/
|
||||||
|
private static final class SimpleInterestValues extends CompoundInterestValues {
|
||||||
|
|
||||||
|
SimpleInterestValues() {
|
||||||
|
super(BigDecimal.ZERO, BigDecimal.ZERO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCompoundedInterest(final BigDecimal interestToBeCompounded) {
|
||||||
|
super.setCompoundedInterest(BigDecimal.ZERO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSimpleInterest() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -50,4 +50,9 @@ public class CompoundInterestValues {
|
|||||||
this.uncompoundedInterest = BigDecimal.ZERO;
|
this.uncompoundedInterest = BigDecimal.ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** True when earned interest must never earn interest itself - not across periods, and not within one either. */
|
||||||
|
public boolean isSimpleInterest() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+12
@@ -94,6 +94,18 @@ public final class DailyCompoundingPeriod implements CompoundingPeriod {
|
|||||||
return interestEarned;
|
return interestEarned;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Interest on each day's balance alone, none of it added to the balance - for simple interest. */
|
||||||
|
public BigDecimal calculateSimpleInterest(final BigDecimal interestRateAsFraction, final long daysInYear,
|
||||||
|
final BigDecimal minBalanceForInterestCalculation, final BigDecimal overdraftInterestRateAsFraction,
|
||||||
|
final BigDecimal minOverdraftForInterestCalculation) {
|
||||||
|
BigDecimal interestEarned = BigDecimal.ZERO;
|
||||||
|
for (final EndOfDayBalance balance : this.endOfDayBalances) {
|
||||||
|
interestEarned = interestEarned.add(balance.calculateInterestOnBalance(BigDecimal.ZERO, interestRateAsFraction, daysInYear,
|
||||||
|
minBalanceForInterestCalculation, overdraftInterestRateAsFraction, minOverdraftForInterestCalculation));
|
||||||
|
}
|
||||||
|
return interestEarned;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LocalDateInterval getPeriodInterval() {
|
public LocalDateInterval getPeriodInterval() {
|
||||||
return this.periodInterval;
|
return this.periodInterval;
|
||||||
|
|||||||
+10
-3
@@ -301,9 +301,16 @@ public final class PostingPeriod {
|
|||||||
// to be applied to the balanced for interest calculation
|
// to be applied to the balanced for interest calculation
|
||||||
for (final CompoundingPeriod compoundingPeriod : this.compoundingPeriods) {
|
for (final CompoundingPeriod compoundingPeriod : this.compoundingPeriods) {
|
||||||
|
|
||||||
final BigDecimal interestUnrounded = compoundingPeriod.calculateInterest(this.interestCompoundingType,
|
// A daily compounding period compounds day by day inside itself, so simple interest has to bypass it - zeroing
|
||||||
this.interestCalculationType, compoundInterestValues.getcompoundedInterest(), this.interestRateAsFraction,
|
// what is carried between periods alone still left a month's interest earning interest within the month.
|
||||||
this.daysInYear, this.minBalanceForInterestCalculation.getAmount(), this.overdraftInterestRateAsFraction,
|
final BigDecimal interestUnrounded = compoundInterestValues.isSimpleInterest()
|
||||||
|
&& compoundingPeriod instanceof DailyCompoundingPeriod dailyPeriod
|
||||||
|
? dailyPeriod.calculateSimpleInterest(this.interestRateAsFraction, this.daysInYear,
|
||||||
|
this.minBalanceForInterestCalculation.getAmount(), this.overdraftInterestRateAsFraction,
|
||||||
|
this.minOverdraftForInterestCalculation.getAmount())
|
||||||
|
: compoundingPeriod.calculateInterest(this.interestCompoundingType, this.interestCalculationType,
|
||||||
|
compoundInterestValues.getcompoundedInterest(), this.interestRateAsFraction, this.daysInYear,
|
||||||
|
this.minBalanceForInterestCalculation.getAmount(), this.overdraftInterestRateAsFraction,
|
||||||
this.minOverdraftForInterestCalculation.getAmount());
|
this.minOverdraftForInterestCalculation.getAmount());
|
||||||
BigDecimal unCompoundedInterest = compoundInterestValues.getuncompoundedInterest().add(interestUnrounded);
|
BigDecimal unCompoundedInterest = compoundInterestValues.getuncompoundedInterest().add(interestUnrounded);
|
||||||
compoundInterestValues.setuncompoundedInterest(unCompoundedInterest);
|
compoundInterestValues.setuncompoundedInterest(unCompoundedInterest);
|
||||||
|
|||||||
+4
@@ -801,6 +801,10 @@ public final class SavingsEnumerations {
|
|||||||
optionData = new EnumOptionData(DepositAccountOnClosureType.PARTIAL_REINVEST.getValue().longValue(),
|
optionData = new EnumOptionData(DepositAccountOnClosureType.PARTIAL_REINVEST.getValue().longValue(),
|
||||||
DepositAccountOnClosureType.PARTIAL_REINVEST.getCode(), "Partial Re-Invest");
|
DepositAccountOnClosureType.PARTIAL_REINVEST.getCode(), "Partial Re-Invest");
|
||||||
break;
|
break;
|
||||||
|
case TRANSFER_TO_GL:
|
||||||
|
optionData = new EnumOptionData(DepositAccountOnClosureType.TRANSFER_TO_GL.getValue().longValue(),
|
||||||
|
DepositAccountOnClosureType.TRANSFER_TO_GL.getCode(), "Transfer to GL Account");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return optionData;
|
return optionData;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -76,7 +76,8 @@ public class CurrentAccount extends AbstractAuditableCustom {
|
|||||||
@Column(name = "status_enum", nullable = false)
|
@Column(name = "status_enum", nullable = false)
|
||||||
private Integer statusEnum = 100;
|
private Integer statusEnum = 100;
|
||||||
|
|
||||||
// SubStatus: 0=None, 100=Inactive, 200=Dormant, 300=Block, 400=BlockDebit, 500=BlockCredit
|
// SubStatus, same codes as savings: 0=None, 100=Inactive, 200=Dormant, 300=Escheat, 400=Block, 500=BlockCredit,
|
||||||
|
// 600=BlockDebit
|
||||||
@Column(name = "sub_status_enum", nullable = false)
|
@Column(name = "sub_status_enum", nullable = false)
|
||||||
private Integer subStatusEnum = 0;
|
private Integer subStatusEnum = 0;
|
||||||
|
|
||||||
|
|||||||
+7
-1
@@ -38,6 +38,12 @@ public interface CurrentAccountRepository extends JpaRepository<CurrentAccount,
|
|||||||
@Query("SELECT ca FROM CurrentAccount ca WHERE ca.client.id = :clientId AND ca.statusEnum != 600")
|
@Query("SELECT ca FROM CurrentAccount ca WHERE ca.client.id = :clientId AND ca.statusEnum != 600")
|
||||||
List<CurrentAccount> findActiveByClientId(@Param("clientId") Long clientId);
|
List<CurrentAccount> findActiveByClientId(@Param("clientId") Long clientId);
|
||||||
|
|
||||||
@Query("SELECT COUNT(ca) FROM CurrentAccount ca WHERE ca.client.id = :clientId AND ca.productId = :productId AND ca.statusEnum != 600")
|
// statusEnum != 600 (CLOSED) let a client re-apply for the same product only once every prior
|
||||||
|
// account on it was closed -- but 400 (WITHDRAWN) and 500 (REJECTED), see CurrentAccount.withdraw()
|
||||||
|
// /.reject(), are equally terminal and were still being counted as "still has one", blocking a
|
||||||
|
// fresh application the client should have been free to make. 100/200/300 (submitted, approved,
|
||||||
|
// active) are the only statuses a second application on the same product should actually collide
|
||||||
|
// with.
|
||||||
|
@Query("SELECT COUNT(ca) FROM CurrentAccount ca WHERE ca.client.id = :clientId AND ca.productId = :productId AND ca.statusEnum IN (100, 200, 300)")
|
||||||
long countActiveByClientAndProduct(@Param("clientId") Long clientId, @Param("productId") Long productId);
|
long countActiveByClientAndProduct(@Param("clientId") Long clientId, @Param("productId") Long productId);
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-1
@@ -46,7 +46,7 @@ public class CurrentAccountTransaction extends AbstractPersistableCustom<Long> {
|
|||||||
@JoinColumn(name = "office_id", nullable = false)
|
@JoinColumn(name = "office_id", nullable = false)
|
||||||
private Office office;
|
private Office office;
|
||||||
|
|
||||||
// 1=Deposit, 2=Withdrawal, 3=InterestPosting, 4=Charge, 5=ChargeWaiver, 6=Transfer, 7=Reversal
|
// 1=Deposit, 2=Withdrawal, 3=InterestPosting, 4=Charge, 5=ChargeWaiver, 6=Transfer, 7=Reversal, 19=Escheat
|
||||||
@Column(name = "transaction_type_enum", nullable = false)
|
@Column(name = "transaction_type_enum", nullable = false)
|
||||||
private Integer transactionTypeEnum;
|
private Integer transactionTypeEnum;
|
||||||
|
|
||||||
@@ -176,6 +176,20 @@ public class CurrentAccountTransaction extends AbstractPersistableCustom<Long> {
|
|||||||
return txn;
|
return txn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// transactionTypeEnum = 19 (Escheat) -- the whole balance moved to the escheat liability, same code as savings
|
||||||
|
public static CurrentAccountTransaction escheat(CurrentAccount account, Office office,
|
||||||
|
BigDecimal amount, LocalDate transactionDate) {
|
||||||
|
CurrentAccountTransaction txn = new CurrentAccountTransaction();
|
||||||
|
txn.currentAccount = account;
|
||||||
|
txn.office = office;
|
||||||
|
txn.transactionTypeEnum = 19;
|
||||||
|
txn.amount = amount;
|
||||||
|
txn.transactionDate = transactionDate;
|
||||||
|
txn.remarks = "Escheat: dormant for the product's escheat period, balance moved to the escheat liability";
|
||||||
|
txn.submittedOnDate = transactionDate;
|
||||||
|
return txn;
|
||||||
|
}
|
||||||
|
|
||||||
// transactionTypeEnum = 7 (Reversal / Undo)
|
// transactionTypeEnum = 7 (Reversal / Undo)
|
||||||
public static CurrentAccountTransaction reversal(CurrentAccount account, Office office,
|
public static CurrentAccountTransaction reversal(CurrentAccount account, Office office,
|
||||||
BigDecimal amount, LocalDate transactionDate, Long originalTransactionId) {
|
BigDecimal amount, LocalDate transactionDate, Long originalTransactionId) {
|
||||||
|
|||||||
+6
@@ -36,4 +36,10 @@ public interface CurrentAccountTransactionWritePlatformService {
|
|||||||
CommandProcessingResult reverseTransaction(Long accountId, Long transactionId, boolean isReversal, JsonCommand command);
|
CommandProcessingResult reverseTransaction(Long accountId, Long transactionId, boolean isReversal, JsonCommand command);
|
||||||
|
|
||||||
CommandProcessingResult adjustTransaction(Long accountId, Long transactionId, JsonCommand command);
|
CommandProcessingResult adjustTransaction(Long accountId, Long transactionId, JsonCommand command);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escheats a dormant current account: moves its whole balance to the escheat liability and closes it. Run by the
|
||||||
|
* nightly dormancy job; returns false, leaving the account untouched, where it cannot safely be done.
|
||||||
|
*/
|
||||||
|
boolean escheat(Long accountId);
|
||||||
}
|
}
|
||||||
|
|||||||
+112
-16
@@ -44,7 +44,13 @@ import static org.apache.fineract.portfolio.savings.SavingsApiConstants.minRequi
|
|||||||
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.nameParamName;
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.nameParamName;
|
||||||
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.nominalAnnualInterestRateOverdraftParamName;
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.nominalAnnualInterestRateOverdraftParamName;
|
||||||
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.nominalAnnualInterestRateParamName;
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.nominalAnnualInterestRateParamName;
|
||||||
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.odExcessAllowedParamName;
|
||||||
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.odExcessLimitPercentParamName;
|
||||||
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.odMinLimitParamName;
|
||||||
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.odPenalRateParamName;
|
||||||
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.odSecurityTypeParamName;
|
||||||
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.overdraftLimitParamName;
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.overdraftLimitParamName;
|
||||||
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.validForPeriodParamName;
|
||||||
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.shortNameParamName;
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.shortNameParamName;
|
||||||
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.taxGroupIdParamName;
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.taxGroupIdParamName;
|
||||||
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.withHoldTaxParamName;
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.withHoldTaxParamName;
|
||||||
@@ -136,7 +142,17 @@ public class CurrentProductDataValidator {
|
|||||||
SavingsApiConstants.balanceSwapOptionParamName, SavingsApiConstants.msmeParamName,
|
SavingsApiConstants.balanceSwapOptionParamName, SavingsApiConstants.msmeParamName,
|
||||||
SavingsApiConstants.autoDebitFacilityParamName, SavingsApiConstants.avgBalanceCalcPeriodParamName,
|
SavingsApiConstants.autoDebitFacilityParamName, SavingsApiConstants.avgBalanceCalcPeriodParamName,
|
||||||
SavingsApiConstants.validForPeriodParamName, SavingsApiConstants.odAccountClosedZeroBalanceInDayClosingParamName,
|
SavingsApiConstants.validForPeriodParamName, SavingsApiConstants.odAccountClosedZeroBalanceInDayClosingParamName,
|
||||||
SavingsApiConstants.glAccountIdParamName));
|
odMinLimitParamName, odSecurityTypeParamName, odExcessAllowedParamName, odExcessLimitPercentParamName,
|
||||||
|
odPenalRateParamName, SavingsApiConstants.glAccountIdParamName));
|
||||||
|
|
||||||
|
/** How long an OD sanction on this scheme runs before it has to be renewed. */
|
||||||
|
private static final List<String> OD_VALIDITY_PERIODS = List.of("3M", "6M", "1Y", "2Y", "3Y");
|
||||||
|
/** CLEAN: no security needed; SECURED: backed by FD lien, property etc.; BOTH: decided per sanction. */
|
||||||
|
private static final List<String> OD_SECURITY_TYPES = List.of("CLEAN", "SECURED", "BOTH");
|
||||||
|
/** A sanity ceiling on the OD rate, catching a limit keyed into the rate field. */
|
||||||
|
private static final BigDecimal MAX_OVERDRAFT_RATE = new BigDecimal("50");
|
||||||
|
/** Excess drawing is a small tolerance over the limit, never a second limit. */
|
||||||
|
private static final BigDecimal MAX_EXCESS_PERCENT = new BigDecimal("25");
|
||||||
|
|
||||||
public void validateForCreate(final String json) {
|
public void validateForCreate(final String json) {
|
||||||
if (StringUtils.isBlank(json)) {
|
if (StringUtils.isBlank(json)) {
|
||||||
@@ -260,10 +276,10 @@ public class CurrentProductDataValidator {
|
|||||||
if (AccountingValidations.isCashBasedAccounting(accountingRuleType)
|
if (AccountingValidations.isCashBasedAccounting(accountingRuleType)
|
||||||
|| AccountingValidations.isAccrualPeriodicBasedAccounting(accountingRuleType)) {
|
|| AccountingValidations.isAccrualPeriodicBasedAccounting(accountingRuleType)) {
|
||||||
savingsProductAccountingDataValidator.evaluateProductAccountingData(accountingRuleType, isDormancyActive, element,
|
savingsProductAccountingDataValidator.evaluateProductAccountingData(accountingRuleType, isDormancyActive, element,
|
||||||
baseDataValidator, DepositAccountType.SAVINGS_DEPOSIT, true);
|
baseDataValidator, DepositAccountType.CURRENT_DEPOSIT, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
validateOverdraftParams(baseDataValidator, element);
|
validateOverdraftParams(baseDataValidator, element, null);
|
||||||
|
|
||||||
if (this.fromApiJsonHelper.parameterExists(minBalanceForInterestCalculationParamName, element)) {
|
if (this.fromApiJsonHelper.parameterExists(minBalanceForInterestCalculationParamName, element)) {
|
||||||
final BigDecimal minBalanceForInterestCalculation = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(minBalanceForInterestCalculationParamName, element);
|
final BigDecimal minBalanceForInterestCalculation = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(minBalanceForInterestCalculationParamName, element);
|
||||||
@@ -358,7 +374,7 @@ public class CurrentProductDataValidator {
|
|||||||
if (AccountingValidations.isCashBasedAccounting(accountingRuleType)
|
if (AccountingValidations.isCashBasedAccounting(accountingRuleType)
|
||||||
|| AccountingValidations.isAccrualPeriodicBasedAccounting(accountingRuleType)) {
|
|| AccountingValidations.isAccrualPeriodicBasedAccounting(accountingRuleType)) {
|
||||||
savingsProductAccountingDataValidator.evaluateProductAccountingData(accountingRuleType, isDormancyActive, element,
|
savingsProductAccountingDataValidator.evaluateProductAccountingData(accountingRuleType, isDormancyActive, element,
|
||||||
baseDataValidator, DepositAccountType.SAVINGS_DEPOSIT, false);
|
baseDataValidator, DepositAccountType.CURRENT_DEPOSIT, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null != isDormancyActive && isDormancyActive) {
|
if (null != isDormancyActive && isDormancyActive) {
|
||||||
@@ -380,7 +396,7 @@ public class CurrentProductDataValidator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
validateOverdraftParams(baseDataValidator, element);
|
validateOverdraftParams(baseDataValidator, element, product);
|
||||||
|
|
||||||
if (this.fromApiJsonHelper.parameterExists(minBalanceForInterestCalculationParamName, element)) {
|
if (this.fromApiJsonHelper.parameterExists(minBalanceForInterestCalculationParamName, element)) {
|
||||||
final BigDecimal minBalanceForInterestCalculation = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(minBalanceForInterestCalculationParamName, element);
|
final BigDecimal minBalanceForInterestCalculation = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(minBalanceForInterestCalculationParamName, element);
|
||||||
@@ -398,23 +414,103 @@ public class CurrentProductDataValidator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateOverdraftParams(final DataValidatorBuilder baseDataValidator, final JsonElement element) {
|
/**
|
||||||
|
* The overdraft section of a current product is the scheme every account's OD sanction is held to, so when OD is
|
||||||
|
* allowed it has to be complete: a ceiling (overdraftLimit, an amount, not a percentage), an optional floor, a rate,
|
||||||
|
* a sanction validity and whether the limit may be clean or must be secured. Interest on an OD is applied monthly,
|
||||||
|
* as RBI requires for advances, or at most quarterly.
|
||||||
|
*
|
||||||
|
* On update, product is the stored product and fills in any value the request leaves out, so a partial edit is
|
||||||
|
* checked against the scheme it will produce; on create it is null.
|
||||||
|
*/
|
||||||
|
private void validateOverdraftParams(final DataValidatorBuilder baseDataValidator, final JsonElement element,
|
||||||
|
final CurrentProduct product) {
|
||||||
if (this.fromApiJsonHelper.parameterExists(allowOverdraftParamName, element)) {
|
if (this.fromApiJsonHelper.parameterExists(allowOverdraftParamName, element)) {
|
||||||
final Boolean allowOverdraft = this.fromApiJsonHelper.extractBooleanNamed(allowOverdraftParamName, element);
|
final Boolean allowOverdraft = this.fromApiJsonHelper.extractBooleanNamed(allowOverdraftParamName, element);
|
||||||
baseDataValidator.reset().parameter(allowOverdraftParamName).value(allowOverdraft).ignoreIfNull().validateForBooleanValue();
|
baseDataValidator.reset().parameter(allowOverdraftParamName).value(allowOverdraft).ignoreIfNull().validateForBooleanValue();
|
||||||
}
|
}
|
||||||
if (this.fromApiJsonHelper.parameterExists(overdraftLimitParamName, element)) {
|
final boolean allowOverdraft = this.fromApiJsonHelper.parameterExists(allowOverdraftParamName, element)
|
||||||
final BigDecimal overdraftLimit = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(overdraftLimitParamName, element);
|
? BooleanUtils.isTrue(this.fromApiJsonHelper.extractBooleanNamed(allowOverdraftParamName, element))
|
||||||
baseDataValidator.reset().parameter(overdraftLimitParamName).value(overdraftLimit).ignoreIfNull().zeroOrPositiveAmount();
|
: product != null && product.isAllowOverdraft();
|
||||||
|
|
||||||
|
final BigDecimal maxLimit = bigDecimalOrStored(element, overdraftLimitParamName,
|
||||||
|
product == null ? null : product.getOverdraftLimit());
|
||||||
|
final BigDecimal minLimit = bigDecimalOrStored(element, odMinLimitParamName, product == null ? null : product.getOdMinLimit());
|
||||||
|
final BigDecimal rate = bigDecimalOrStored(element, nominalAnnualInterestRateOverdraftParamName,
|
||||||
|
product == null ? null : product.getNominalAnnualInterestRateOverdraft());
|
||||||
|
final BigDecimal minOdForInterest = bigDecimalOrStored(element, minOverdraftForInterestCalculationParamName,
|
||||||
|
product == null ? null : product.getMinOverdraftForInterestCalculation());
|
||||||
|
|
||||||
|
if (!allowOverdraft) {
|
||||||
|
baseDataValidator.reset().parameter(overdraftLimitParamName).value(maxLimit).ignoreIfNull().zeroOrPositiveAmount();
|
||||||
|
baseDataValidator.reset().parameter(nominalAnnualInterestRateOverdraftParamName).value(rate).ignoreIfNull()
|
||||||
|
.zeroOrPositiveAmount();
|
||||||
|
baseDataValidator.reset().parameter(minOverdraftForInterestCalculationParamName).value(minOdForInterest).ignoreIfNull()
|
||||||
|
.zeroOrPositiveAmount();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (this.fromApiJsonHelper.parameterExists(nominalAnnualInterestRateOverdraftParamName, element)) {
|
|
||||||
final BigDecimal nominalAnnualInterestRateOverdraft = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(nominalAnnualInterestRateOverdraftParamName, element);
|
baseDataValidator.reset().parameter(overdraftLimitParamName).value(maxLimit).notNull().positiveAmount();
|
||||||
baseDataValidator.reset().parameter(nominalAnnualInterestRateOverdraftParamName).value(nominalAnnualInterestRateOverdraft).ignoreIfNull().zeroOrPositiveAmount();
|
baseDataValidator.reset().parameter(odMinLimitParamName).value(minLimit).ignoreIfNull().zeroOrPositiveAmount();
|
||||||
|
if (minLimit != null && maxLimit != null && minLimit.compareTo(maxLimit) > 0) {
|
||||||
|
baseDataValidator.reset().parameter(odMinLimitParamName).value(minLimit)
|
||||||
|
.failWithCodeAndMessage("cannot.exceed.maximum.overdraft.limit", "Minimum OD limit cannot exceed the maximum OD limit.");
|
||||||
}
|
}
|
||||||
if (this.fromApiJsonHelper.parameterExists(minOverdraftForInterestCalculationParamName, element)) {
|
baseDataValidator.reset().parameter(nominalAnnualInterestRateOverdraftParamName).value(rate).notNull().positiveAmount()
|
||||||
final BigDecimal minOverdraftForInterestCalculation = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(minOverdraftForInterestCalculationParamName, element);
|
.notGreaterThanMax(MAX_OVERDRAFT_RATE);
|
||||||
baseDataValidator.reset().parameter(minOverdraftForInterestCalculationParamName).value(minOverdraftForInterestCalculation).ignoreIfNull().zeroOrPositiveAmount();
|
baseDataValidator.reset().parameter(minOverdraftForInterestCalculationParamName).value(minOdForInterest).ignoreIfNull()
|
||||||
|
.zeroOrPositiveAmount();
|
||||||
|
|
||||||
|
final String validity = stringOrStored(element, validForPeriodParamName, product == null ? null : product.getValidForPeriod());
|
||||||
|
baseDataValidator.reset().parameter(validForPeriodParamName).value(validity).notBlank()
|
||||||
|
.isOneOfTheseStringValues(OD_VALIDITY_PERIODS);
|
||||||
|
|
||||||
|
final String securityType = stringOrStored(element, odSecurityTypeParamName,
|
||||||
|
product == null ? null : product.getOdSecurityType());
|
||||||
|
baseDataValidator.reset().parameter(odSecurityTypeParamName).value(securityType).notBlank()
|
||||||
|
.isOneOfTheseStringValues(OD_SECURITY_TYPES);
|
||||||
|
|
||||||
|
// Excess drawing past the sanctioned limit. Off means a withdrawal beyond the limit is refused. On, the
|
||||||
|
// excess is capped at a percentage of the limit and carries a penal charge on the excess alone -- a separate
|
||||||
|
// charge, as RBI's 2023 penal-charges directions require, not a higher rate on the whole balance.
|
||||||
|
final boolean excessAllowed = this.fromApiJsonHelper.parameterExists(odExcessAllowedParamName, element)
|
||||||
|
? BooleanUtils.isTrue(this.fromApiJsonHelper.extractBooleanNamed(odExcessAllowedParamName, element))
|
||||||
|
: product != null && product.isOdExcessAllowed();
|
||||||
|
if (excessAllowed) {
|
||||||
|
final BigDecimal excessPercent = bigDecimalOrStored(element, odExcessLimitPercentParamName,
|
||||||
|
product == null ? null : product.getOdExcessLimitPercent());
|
||||||
|
baseDataValidator.reset().parameter(odExcessLimitPercentParamName).value(excessPercent).notNull().positiveAmount()
|
||||||
|
.notGreaterThanMax(MAX_EXCESS_PERCENT);
|
||||||
|
final BigDecimal penalRate = bigDecimalOrStored(element, odPenalRateParamName,
|
||||||
|
product == null ? null : product.getOdPenalRate());
|
||||||
|
baseDataValidator.reset().parameter(odPenalRateParamName).value(penalRate).notNull().positiveAmount()
|
||||||
|
.notGreaterThanMax(MAX_OVERDRAFT_RATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Integer postingPeriod = this.fromApiJsonHelper.parameterExists(interestPostingPeriodTypeParamName, element)
|
||||||
|
? this.fromApiJsonHelper.extractIntegerSansLocaleNamed(interestPostingPeriodTypeParamName, element)
|
||||||
|
: product == null ? null : product.getInterestPostingPeriodType();
|
||||||
|
baseDataValidator.reset().parameter(interestPostingPeriodTypeParamName).value(postingPeriod).ignoreIfNull()
|
||||||
|
.isOneOfTheseValues(SavingsPostingInterestPeriodType.MONTHLY.getValue(),
|
||||||
|
SavingsPostingInterestPeriodType.QUATERLY.getValue());
|
||||||
|
|
||||||
|
final Integer daysInYear = this.fromApiJsonHelper.parameterExists(interestCalculationDaysInYearTypeParamName, element)
|
||||||
|
? this.fromApiJsonHelper.extractIntegerSansLocaleNamed(interestCalculationDaysInYearTypeParamName, element)
|
||||||
|
: product == null ? null : product.getInterestCalculationDaysInYearType();
|
||||||
|
baseDataValidator.reset().parameter(interestCalculationDaysInYearTypeParamName).value(daysInYear).ignoreIfNull()
|
||||||
|
.isOneOfTheseValues(SavingsInterestCalculationDaysInYearType.DAYS_360.getValue(),
|
||||||
|
SavingsInterestCalculationDaysInYearType.DAYS_365.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
private BigDecimal bigDecimalOrStored(final JsonElement element, final String paramName, final BigDecimal stored) {
|
||||||
|
return this.fromApiJsonHelper.parameterExists(paramName, element)
|
||||||
|
? this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(paramName, element)
|
||||||
|
: stored;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String stringOrStored(final JsonElement element, final String paramName, final String stored) {
|
||||||
|
return this.fromApiJsonHelper.parameterExists(paramName, element) ? this.fromApiJsonHelper.extractStringNamed(paramName, element)
|
||||||
|
: stored;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateLienParams(final DataValidatorBuilder baseDataValidator, final JsonElement element) {
|
private void validateLienParams(final DataValidatorBuilder baseDataValidator, final JsonElement element) {
|
||||||
@@ -430,7 +526,7 @@ public class CurrentProductDataValidator {
|
|||||||
&& BooleanUtils.isTrue(this.fromApiJsonHelper.extractBooleanNamed(allowOverdraftParamName, element))) {
|
&& BooleanUtils.isTrue(this.fromApiJsonHelper.extractBooleanNamed(allowOverdraftParamName, element))) {
|
||||||
final BigDecimal maxAllowedLienLimit = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(maxAllowedLienLimitParamName, element);
|
final BigDecimal maxAllowedLienLimit = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(maxAllowedLienLimitParamName, element);
|
||||||
final BigDecimal overdraftLimit = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(overdraftLimitParamName, element);
|
final BigDecimal overdraftLimit = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(overdraftLimitParamName, element);
|
||||||
if (overdraftLimit.compareTo(maxAllowedLienLimit) > 0) {
|
if (overdraftLimit != null && maxAllowedLienLimit != null && overdraftLimit.compareTo(maxAllowedLienLimit) > 0) {
|
||||||
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("Overdraft.limit.can.not.be.greater.than.lien.limit");
|
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("Overdraft.limit.can.not.be.greater.than.lien.limit");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+68
@@ -68,6 +68,11 @@ import static org.apache.fineract.portfolio.savings.SavingsApiConstants.autoDebi
|
|||||||
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.avgBalanceCalcPeriodParamName;
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.avgBalanceCalcPeriodParamName;
|
||||||
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.validForPeriodParamName;
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.validForPeriodParamName;
|
||||||
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.odAccountClosedZeroBalanceInDayClosingParamName;
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.odAccountClosedZeroBalanceInDayClosingParamName;
|
||||||
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.odMinLimitParamName;
|
||||||
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.odSecurityTypeParamName;
|
||||||
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.odExcessAllowedParamName;
|
||||||
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.odExcessLimitPercentParamName;
|
||||||
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.odPenalRateParamName;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import jakarta.persistence.CascadeType;
|
import jakarta.persistence.CascadeType;
|
||||||
@@ -290,6 +295,25 @@ public class CurrentProduct extends AbstractPersistableCustom<Long> {
|
|||||||
@Column(name = "od_account_closed_zero_balance_in_day_closing")
|
@Column(name = "od_account_closed_zero_balance_in_day_closing")
|
||||||
private boolean odAccountClosedZeroBalanceInDayClosing = false;
|
private boolean odAccountClosedZeroBalanceInDayClosing = false;
|
||||||
|
|
||||||
|
// The smallest limit an account on this scheme may be sanctioned; overdraftLimit is the largest.
|
||||||
|
@Column(name = "od_min_limit", scale = 6, precision = 19)
|
||||||
|
private BigDecimal odMinLimit;
|
||||||
|
|
||||||
|
// CLEAN, SECURED or BOTH: whether a sanction must be backed by security (FD lien, property...).
|
||||||
|
@Column(name = "od_security_type", length = 20)
|
||||||
|
private String odSecurityType;
|
||||||
|
|
||||||
|
// Excess drawing past the sanctioned limit: off means it is blocked. When on, odExcessLimitPercent caps the excess
|
||||||
|
// as a percentage of the limit and odPenalRate (% p.a.) is charged on the excess alone.
|
||||||
|
@Column(name = "od_excess_allowed")
|
||||||
|
private boolean odExcessAllowed = false;
|
||||||
|
|
||||||
|
@Column(name = "od_excess_limit_percent", scale = 6, precision = 19)
|
||||||
|
private BigDecimal odExcessLimitPercent;
|
||||||
|
|
||||||
|
@Column(name = "od_penal_rate", scale = 6, precision = 19)
|
||||||
|
private BigDecimal odPenalRate;
|
||||||
|
|
||||||
@OneToOne(cascade = CascadeType.ALL, mappedBy = "currentProduct", orphanRemoval = true)
|
@OneToOne(cascade = CascadeType.ALL, mappedBy = "currentProduct", orphanRemoval = true)
|
||||||
private CurrentProductFacilityConfig facilityConfig;
|
private CurrentProductFacilityConfig facilityConfig;
|
||||||
|
|
||||||
@@ -804,11 +828,45 @@ public class CurrentProduct extends AbstractPersistableCustom<Long> {
|
|||||||
actualChanges.put(odAccountClosedZeroBalanceInDayClosingParamName, newValue);
|
actualChanges.put(odAccountClosedZeroBalanceInDayClosingParamName, newValue);
|
||||||
this.odAccountClosedZeroBalanceInDayClosing = newValue;
|
this.odAccountClosedZeroBalanceInDayClosing = newValue;
|
||||||
}
|
}
|
||||||
|
if (command.isChangeInBigDecimalParameterNamedDefaultingZeroToNull(odMinLimitParamName, this.odMinLimit)) {
|
||||||
|
final BigDecimal newValue = command.bigDecimalValueOfParameterNamedDefaultToNullIfZero(odMinLimitParamName);
|
||||||
|
actualChanges.put(odMinLimitParamName, newValue);
|
||||||
|
this.odMinLimit = newValue;
|
||||||
|
}
|
||||||
|
if (command.isChangeInStringParameterNamed(odSecurityTypeParamName, this.odSecurityType)) {
|
||||||
|
final String newValue = command.stringValueOfParameterNamed(odSecurityTypeParamName);
|
||||||
|
actualChanges.put(odSecurityTypeParamName, newValue);
|
||||||
|
this.odSecurityType = newValue;
|
||||||
|
}
|
||||||
|
if (command.isChangeInBooleanParameterNamed(odExcessAllowedParamName, this.odExcessAllowed)) {
|
||||||
|
final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(odExcessAllowedParamName);
|
||||||
|
actualChanges.put(odExcessAllowedParamName, newValue);
|
||||||
|
this.odExcessAllowed = newValue;
|
||||||
|
}
|
||||||
|
if (command.isChangeInBigDecimalParameterNamedDefaultingZeroToNull(odExcessLimitPercentParamName, this.odExcessLimitPercent)) {
|
||||||
|
final BigDecimal newValue = command.bigDecimalValueOfParameterNamedDefaultToNullIfZero(odExcessLimitPercentParamName);
|
||||||
|
actualChanges.put(odExcessLimitPercentParamName, newValue);
|
||||||
|
this.odExcessLimitPercent = newValue;
|
||||||
|
}
|
||||||
|
if (command.isChangeInBigDecimalParameterNamedDefaultingZeroToNull(odPenalRateParamName, this.odPenalRate)) {
|
||||||
|
final BigDecimal newValue = command.bigDecimalValueOfParameterNamedDefaultToNullIfZero(odPenalRateParamName);
|
||||||
|
actualChanges.put(odPenalRateParamName, newValue);
|
||||||
|
this.odPenalRate = newValue;
|
||||||
|
}
|
||||||
|
if (!this.odExcessAllowed) {
|
||||||
|
this.odExcessLimitPercent = null;
|
||||||
|
this.odPenalRate = null;
|
||||||
|
}
|
||||||
// Clear OD-specific fields when overdraft is disabled
|
// Clear OD-specific fields when overdraft is disabled
|
||||||
if (!this.allowOverdraft) {
|
if (!this.allowOverdraft) {
|
||||||
this.avgBalanceCalcPeriod = null;
|
this.avgBalanceCalcPeriod = null;
|
||||||
this.validForPeriod = null;
|
this.validForPeriod = null;
|
||||||
this.odAccountClosedZeroBalanceInDayClosing = false;
|
this.odAccountClosedZeroBalanceInDayClosing = false;
|
||||||
|
this.odMinLimit = null;
|
||||||
|
this.odSecurityType = null;
|
||||||
|
this.odExcessAllowed = false;
|
||||||
|
this.odExcessLimitPercent = null;
|
||||||
|
this.odPenalRate = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return actualChanges;
|
return actualChanges;
|
||||||
@@ -890,4 +948,14 @@ public class CurrentProduct extends AbstractPersistableCustom<Long> {
|
|||||||
public void setValidForPeriod(String validForPeriod) { this.validForPeriod = validForPeriod; }
|
public void setValidForPeriod(String validForPeriod) { this.validForPeriod = validForPeriod; }
|
||||||
public boolean isOdAccountClosedZeroBalanceInDayClosing() { return odAccountClosedZeroBalanceInDayClosing; }
|
public boolean isOdAccountClosedZeroBalanceInDayClosing() { return odAccountClosedZeroBalanceInDayClosing; }
|
||||||
public void setOdAccountClosedZeroBalanceInDayClosing(boolean val) { this.odAccountClosedZeroBalanceInDayClosing = val; }
|
public void setOdAccountClosedZeroBalanceInDayClosing(boolean val) { this.odAccountClosedZeroBalanceInDayClosing = val; }
|
||||||
|
public BigDecimal getOdMinLimit() { return odMinLimit; }
|
||||||
|
public void setOdMinLimit(BigDecimal odMinLimit) { this.odMinLimit = odMinLimit; }
|
||||||
|
public String getOdSecurityType() { return odSecurityType; }
|
||||||
|
public void setOdSecurityType(String odSecurityType) { this.odSecurityType = odSecurityType; }
|
||||||
|
public boolean isOdExcessAllowed() { return odExcessAllowed; }
|
||||||
|
public void setOdExcessAllowed(boolean odExcessAllowed) { this.odExcessAllowed = odExcessAllowed; }
|
||||||
|
public BigDecimal getOdExcessLimitPercent() { return odExcessLimitPercent; }
|
||||||
|
public void setOdExcessLimitPercent(BigDecimal odExcessLimitPercent) { this.odExcessLimitPercent = odExcessLimitPercent; }
|
||||||
|
public BigDecimal getOdPenalRate() { return odPenalRate; }
|
||||||
|
public void setOdPenalRate(BigDecimal odPenalRate) { this.odPenalRate = odPenalRate; }
|
||||||
}
|
}
|
||||||
|
|||||||
+22
@@ -43,6 +43,11 @@ import static org.apache.fineract.portfolio.savings.SavingsApiConstants.autoDebi
|
|||||||
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.avgBalanceCalcPeriodParamName;
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.avgBalanceCalcPeriodParamName;
|
||||||
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.validForPeriodParamName;
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.validForPeriodParamName;
|
||||||
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.odAccountClosedZeroBalanceInDayClosingParamName;
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.odAccountClosedZeroBalanceInDayClosingParamName;
|
||||||
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.odMinLimitParamName;
|
||||||
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.odSecurityTypeParamName;
|
||||||
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.odExcessAllowedParamName;
|
||||||
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.odExcessLimitPercentParamName;
|
||||||
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.odPenalRateParamName;
|
||||||
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.endDateParamName;
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.endDateParamName;
|
||||||
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.enforceMinRequiredBalanceParamName;
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.enforceMinRequiredBalanceParamName;
|
||||||
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.frequencyFixDayParamName;
|
import static org.apache.fineract.portfolio.savings.SavingsApiConstants.frequencyFixDayParamName;
|
||||||
@@ -314,6 +319,23 @@ public class CurrentProductAssembler {
|
|||||||
if (command.parameterExists(odAccountClosedZeroBalanceInDayClosingParamName)) {
|
if (command.parameterExists(odAccountClosedZeroBalanceInDayClosingParamName)) {
|
||||||
product.setOdAccountClosedZeroBalanceInDayClosing(command.booleanPrimitiveValueOfParameterNamed(odAccountClosedZeroBalanceInDayClosingParamName));
|
product.setOdAccountClosedZeroBalanceInDayClosing(command.booleanPrimitiveValueOfParameterNamed(odAccountClosedZeroBalanceInDayClosingParamName));
|
||||||
}
|
}
|
||||||
|
if (command.parameterExists(odMinLimitParamName)) {
|
||||||
|
product.setOdMinLimit(command.bigDecimalValueOfParameterNamed(odMinLimitParamName));
|
||||||
|
}
|
||||||
|
if (command.parameterExists(odSecurityTypeParamName)) {
|
||||||
|
product.setOdSecurityType(command.stringValueOfParameterNamed(odSecurityTypeParamName));
|
||||||
|
}
|
||||||
|
final boolean excessAllowed = command.parameterExists(odExcessAllowedParamName)
|
||||||
|
&& command.booleanPrimitiveValueOfParameterNamed(odExcessAllowedParamName);
|
||||||
|
product.setOdExcessAllowed(excessAllowed);
|
||||||
|
if (excessAllowed) {
|
||||||
|
if (command.parameterExists(odExcessLimitPercentParamName)) {
|
||||||
|
product.setOdExcessLimitPercent(command.bigDecimalValueOfParameterNamed(odExcessLimitPercentParamName));
|
||||||
|
}
|
||||||
|
if (command.parameterExists(odPenalRateParamName)) {
|
||||||
|
product.setOdPenalRate(command.bigDecimalValueOfParameterNamed(odPenalRateParamName));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return product;
|
return product;
|
||||||
|
|||||||
+115
@@ -0,0 +1,115 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.portfolio.currentproduct.service;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.apache.fineract.accounting.common.AccountingConstants.SavingProductAccountingParams;
|
||||||
|
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
||||||
|
import org.apache.fineract.portfolio.PortfolioProductType;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes a current product's GL mappings to acc_product_mapping under {@link PortfolioProductType#CURRENT}.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* They used to be written by the savings mapping writer under SAVING, keyed only by product id, so a current product
|
||||||
|
* and a savings product with the same id shared rows: two Current Control rows came back for one lookup and the
|
||||||
|
* account's GL posting failed outright, leaving the balance moved with no journal entry. Written under their own type,
|
||||||
|
* the two can never meet.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* A parameter present in the request replaces that one mapping (null clears it); an absent one is left alone, so a
|
||||||
|
* partial edit changes only what it names. Accounting rule NONE clears every mapping.
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class CurrentProductGlMappingWriter {
|
||||||
|
|
||||||
|
/** Request parameter -> financial account type (CashAccountsForSavings / AccrualAccountsForSavings). */
|
||||||
|
private static final Map<String, Integer> PARAM_TO_FINANCIAL_TYPE = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
PARAM_TO_FINANCIAL_TYPE.put(SavingProductAccountingParams.SAVINGS_REFERENCE.getValue(), 1);
|
||||||
|
PARAM_TO_FINANCIAL_TYPE.put(SavingProductAccountingParams.SAVINGS_CONTROL.getValue(), 2);
|
||||||
|
PARAM_TO_FINANCIAL_TYPE.put(SavingProductAccountingParams.INTEREST_ON_SAVINGS.getValue(), 3);
|
||||||
|
PARAM_TO_FINANCIAL_TYPE.put(SavingProductAccountingParams.INCOME_FROM_FEES.getValue(), 4);
|
||||||
|
PARAM_TO_FINANCIAL_TYPE.put(SavingProductAccountingParams.INCOME_FROM_PENALTIES.getValue(), 5);
|
||||||
|
PARAM_TO_FINANCIAL_TYPE.put(SavingProductAccountingParams.TRANSFERS_SUSPENSE.getValue(), 10);
|
||||||
|
PARAM_TO_FINANCIAL_TYPE.put(SavingProductAccountingParams.OVERDRAFT_PORTFOLIO_CONTROL.getValue(), 11);
|
||||||
|
PARAM_TO_FINANCIAL_TYPE.put(SavingProductAccountingParams.INCOME_FROM_INTEREST.getValue(), 12);
|
||||||
|
PARAM_TO_FINANCIAL_TYPE.put(SavingProductAccountingParams.LOSSES_WRITTEN_OFF.getValue(), 13);
|
||||||
|
PARAM_TO_FINANCIAL_TYPE.put(SavingProductAccountingParams.ESCHEAT_LIABILITY.getValue(), 14);
|
||||||
|
PARAM_TO_FINANCIAL_TYPE.put(SavingProductAccountingParams.FEES_RECEIVABLE.getValue(), 15);
|
||||||
|
PARAM_TO_FINANCIAL_TYPE.put(SavingProductAccountingParams.PENALTIES_RECEIVABLE.getValue(), 16);
|
||||||
|
PARAM_TO_FINANCIAL_TYPE.put(SavingProductAccountingParams.INTEREST_PAYABLE.getValue(), 17);
|
||||||
|
PARAM_TO_FINANCIAL_TYPE.put(SavingProductAccountingParams.INTEREST_RECEIVABLE.getValue(), 18);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final int CURRENT = PortfolioProductType.CURRENT.getValue();
|
||||||
|
|
||||||
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies the request's mappings to the product and returns what changed, keyed by parameter name.
|
||||||
|
*
|
||||||
|
* @param accountingRule
|
||||||
|
* the product's accounting rule after this request (1 = NONE)
|
||||||
|
*/
|
||||||
|
public Map<String, Object> write(final Long productId, final JsonCommand command, final Integer accountingRule) {
|
||||||
|
final Map<String, Object> changes = new LinkedHashMap<>();
|
||||||
|
if (accountingRule == null || accountingRule == 1) {
|
||||||
|
jdbcTemplate.update("DELETE FROM acc_product_mapping WHERE product_type = ? AND product_id = ?", CURRENT, productId);
|
||||||
|
return changes;
|
||||||
|
}
|
||||||
|
final JsonElement parsed = command.parsedJson();
|
||||||
|
final JsonObject json = parsed != null && parsed.isJsonObject() ? parsed.getAsJsonObject() : new JsonObject();
|
||||||
|
for (final Map.Entry<String, Integer> entry : PARAM_TO_FINANCIAL_TYPE.entrySet()) {
|
||||||
|
final String param = entry.getKey();
|
||||||
|
if (!json.has(param)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final Long glAccountId = json.get(param).isJsonNull() ? null : json.get(param).getAsLong();
|
||||||
|
final Long existing = jdbcTemplate.queryForList(
|
||||||
|
"SELECT gl_account_id FROM acc_product_mapping WHERE product_type = ? AND product_id = ? AND financial_account_type = ?"
|
||||||
|
+ " AND payment_type IS NULL AND charge_id IS NULL",
|
||||||
|
Long.class, CURRENT, productId, entry.getValue()).stream().findFirst().orElse(null);
|
||||||
|
if (java.util.Objects.equals(existing, glAccountId)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
jdbcTemplate.update("DELETE FROM acc_product_mapping WHERE product_type = ? AND product_id = ? AND financial_account_type = ?"
|
||||||
|
+ " AND payment_type IS NULL AND charge_id IS NULL", CURRENT, productId, entry.getValue());
|
||||||
|
if (glAccountId != null) {
|
||||||
|
jdbcTemplate.update("INSERT INTO acc_product_mapping (gl_account_id, product_id, product_type, financial_account_type)"
|
||||||
|
+ " VALUES (?, ?, ?, ?)", glAccountId, productId, CURRENT, entry.getValue());
|
||||||
|
}
|
||||||
|
changes.put(param, glAccountId);
|
||||||
|
}
|
||||||
|
return changes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Removes every mapping of a deleted product. */
|
||||||
|
public void deleteAll(final Long productId) {
|
||||||
|
jdbcTemplate.update("DELETE FROM acc_product_mapping WHERE product_type = ? AND product_id = ?", CURRENT, productId);
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
@@ -268,6 +268,9 @@ public class CurrentProductReadPlatformServiceImpl implements CurrentProductRead
|
|||||||
sqlBuilder.append("cp.balance_swap_option as balanceSwapOption, cp.msme as msme, cp.auto_debit_facility as autoDebitFacility, ");
|
sqlBuilder.append("cp.balance_swap_option as balanceSwapOption, cp.msme as msme, cp.auto_debit_facility as autoDebitFacility, ");
|
||||||
sqlBuilder.append("cp.avg_balance_calc_period as avgBalanceCalcPeriod, cp.valid_for_period as validForPeriod, ");
|
sqlBuilder.append("cp.avg_balance_calc_period as avgBalanceCalcPeriod, cp.valid_for_period as validForPeriod, ");
|
||||||
sqlBuilder.append("cp.od_account_closed_zero_balance_in_day_closing as odAccountClosedZeroBalanceInDayClosing, ");
|
sqlBuilder.append("cp.od_account_closed_zero_balance_in_day_closing as odAccountClosedZeroBalanceInDayClosing, ");
|
||||||
|
sqlBuilder.append("cp.od_min_limit as odMinLimit, cp.od_security_type as odSecurityType, ");
|
||||||
|
sqlBuilder.append("cp.od_excess_allowed as odExcessAllowed, cp.od_excess_limit_percent as odExcessLimitPercent, ");
|
||||||
|
sqlBuilder.append("cp.od_penal_rate as odPenalRate, ");
|
||||||
sqlBuilder.append("exists(select 1 from m_saving_product_temp spt where spt.product_id = cp.id "
|
sqlBuilder.append("exists(select 1 from m_saving_product_temp spt where spt.product_id = cp.id "
|
||||||
+ "and spt.product_type = 'CURRENT' and spt.status = 'PENDING') as isPendingApproval ");
|
+ "and spt.product_type = 'CURRENT' and spt.status = 'PENDING') as isPendingApproval ");
|
||||||
|
|
||||||
@@ -393,6 +396,11 @@ public class CurrentProductReadPlatformServiceImpl implements CurrentProductRead
|
|||||||
productData.setAvgBalanceCalcPeriod(rs.getString("avgBalanceCalcPeriod"));
|
productData.setAvgBalanceCalcPeriod(rs.getString("avgBalanceCalcPeriod"));
|
||||||
productData.setValidForPeriod(rs.getString("validForPeriod"));
|
productData.setValidForPeriod(rs.getString("validForPeriod"));
|
||||||
productData.setOdAccountClosedZeroBalanceInDayClosing(rs.getBoolean("odAccountClosedZeroBalanceInDayClosing"));
|
productData.setOdAccountClosedZeroBalanceInDayClosing(rs.getBoolean("odAccountClosedZeroBalanceInDayClosing"));
|
||||||
|
productData.setOdMinLimit(rs.getBigDecimal("odMinLimit"));
|
||||||
|
productData.setOdSecurityType(rs.getString("odSecurityType"));
|
||||||
|
productData.setOdExcessAllowed(rs.getBoolean("odExcessAllowed"));
|
||||||
|
productData.setOdExcessLimitPercent(rs.getBigDecimal("odExcessLimitPercent"));
|
||||||
|
productData.setOdPenalRate(rs.getBigDecimal("odPenalRate"));
|
||||||
productData.setIsPendingApproval(rs.getBoolean("isPendingApproval"));
|
productData.setIsPendingApproval(rs.getBoolean("isPendingApproval"));
|
||||||
|
|
||||||
return productData;
|
return productData;
|
||||||
|
|||||||
+6
-6
@@ -98,6 +98,7 @@ public class CurrentProductWritePlatformServiceJpaRepositoryImpl implements Curr
|
|||||||
private final ProductPendingEditGlMappingRepository pendingEditGlMappingRepository;
|
private final ProductPendingEditGlMappingRepository pendingEditGlMappingRepository;
|
||||||
private final FromJsonHelper fromApiJsonHelper;
|
private final FromJsonHelper fromApiJsonHelper;
|
||||||
private final CommandSourceRepository commandSourceRepository;
|
private final CommandSourceRepository commandSourceRepository;
|
||||||
|
private final CurrentProductGlMappingWriter glMappingWriter;
|
||||||
|
|
||||||
private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dae) {
|
private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dae) {
|
||||||
String msgCode = "error.msg." + DepositsApiConstants.CURRENT_PRODUCT_RESOURCE_NAME;
|
String msgCode = "error.msg." + DepositsApiConstants.CURRENT_PRODUCT_RESOURCE_NAME;
|
||||||
@@ -161,8 +162,8 @@ public class CurrentProductWritePlatformServiceJpaRepositoryImpl implements Curr
|
|||||||
this.depositLimitKycRepository.saveAndFlush(depositLimitKyc);
|
this.depositLimitKycRepository.saveAndFlush(depositLimitKyc);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.accountMappingWritePlatformService.createSavingProductToGLAccountMapping(product.getId(), command,
|
// Under the product's own CURRENT type, never SAVING: see CurrentProductGlMappingWriter.
|
||||||
DepositAccountType.SAVINGS_DEPOSIT);
|
this.glMappingWriter.write(product.getId(), command, product.getAccountingType());
|
||||||
|
|
||||||
return new CommandProcessingResultBuilder() //
|
return new CommandProcessingResultBuilder() //
|
||||||
.withEntityId(product.getId()) //
|
.withEntityId(product.getId()) //
|
||||||
@@ -258,10 +259,8 @@ public class CurrentProductWritePlatformServiceJpaRepositoryImpl implements Curr
|
|||||||
}
|
}
|
||||||
|
|
||||||
// accounting related changes
|
// accounting related changes
|
||||||
final boolean accountingTypeChanged = changes.containsKey(accountingRuleParamName);
|
final Map<String, Object> accountingMappingChanges = this.glMappingWriter.write(product.getId(), command,
|
||||||
final Map<String, Object> accountingMappingChanges = this.accountMappingWritePlatformService
|
product.getAccountingType());
|
||||||
.updateSavingsProductToGLAccountMapping(product.getId(), command, accountingTypeChanged, product.getAccountingType(),
|
|
||||||
DepositAccountType.SAVINGS_DEPOSIT);
|
|
||||||
changes.putAll(accountingMappingChanges);
|
changes.putAll(accountingMappingChanges);
|
||||||
|
|
||||||
if (!changes.isEmpty()) {
|
if (!changes.isEmpty()) {
|
||||||
@@ -504,6 +503,7 @@ public class CurrentProductWritePlatformServiceJpaRepositoryImpl implements Curr
|
|||||||
.orElseThrow(() -> new SavingsProductNotFoundException(productId));
|
.orElseThrow(() -> new SavingsProductNotFoundException(productId));
|
||||||
|
|
||||||
this.currentProductRepository.delete(product);
|
this.currentProductRepository.delete(product);
|
||||||
|
this.glMappingWriter.deleteAll(productId);
|
||||||
|
|
||||||
return new CommandProcessingResultBuilder() //
|
return new CommandProcessingResultBuilder() //
|
||||||
.withEntityId(product.getId()) //
|
.withEntityId(product.getId()) //
|
||||||
|
|||||||
+3
-2
@@ -33,6 +33,7 @@ import org.apache.fineract.portfolio.currentproduct.domain.CurrentProductDeposit
|
|||||||
import org.apache.fineract.portfolio.currentproduct.domain.CurrentProductFacilityConfigRepository;
|
import org.apache.fineract.portfolio.currentproduct.domain.CurrentProductFacilityConfigRepository;
|
||||||
import org.apache.fineract.portfolio.currentproduct.domain.CurrentProductFacilityLimitRepository;
|
import org.apache.fineract.portfolio.currentproduct.domain.CurrentProductFacilityLimitRepository;
|
||||||
import org.apache.fineract.portfolio.currentproduct.domain.CurrentProductRepository;
|
import org.apache.fineract.portfolio.currentproduct.domain.CurrentProductRepository;
|
||||||
|
import org.apache.fineract.portfolio.currentproduct.service.CurrentProductGlMappingWriter;
|
||||||
import org.apache.fineract.portfolio.currentproduct.service.CurrentProductReadPlatformService;
|
import org.apache.fineract.portfolio.currentproduct.service.CurrentProductReadPlatformService;
|
||||||
import org.apache.fineract.portfolio.currentproduct.service.CurrentProductReadPlatformServiceImpl;
|
import org.apache.fineract.portfolio.currentproduct.service.CurrentProductReadPlatformServiceImpl;
|
||||||
import org.apache.fineract.portfolio.currentproduct.service.CurrentProductWritePlatformService;
|
import org.apache.fineract.portfolio.currentproduct.service.CurrentProductWritePlatformService;
|
||||||
@@ -78,11 +79,11 @@ public class CurrentProductConfiguration {
|
|||||||
ProductPendingEditFacilityLimitRepository pendingEditFacilityLimitRepository,
|
ProductPendingEditFacilityLimitRepository pendingEditFacilityLimitRepository,
|
||||||
ProductPendingEditGlMappingRepository pendingEditGlMappingRepository,
|
ProductPendingEditGlMappingRepository pendingEditGlMappingRepository,
|
||||||
FromJsonHelper fromApiJsonHelper,
|
FromJsonHelper fromApiJsonHelper,
|
||||||
CommandSourceRepository commandSourceRepository) {
|
CommandSourceRepository commandSourceRepository, CurrentProductGlMappingWriter glMappingWriter) {
|
||||||
return new CurrentProductWritePlatformServiceJpaRepositoryImpl(context, currentProductRepository, currentProductDataValidator,
|
return new CurrentProductWritePlatformServiceJpaRepositoryImpl(context, currentProductRepository, currentProductDataValidator,
|
||||||
currentProductAssembler, accountMappingWritePlatformService, currentFacilityConfigRepository,
|
currentProductAssembler, accountMappingWritePlatformService, currentFacilityConfigRepository,
|
||||||
currentFacilityLimitRepository, currentDepositLimitKycRepository, productPendingEditRepository,
|
currentFacilityLimitRepository, currentDepositLimitKycRepository, productPendingEditRepository,
|
||||||
pendingEditSubmittedFieldRepository, pendingEditChargeRepository, pendingEditFacilityLimitRepository,
|
pendingEditSubmittedFieldRepository, pendingEditChargeRepository, pendingEditFacilityLimitRepository,
|
||||||
pendingEditGlMappingRepository, fromApiJsonHelper, commandSourceRepository);
|
pendingEditGlMappingRepository, fromApiJsonHelper, commandSourceRepository, glMappingWriter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+40
-1
@@ -18,20 +18,29 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.fineract.infrastructure.documentmanagement.service;
|
package org.apache.fineract.infrastructure.documentmanagement.service;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.nio.file.NoSuchFileException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.fineract.infrastructure.contentstore.service.ContentStoreService;
|
import org.apache.fineract.infrastructure.contentstore.service.ContentStoreService;
|
||||||
|
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException;
|
||||||
import org.apache.fineract.infrastructure.documentmanagement.data.DocumentContent;
|
import org.apache.fineract.infrastructure.documentmanagement.data.DocumentContent;
|
||||||
import org.apache.fineract.infrastructure.documentmanagement.data.DocumentData;
|
import org.apache.fineract.infrastructure.documentmanagement.data.DocumentData;
|
||||||
import org.apache.fineract.infrastructure.documentmanagement.domain.DocumentRepository;
|
import org.apache.fineract.infrastructure.documentmanagement.domain.DocumentRepository;
|
||||||
|
import org.apache.fineract.infrastructure.documentmanagement.exception.DocumentInvalidRequestException;
|
||||||
import org.apache.fineract.infrastructure.documentmanagement.exception.DocumentNotFoundException;
|
import org.apache.fineract.infrastructure.documentmanagement.exception.DocumentNotFoundException;
|
||||||
import org.apache.fineract.infrastructure.documentmanagement.mapping.DocumentMapper;
|
import org.apache.fineract.infrastructure.documentmanagement.mapping.DocumentMapper;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class DocumentReadPlatformServiceImpl implements DocumentReadPlatformService {
|
public class DocumentReadPlatformServiceImpl implements DocumentReadPlatformService {
|
||||||
|
|
||||||
|
/** Bound on the cause walk below, so a self-referencing cause chain cannot spin. */
|
||||||
|
private static final int MAX_CAUSE_DEPTH = 10;
|
||||||
|
|
||||||
private final ContentStoreService storeService;
|
private final ContentStoreService storeService;
|
||||||
private final DocumentRepository documentRepository;
|
private final DocumentRepository documentRepository;
|
||||||
private final DocumentMapper documentMapper;
|
private final DocumentMapper documentMapper;
|
||||||
@@ -52,9 +61,39 @@ public class DocumentReadPlatformServiceImpl implements DocumentReadPlatformServ
|
|||||||
public DocumentContent retrieveDocumentContent(final String entityType, final Long entityId, final Long documentId) {
|
public DocumentContent retrieveDocumentContent(final String entityType, final Long entityId, final Long documentId) {
|
||||||
final var doc = documentRepository.findByIdAndParentEntityTypeAndParentEntityId(documentId, entityType, entityId)
|
final var doc = documentRepository.findByIdAndParentEntityTypeAndParentEntityId(documentId, entityType, entityId)
|
||||||
.orElseThrow(() -> new DocumentNotFoundException(entityType, entityId, documentId));
|
.orElseThrow(() -> new DocumentNotFoundException(entityType, entityId, documentId));
|
||||||
|
try {
|
||||||
final var is = storeService.download(doc.getLocation());
|
final var is = storeService.download(doc.getLocation());
|
||||||
|
|
||||||
return documentMapper.map(doc, is);
|
return documentMapper.map(doc, is);
|
||||||
|
} catch (final AbstractPlatformDomainRuleException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Exception e) {
|
||||||
|
if (isMissingFromContentStore(e)) {
|
||||||
|
// The m_document row survives but the file it points at does not — the usual cause is
|
||||||
|
// a database copied between environments without its file store (see the identical
|
||||||
|
// guard in ImageReadPlatformServiceImpl). For the caller that is simply "this document
|
||||||
|
// has no content", not a server fault, so report it the same way as a missing document
|
||||||
|
// instead of letting a raw ContentStoreException surface as a 500.
|
||||||
|
log.warn("Document {} for {} {} is recorded but missing from the content store; treating it as not found", documentId,
|
||||||
|
entityType, entityId);
|
||||||
|
throw new DocumentNotFoundException(entityType, entityId, documentId);
|
||||||
|
}
|
||||||
|
throw new DocumentInvalidRequestException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a failure bottoms out in "the stored file is not there", however it was wrapped on the
|
||||||
|
* way up (the file store rethrows as ContentStoreException).
|
||||||
|
*/
|
||||||
|
private boolean isMissingFromContentStore(final Throwable failure) {
|
||||||
|
Throwable cause = failure;
|
||||||
|
for (int depth = 0; cause != null && depth < MAX_CAUSE_DEPTH; depth++) {
|
||||||
|
if (cause instanceof NoSuchFileException || cause instanceof FileNotFoundException) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
cause = cause.getCause();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+45
@@ -55,4 +55,49 @@ public final class GLAccountTransactionGuard {
|
|||||||
"glAccountId", glAccountId);
|
"glAccountId", glAccountId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refuses to draw more out of a holding account than it holds.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* A suspense or sundry account exists to hold money on its way somewhere else, so what is in it
|
||||||
|
* is the whole of what can come out. Drawing more leaves it with a negative balance, and a
|
||||||
|
* liability with a negative balance is not a small number - it says the bank owes less than
|
||||||
|
* nothing, which is not a state that exists. It also breaks the balance sheet by the overdraw,
|
||||||
|
* and the figure is small enough to sit unnoticed inside a head that totals positive.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Checked here rather than at each call site because the accounts this protects are reached by
|
||||||
|
* several features posting directly through JDBC, and a rule enforced in one of them is a rule
|
||||||
|
* the next one added will not have.
|
||||||
|
*
|
||||||
|
* @param glAccountId the account being drawn on.
|
||||||
|
* @param amount how much the caller wants to take out.
|
||||||
|
* @param what the account's role in the caller's own words, for the message a clerk reads.
|
||||||
|
*/
|
||||||
|
public static void assertSufficientBalance(final JdbcTemplate jdbcTemplate, final Long glAccountId,
|
||||||
|
final java.math.BigDecimal amount, final String what) {
|
||||||
|
if (glAccountId == null || amount == null || amount.signum() <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Credits less debits: these are liability-natured holding accounts, so the balance is what
|
||||||
|
// is still owed onward. Reversed entries and the entries they reverse both drop out - a
|
||||||
|
// reversal pair nets to nothing, and counting either side alone moves the balance by the
|
||||||
|
// whole amount.
|
||||||
|
final java.math.BigDecimal held = jdbcTemplate.queryForObject("""
|
||||||
|
SELECT COALESCE(SUM(CASE WHEN type_enum = 1 THEN amount ELSE -amount END), 0)
|
||||||
|
FROM acc_gl_journal_entry
|
||||||
|
WHERE account_id = ?
|
||||||
|
AND (reversed IS NULL OR reversed = false)
|
||||||
|
AND id NOT IN (SELECT reversal_id FROM acc_gl_journal_entry WHERE reversal_id IS NOT NULL)
|
||||||
|
""", java.math.BigDecimal.class, glAccountId);
|
||||||
|
final java.math.BigDecimal balance = held == null ? java.math.BigDecimal.ZERO : held;
|
||||||
|
if (balance.compareTo(amount) < 0) {
|
||||||
|
throw new PlatformDataIntegrityException("error.msg.glaccount.insufficient.balance",
|
||||||
|
what + " holds " + balance + " but " + amount + " was asked of it. Drawing the "
|
||||||
|
+ "difference would leave the account with a negative balance, which a "
|
||||||
|
+ "holding account cannot have.",
|
||||||
|
"glAccountId", glAccountId, amount);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+188
-28
@@ -27,6 +27,7 @@ import java.util.Map;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.fineract.accounting.closure.domain.GLClosure;
|
import org.apache.fineract.accounting.closure.domain.GLClosure;
|
||||||
import org.apache.fineract.accounting.closure.domain.GLClosureRepository;
|
import org.apache.fineract.accounting.closure.domain.GLClosureRepository;
|
||||||
@@ -42,6 +43,7 @@ import org.apache.fineract.accounting.financialactivityaccount.domain.FinancialA
|
|||||||
import org.apache.fineract.accounting.financialactivityaccount.domain.FinancialActivityAccountRepositoryWrapper;
|
import org.apache.fineract.accounting.financialactivityaccount.domain.FinancialActivityAccountRepositoryWrapper;
|
||||||
import org.apache.fineract.accounting.glaccount.domain.GLAccount;
|
import org.apache.fineract.accounting.glaccount.domain.GLAccount;
|
||||||
import org.apache.fineract.accounting.glaccount.domain.GLAccountRepository;
|
import org.apache.fineract.accounting.glaccount.domain.GLAccountRepository;
|
||||||
|
import org.apache.fineract.accounting.glaccount.domain.GLAccountType;
|
||||||
import org.apache.fineract.accounting.journalentry.data.ChargePaymentDTO;
|
import org.apache.fineract.accounting.journalentry.data.ChargePaymentDTO;
|
||||||
import org.apache.fineract.accounting.journalentry.data.ClientChargePaymentDTO;
|
import org.apache.fineract.accounting.journalentry.data.ClientChargePaymentDTO;
|
||||||
import org.apache.fineract.accounting.journalentry.data.ClientTransactionDTO;
|
import org.apache.fineract.accounting.journalentry.data.ClientTransactionDTO;
|
||||||
@@ -68,6 +70,7 @@ import org.apache.fineract.infrastructure.event.business.domain.journalentry.Loa
|
|||||||
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
|
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
|
||||||
import org.apache.fineract.organisation.office.domain.Office;
|
import org.apache.fineract.organisation.office.domain.Office;
|
||||||
import org.apache.fineract.organisation.office.domain.OfficeRepository;
|
import org.apache.fineract.organisation.office.domain.OfficeRepository;
|
||||||
|
import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
|
||||||
import org.apache.fineract.portfolio.PortfolioProductType;
|
import org.apache.fineract.portfolio.PortfolioProductType;
|
||||||
import org.apache.fineract.portfolio.account.PortfolioAccountType;
|
import org.apache.fineract.portfolio.account.PortfolioAccountType;
|
||||||
import org.apache.fineract.portfolio.account.service.AccountTransfersReadPlatformService;
|
import org.apache.fineract.portfolio.account.service.AccountTransfersReadPlatformService;
|
||||||
@@ -81,6 +84,7 @@ import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountTransactionE
|
|||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class AccountingProcessorHelper {
|
public class AccountingProcessorHelper {
|
||||||
|
|
||||||
@@ -646,10 +650,12 @@ public class AccountingProcessorHelper {
|
|||||||
*/
|
*/
|
||||||
public void createInterestPostingJournalEntriesForSavings(final Office office, final String currencyCode,
|
public void createInterestPostingJournalEntriesForSavings(final Office office, final String currencyCode,
|
||||||
final Long savingsProductId, final Long paymentTypeId, final Long savingsId, final String transactionId,
|
final Long savingsProductId, final Long paymentTypeId, final Long savingsId, final String transactionId,
|
||||||
final LocalDate transactionDate, final BigDecimal amount, final boolean isReversal) {
|
final LocalDate transactionDate, final BigDecimal amount, final boolean isReversal, final boolean payableCarriesAccrual) {
|
||||||
|
|
||||||
final GLAccount controlAccount = getLinkedGLAccountForSavingsProduct(savingsProductId,
|
final GLAccount controlAccount = getLinkedGLAccountForSavingsProduct(savingsProductId,
|
||||||
CashAccountsForSavings.SAVINGS_CONTROL.getValue(), paymentTypeId);
|
CashAccountsForSavings.SAVINGS_CONTROL.getValue(), paymentTypeId);
|
||||||
|
final GLAccount interestOnSavingsAccount = getLinkedGLAccountForSavingsProduct(savingsProductId,
|
||||||
|
CashAccountsForSavings.INTEREST_ON_SAVINGS.getValue(), paymentTypeId);
|
||||||
|
|
||||||
// The payable comes from the Interest Payable row on the product's Accounting tab, which is
|
// The payable comes from the Interest Payable row on the product's Accounting tab, which is
|
||||||
// where a bank actually picks it. The reserved name in the product's other GL mappings is
|
// where a bank actually picks it. The reserved name in the product's other GL mappings is
|
||||||
@@ -658,30 +664,103 @@ public class AccountingProcessorHelper {
|
|||||||
final GLAccount payableAccount = Optional
|
final GLAccount payableAccount = Optional
|
||||||
.ofNullable(optionalLinkedGLAccountForSavingsProduct(savingsProductId,
|
.ofNullable(optionalLinkedGLAccountForSavingsProduct(savingsProductId,
|
||||||
AccrualAccountsForSavings.INTEREST_PAYABLE.getValue(), paymentTypeId))
|
AccrualAccountsForSavings.INTEREST_PAYABLE.getValue(), paymentTypeId))
|
||||||
.or(() -> Optional.ofNullable(namedSavingsGlAccount(savingsProductId, SAVINGS_INTEREST_PAYABLE_MAPPING)))
|
.or(() -> Optional.ofNullable(namedSavingsGlAccount(savingsProductId,
|
||||||
|
SAVINGS_INTEREST_PAYABLE_MAPPING, "Fixed Deposit Interest Payable", "Recurring Deposit Interest Payable",
|
||||||
|
"Interest Payable", "Interest Payable Account")))
|
||||||
.orElse(controlAccount);
|
.orElse(controlAccount);
|
||||||
final GLAccount paidAccount = Optional.ofNullable(namedSavingsGlAccount(savingsProductId, SAVINGS_INTEREST_PAID_MAPPING))
|
// The RD product screen saves its paid account as "Recurring Deposit Interest Paid"; without that name here an
|
||||||
|
// RD's interest skipped the paid leg even when the product had one mapped.
|
||||||
|
final GLAccount paidAccount = Optional.ofNullable(namedSavingsGlAccount(savingsProductId,
|
||||||
|
SAVINGS_INTEREST_PAID_MAPPING, "Fixed Deposit Interest Paid", "Recurring Deposit Interest Paid", "Interest Paid",
|
||||||
|
"Interest Paid Account"))
|
||||||
.orElse(payableAccount);
|
.orElse(payableAccount);
|
||||||
|
|
||||||
// The interest expense is not raised here. It is recognised as the interest accrues, day by
|
log.info("createInterestPostingJournalEntriesForSavings: savingsProductId={}, payableAccount=[{} - {}], paidAccount=[{} - {}], controlAccount=[{} - {}], interestExpense=[{} - {}], amount={}, isReversal={}",
|
||||||
// day, and this posting settles that recognised debt - raising the expense again at payout
|
savingsProductId, payableAccount.getId(), payableAccount.getName(), paidAccount.getId(), paidAccount.getName(),
|
||||||
// would put the same interest on the P&L twice. This mirrors the pooled posting service,
|
controlAccount.getId(), controlAccount.getName(), interestOnSavingsAccount.getId(), interestOnSavingsAccount.getName(),
|
||||||
// which pays a product's whole membership the same way; a closure reaching this path must
|
amount, isReversal);
|
||||||
// produce the same entries as the nightly run, or the two disagree on what one payment did.
|
|
||||||
//
|
// A product that names no payable falls back to Savings Control above. The chain below would
|
||||||
// Stage 1: the liability moves from the payable to the account it is paid out of. Where the
|
// then open with Dr Savings Control / Cr Interest On Savings and close with its exact
|
||||||
// product names no paid account both resolve to the payable and this says nothing, so it is
|
// reverse, the two cancelling: the expense never charged and the member never credited. Such
|
||||||
// skipped and the payout comes straight out of the payable.
|
// a product has no liability to draw down, so it keeps the single pair it always posted.
|
||||||
final boolean payableIsPaid = payableAccount.getId().equals(paidAccount.getId());
|
if (payableAccount.getId().equals(controlAccount.getId())) {
|
||||||
if (!payableIsPaid) {
|
log.warn("createInterestPostingJournalEntriesForSavings: payableAccount == controlAccount [id={}], posting standard 2-leg entry",
|
||||||
postSavingsLeg(office, currencyCode, payableAccount, paidAccount, savingsId, transactionId, transactionDate, amount,
|
payableAccount.getId());
|
||||||
isReversal);
|
postSavingsLeg(office, currencyCode, interestOnSavingsAccount, controlAccount, savingsId, transactionId, transactionDate,
|
||||||
|
amount, isReversal);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stage 2: into the member's own balance.
|
// The interest is charged to expense and raised as a liability first, for whatever part of
|
||||||
final GLAccount payoutFromAccount = payableIsPaid ? payableAccount : paidAccount;
|
// it no accrual has already covered.
|
||||||
postSavingsLeg(office, currencyCode, payoutFromAccount, controlAccount, savingsId, transactionId, transactionDate, amount,
|
//
|
||||||
|
// The chain below draws the payable DOWN, so it assumes an accrual already credited it for
|
||||||
|
// the period. Where none ran - a product posting on cash accounting, or a period the accrual
|
||||||
|
// job never covered - the payable went negative by the interest and the expense netted to
|
||||||
|
// nothing across the next two legs, leaving the charge off the P&L entirely. A liability
|
||||||
|
// account cannot hold a negative balance: the bank does not owe less than nothing.
|
||||||
|
//
|
||||||
|
// So the shortfall is raised here rather than assumed away. Where the accrual DID run, the
|
||||||
|
// payable already carries the interest and this leg writes nothing - the balance below is
|
||||||
|
// enough, and raising it again would double the liability.
|
||||||
|
//
|
||||||
|
// Only a liability payable is topped up. A bank that maps an expense GL as the payable books
|
||||||
|
// the cost there directly: payableBalance reads credit minus debit, so an expense's normal
|
||||||
|
// debit balance would come back negative and every posting would raise a shortfall larger
|
||||||
|
// than the interest itself.
|
||||||
|
final boolean payableIsLiability = GLAccountType.LIABILITY.getValue().equals(payableAccount.getType());
|
||||||
|
if (!payableCarriesAccrual) {
|
||||||
|
// Cash basis: nothing ever accrues into the payable, so whatever already sits on it - an opening balance
|
||||||
|
// brought over at migration, or another product's interest sharing the GL - is not this interest. Reading
|
||||||
|
// it as "already accrued" skipped the expense and drew that balance down instead, leaving the cost off the
|
||||||
|
// P&L. The whole amount is charged and raised, and a reversal or clawback takes it back the same way.
|
||||||
|
if (payableIsLiability) {
|
||||||
|
postSavingsLeg(office, currencyCode, interestOnSavingsAccount, payableAccount, savingsId, transactionId, transactionDate,
|
||||||
|
amount, isReversal);
|
||||||
|
}
|
||||||
|
postPayableToMember(office, currencyCode, payableAccount, paidAccount, controlAccount, savingsId, transactionId,
|
||||||
|
transactionDate, amount, isReversal);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final BigDecimal alreadyAccrued = payableBalance(office, payableAccount, currencyCode);
|
||||||
|
final BigDecimal shortfall = amount.subtract(alreadyAccrued).max(BigDecimal.ZERO);
|
||||||
|
log.info("createInterestPostingJournalEntriesForSavings: alreadyAccrued={}, shortfall={}, payableIsLiability={}, isReversal={}",
|
||||||
|
alreadyAccrued, shortfall, payableIsLiability, isReversal);
|
||||||
|
if (!isReversal && payableIsLiability && shortfall.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
log.info("createInterestPostingJournalEntriesForSavings: posting Stage 1 [Dr {} / Cr {} = {}]",
|
||||||
|
interestOnSavingsAccount.getName(), payableAccount.getName(), shortfall);
|
||||||
|
// Stage 1: Dr Interest On Savings (the expense) / Cr Payable - the accrual that should have run.
|
||||||
|
postSavingsLeg(office, currencyCode, interestOnSavingsAccount, payableAccount, savingsId, transactionId, transactionDate,
|
||||||
|
shortfall, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
postPayableToMember(office, currencyCode, payableAccount, paidAccount, controlAccount, savingsId, transactionId, transactionDate,
|
||||||
|
amount, isReversal);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Stages 2 and 3: out of the payable, through the paid account when the product names one, into the member. */
|
||||||
|
private void postPayableToMember(final Office office, final String currencyCode, final GLAccount payableAccount,
|
||||||
|
final GLAccount paidAccount, final GLAccount controlAccount, final Long savingsId, final String transactionId,
|
||||||
|
final LocalDate transactionDate, final BigDecimal amount, final boolean isReversal) {
|
||||||
|
final boolean hasSeparatePaidAccount = !payableAccount.getId().equals(paidAccount.getId());
|
||||||
|
if (hasSeparatePaidAccount) {
|
||||||
|
log.info("createInterestPostingJournalEntriesForSavings: posting Stage 2 [Dr {} / Cr {} = {}] and Stage 3 [Dr {} / Cr {} = {}]",
|
||||||
|
payableAccount.getName(), paidAccount.getName(), amount, paidAccount.getName(), controlAccount.getName(), amount);
|
||||||
|
// Stage 2: Out of the payable, into the interest-paid transit/clearing account
|
||||||
|
postSavingsLeg(office, currencyCode, payableAccount, paidAccount, savingsId, transactionId, transactionDate, amount,
|
||||||
isReversal);
|
isReversal);
|
||||||
|
|
||||||
|
// Stage 3: Out of the interest-paid account, into the member's control account
|
||||||
|
postSavingsLeg(office, currencyCode, paidAccount, controlAccount, savingsId, transactionId, transactionDate, amount,
|
||||||
|
isReversal);
|
||||||
|
} else {
|
||||||
|
log.info("createInterestPostingJournalEntriesForSavings: no separate paidAccount, posting direct payout [Dr {} / Cr {} = {}]",
|
||||||
|
payableAccount.getName(), controlAccount.getName(), amount);
|
||||||
|
// Payout directly from payable into member's control account
|
||||||
|
postSavingsLeg(office, currencyCode, payableAccount, controlAccount, savingsId, transactionId, transactionDate, amount,
|
||||||
|
isReversal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -723,15 +802,46 @@ public class AccountingProcessorHelper {
|
|||||||
*
|
*
|
||||||
* @return the account, or null where the product does not configure this name
|
* @return the account, or null where the product does not configure this name
|
||||||
*/
|
*/
|
||||||
private GLAccount namedSavingsGlAccount(final Long savingsProductId, final String accountName) {
|
/**
|
||||||
if (savingsProductId == null) {
|
* What the interest payable account currently holds for this office, on its own liability side.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Read so an interest posting can tell an accrual that already ran from one that did not. The
|
||||||
|
* posting chain draws the payable down; where nothing had raised it, the account went negative
|
||||||
|
* and the expense netted to nothing, so the charge never reached the P&L at all. The caller
|
||||||
|
* raises only the shortfall, which is nil when the accrual did run.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Credits less debits, because a payable is a liability: the balance is what the bank still
|
||||||
|
* owes. Floored at zero by the caller rather than here - a negative balance is a real state to
|
||||||
|
* report, and the caller's arithmetic needs the true figure, not a clamped one.
|
||||||
|
*/
|
||||||
|
private BigDecimal payableBalance(final Office office, final GLAccount payableAccount, final String currencyCode) {
|
||||||
|
if (payableAccount == null || payableAccount.getId() == null) {
|
||||||
|
return BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
// Reversed entries and the entries they reverse are both excluded: a reversal pair nets to
|
||||||
|
// nothing, and counting either side alone would move the balance by the whole amount.
|
||||||
|
final BigDecimal balance = jdbcTemplate.queryForObject("""
|
||||||
|
SELECT COALESCE(SUM(CASE WHEN type_enum = 1 THEN amount ELSE -amount END), 0)
|
||||||
|
FROM acc_gl_journal_entry
|
||||||
|
WHERE account_id = ?
|
||||||
|
AND office_id = ?
|
||||||
|
AND currency_code = ?
|
||||||
|
AND (reversed IS NULL OR reversed = false)
|
||||||
|
AND id NOT IN (SELECT reversal_id FROM acc_gl_journal_entry WHERE reversal_id IS NOT NULL)
|
||||||
|
""", BigDecimal.class, payableAccount.getId(), office.getId(), currencyCode);
|
||||||
|
return balance == null ? BigDecimal.ZERO : balance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private GLAccount namedSavingsGlAccount(final Long savingsProductId, final String... accountNames) {
|
||||||
|
if (savingsProductId == null || accountNames == null || accountNames.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// The column holds an empty string on a product saved with no named mappings, and casting
|
for (final String accountName : accountNames) {
|
||||||
// that to jsonb is an error rather than an empty document - so the cast is done inside a
|
if (accountName == null) {
|
||||||
// subquery that has already filtered those rows out. Postgres is free to evaluate a WHERE
|
continue;
|
||||||
// clause in any order, so guarding at the same query level as the cast would only work by
|
}
|
||||||
// luck.
|
|
||||||
final List<Long> found = jdbcTemplate.queryForList("""
|
final List<Long> found = jdbcTemplate.queryForList("""
|
||||||
SELECT gl.id
|
SELECT gl.id
|
||||||
FROM (SELECT other_gl_mappings::jsonb AS doc
|
FROM (SELECT other_gl_mappings::jsonb AS doc
|
||||||
@@ -747,10 +857,14 @@ public class AccountingProcessorHelper {
|
|||||||
|| COALESCE(sp.doc -> 'income', '[]'::jsonb)
|
|| COALESCE(sp.doc -> 'income', '[]'::jsonb)
|
||||||
) AS m(entry)
|
) AS m(entry)
|
||||||
JOIN acc_gl_account gl ON gl.gl_code = m.entry ->> 'glCode'
|
JOIN acc_gl_account gl ON gl.gl_code = m.entry ->> 'glCode'
|
||||||
WHERE m.entry ->> 'accountName' = ?
|
WHERE lower(trim(m.entry ->> 'accountName')) = lower(trim(?))
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
""", Long.class, savingsProductId, accountName);
|
""", Long.class, savingsProductId, accountName);
|
||||||
return found.isEmpty() ? null : glAccountRepository.findById(found.get(0)).orElse(null);
|
if (!found.isEmpty()) {
|
||||||
|
return glAccountRepository.findById(found.get(0)).orElse(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -774,6 +888,45 @@ public class AccountingProcessorHelper {
|
|||||||
createCreditJournalEntryForSavings(office, currencyCode, creditAccount, creditEntityId, transactionId, transactionDate, amount);
|
createCreditJournalEntryForSavings(office, currencyCode, creditAccount, creditEntityId, transactionId, transactionDate, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The same direct transfer where either side may be a current account. A current product maps its GLs under
|
||||||
|
* {@link PortfolioProductType#CURRENT}, so each side's control GL is read under its own product type -- reading a
|
||||||
|
* current product under SAVING picked up the GLs of the savings product that happens to share its id.
|
||||||
|
*/
|
||||||
|
public void createDirectTransferJournalEntries(final Office office, final String currencyCode, final Long debitProductId,
|
||||||
|
final boolean debitIsCurrent, final Long debitEntityId, final Long creditProductId, final boolean creditIsCurrent,
|
||||||
|
final Long creditEntityId, final String transactionId, final LocalDate transactionDate, final BigDecimal amount) {
|
||||||
|
final GLAccount debitAccount = controlGlAccount(debitProductId, debitIsCurrent);
|
||||||
|
final GLAccount creditAccount = controlGlAccount(creditProductId, creditIsCurrent);
|
||||||
|
createDebitJournalEntryForSavings(office, currencyCode, debitAccount, debitEntityId, transactionId, transactionDate, amount);
|
||||||
|
createCreditJournalEntryForSavings(office, currencyCode, creditAccount, creditEntityId, transactionId, transactionDate, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Dr a current product's Current Control, Cr the GL mapped to {@code financialActivity}. */
|
||||||
|
public void createCurrentControlToFinancialActivityJournalEntries(final Office office, final String currencyCode,
|
||||||
|
final Long currentProductId, final int financialActivity, final Long currentAccountId, final String transactionId,
|
||||||
|
final LocalDate transactionDate, final BigDecimal amount) {
|
||||||
|
final GLAccount controlAccount = controlGlAccount(currentProductId, true);
|
||||||
|
final GLAccount activityAccount = this.financialActivityAccountRepository
|
||||||
|
.findByFinancialActivityTypeWithNotFoundDetection(financialActivity).getGlAccount();
|
||||||
|
createDebitJournalEntryForSavings(office, currencyCode, controlAccount, currentAccountId, transactionId, transactionDate, amount);
|
||||||
|
createCreditJournalEntryForSavings(office, currencyCode, activityAccount, currentAccountId, transactionId, transactionDate, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
private GLAccount controlGlAccount(final Long productId, final boolean isCurrent) {
|
||||||
|
if (!isCurrent) {
|
||||||
|
return getLinkedGLAccountForSavingsProduct(productId, CashAccountsForSavings.SAVINGS_CONTROL.getValue(), null);
|
||||||
|
}
|
||||||
|
final ProductToGLAccountMapping mapping = this.accountMappingRepository.findCoreProductToFinAccountMapping(productId,
|
||||||
|
PortfolioProductType.CURRENT.getValue(), CashAccountsForSavings.SAVINGS_CONTROL.getValue());
|
||||||
|
if (mapping == null) {
|
||||||
|
throw new GeneralPlatformDomainRuleException("error.msg.current.product.control.gl.not.mapped",
|
||||||
|
"Current product " + productId + " has no Current Control GL mapped; map it on the product's Accounting tab.",
|
||||||
|
productId);
|
||||||
|
}
|
||||||
|
return mapping.getGlAccount();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience method that creates a pair of related Debits and Credits for Cash Based accounting.
|
* Convenience method that creates a pair of related Debits and Credits for Cash Based accounting.
|
||||||
*
|
*
|
||||||
@@ -1468,6 +1621,13 @@ public class AccountingProcessorHelper {
|
|||||||
accountMapping = paymentChannelSpecificAccountMapping;
|
accountMapping = paymentChannelSpecificAccountMapping;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Matches getLinkedGLAccountForSavingsProduct's own guard just above: a share product can
|
||||||
|
// now genuinely have no SHARES_REFERENCE mapping (it stopped being a mandatory field), so
|
||||||
|
// this has to fail with a clean, named error instead of NPEing on accountMapping.
|
||||||
|
if (accountMapping == null) {
|
||||||
|
throw new ProductToGLAccountMappingNotFoundException(PortfolioProductType.SHARES, shareProductId,
|
||||||
|
CashAccountsForShares.fromInt(accountMappingTypeId).toString());
|
||||||
|
}
|
||||||
glAccount = accountMapping.getGlAccount();
|
glAccount = accountMapping.getGlAccount();
|
||||||
}
|
}
|
||||||
return glAccount;
|
return glAccount;
|
||||||
|
|||||||
+22
-6
@@ -173,12 +173,28 @@ public class AccrualBasedAccountingProcessorForSavings implements AccountingProc
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if (savingsTransactionDTO.getTransactionType().isInterestPosting()) {
|
else if (savingsTransactionDTO.getTransactionType().isInterestPosting()) {
|
||||||
// Post journal entry if earned interest amount is greater than
|
// A premature FD closure that reprices interest downward (see
|
||||||
// zero
|
// FixedDepositAccount#postPreMaturityInterest) posts the difference as a NEGATIVE
|
||||||
if (savingsTransactionDTO.getAmount().compareTo(BigDecimal.ZERO) > 0) {
|
// interest-posting transaction -- a clawback of interest already recognised in earlier
|
||||||
this.helper.createCashBasedJournalEntriesAndReversalsForSavings(office, currencyCode,
|
// periods, not "zero interest, nothing to post". Skipping it here (the original
|
||||||
AccrualAccountsForSavings.INTEREST_PAYABLE.getValue(), AccrualAccountsForSavings.SAVINGS_CONTROL.getValue(),
|
// "amount > 0" guard) left the FD subledger showing the clawback while the GL never
|
||||||
savingsProductId, paymentTypeId, savingsId, transactionId, transactionDate, amount, isReversal);
|
// recorded it, silently going out of sync. Treating a negative amount as a mirror-image
|
||||||
|
// reversal -- positive magnitude, debit/credit legs swapped, same mechanism
|
||||||
|
// createInterestPostingJournalEntriesForSavings already uses for isReversal -- keeps the two
|
||||||
|
// in sync instead. See CashBasedAccountingProcessorForSavings for the same fix on the
|
||||||
|
// cash-based path.
|
||||||
|
final int amountSign = savingsTransactionDTO.getAmount().compareTo(BigDecimal.ZERO);
|
||||||
|
if (amountSign != 0) {
|
||||||
|
final boolean isClawback = amountSign < 0;
|
||||||
|
final BigDecimal postingAmount = isClawback ? amount.abs() : amount;
|
||||||
|
final boolean effectiveIsReversal = isReversal ^ isClawback;
|
||||||
|
// Routed through the same helper the cash processor uses, so a posting states
|
||||||
|
// the whole chain the product is configured for -- out of the payable, through
|
||||||
|
// the interest-paid account, into the member's balance -- rather than the single
|
||||||
|
// payable-to-control pair that used to be here, which skipped interest-paid
|
||||||
|
// entirely and left the expense off the P&L.
|
||||||
|
this.helper.createInterestPostingJournalEntriesForSavings(office, currencyCode, savingsProductId, paymentTypeId,
|
||||||
|
savingsId, transactionId, transactionDate, postingAmount, effectiveIsReversal, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
-4
@@ -167,15 +167,26 @@ public class CashBasedAccountingProcessorForSavings implements AccountingProcess
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if (savingsTransactionDTO.getTransactionType().isInterestPosting()) {
|
else if (savingsTransactionDTO.getTransactionType().isInterestPosting()) {
|
||||||
// Post journal entry if earned interest amount is greater than
|
// A premature FD closure that reprices interest downward (see
|
||||||
// zero
|
// FixedDepositAccount#postPreMaturityInterest) posts the difference as a NEGATIVE
|
||||||
if (savingsTransactionDTO.getAmount().compareTo(BigDecimal.ZERO) > 0) {
|
// interest-posting transaction -- a clawback of interest already recognised in earlier
|
||||||
|
// periods, not "zero interest, nothing to post". Skipping it here (the original
|
||||||
|
// "amount > 0" guard) left the FD subledger showing the clawback while the GL never
|
||||||
|
// recorded it, silently going out of sync. Treating a negative amount as a mirror-image
|
||||||
|
// reversal -- positive magnitude, debit/credit legs swapped, same mechanism
|
||||||
|
// createInterestPostingJournalEntriesForSavings already uses for isReversal -- keeps the two
|
||||||
|
// in sync instead.
|
||||||
|
final int amountSign = savingsTransactionDTO.getAmount().compareTo(BigDecimal.ZERO);
|
||||||
|
if (amountSign != 0) {
|
||||||
|
final boolean isClawback = amountSign < 0;
|
||||||
|
final BigDecimal postingAmount = isClawback ? amount.abs() : amount;
|
||||||
|
final boolean effectiveIsReversal = isReversal ^ isClawback;
|
||||||
// Routed through the payable and paid accounts the product names, so the society
|
// Routed through the payable and paid accounts the product names, so the society
|
||||||
// can read interest declared but not yet credited as its own balance. Collapses
|
// can read interest declared but not yet credited as its own balance. Collapses
|
||||||
// to the plain Dr Interest On Savings / Cr Savings Control pair for a product
|
// to the plain Dr Interest On Savings / Cr Savings Control pair for a product
|
||||||
// that names neither.
|
// that names neither.
|
||||||
this.helper.createInterestPostingJournalEntriesForSavings(office, currencyCode, savingsProductId, paymentTypeId,
|
this.helper.createInterestPostingJournalEntriesForSavings(office, currencyCode, savingsProductId, paymentTypeId,
|
||||||
savingsId, transactionId, transactionDate, amount, isReversal);
|
savingsId, transactionId, transactionDate, postingAmount, effectiveIsReversal, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
-1
@@ -105,7 +105,23 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
|
|||||||
.append(" journalEntry.currency_code as currencyCode, curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, ")
|
.append(" journalEntry.currency_code as currencyCode, curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, ")
|
||||||
.append(" curr.display_symbol as currencyDisplaySymbol, curr.decimal_places as currencyDigits, curr.currency_multiplesof as inMultiplesOf, ")
|
.append(" curr.display_symbol as currencyDisplaySymbol, curr.decimal_places as currencyDigits, curr.currency_multiplesof as inMultiplesOf, ")
|
||||||
.append(" eao.external_id as externalAssetOwner, ")
|
.append(" eao.external_id as externalAssetOwner, ")
|
||||||
|
// entity_type_enum=6 (PortfolioProductType.CURRENT) unambiguously names a row in
|
||||||
|
// m_current_account -- newer write paths tag current-account entries with it
|
||||||
|
// instead of reusing SAVING's type, specifically so this case needs no guessing.
|
||||||
|
//
|
||||||
|
// entity_type_enum=2 (PortfolioProductType.SAVING) is still written for BOTH savings
|
||||||
|
// and current-account entries by older write paths not yet updated to the above --
|
||||||
|
// current products used to deliberately share SAVING's GL type space (see
|
||||||
|
// PortfolioProductType.CURRENT's own comment) -- and m_savings_account/
|
||||||
|
// m_current_account each have their own id sequence, so an entity_id can be a real
|
||||||
|
// row in both, making a plain COALESCE(ca.account_no, sa.account_no) pick the current
|
||||||
|
// account's number even for an entry that is genuinely a savings one.
|
||||||
|
// savings_transaction_id is the one unambiguous signal available for those older
|
||||||
|
// entries -- only a real savings transaction sets it -- so it decides first; only
|
||||||
|
// when it's absent does the current-account guess apply.
|
||||||
.append(" CASE ")
|
.append(" CASE ")
|
||||||
|
.append(" WHEN journalEntry.entity_type_enum = 6 THEN ca.account_no ")
|
||||||
|
.append(" WHEN journalEntry.entity_type_enum = 2 AND journalEntry.savings_transaction_id IS NOT NULL THEN sa.account_no ")
|
||||||
.append(" WHEN journalEntry.entity_type_enum = 2 THEN COALESCE(ca.account_no, sa.account_no) ")
|
.append(" WHEN journalEntry.entity_type_enum = 2 THEN COALESCE(ca.account_no, sa.account_no) ")
|
||||||
.append(" ELSE NULL ")
|
.append(" ELSE NULL ")
|
||||||
.append(" END as savingsAccountNo ");
|
.append(" END as savingsAccountNo ");
|
||||||
@@ -130,7 +146,7 @@ public class JournalEntryReadPlatformServiceImpl implements JournalEntryReadPlat
|
|||||||
.append(" left join m_external_asset_owner_journal_entry_mapping eajem on eajem.journal_entry_id = journalEntry.id ")
|
.append(" left join m_external_asset_owner_journal_entry_mapping eajem on eajem.journal_entry_id = journalEntry.id ")
|
||||||
.append(" left join m_external_asset_owner eao on eao.id = eajem.owner_id ")
|
.append(" left join m_external_asset_owner eao on eao.id = eajem.owner_id ")
|
||||||
.append(" left join m_savings_account sa on sa.id = journalEntry.entity_id AND journalEntry.entity_type_enum = 2 ")
|
.append(" left join m_savings_account sa on sa.id = journalEntry.entity_id AND journalEntry.entity_type_enum = 2 ")
|
||||||
.append(" left join m_current_account ca on ca.id = journalEntry.entity_id AND journalEntry.entity_type_enum = 2 ");
|
.append(" left join m_current_account ca on ca.id = journalEntry.entity_id AND journalEntry.entity_type_enum IN (2, 6) ");
|
||||||
if (associationParametersData.isTransactionDetailsRequired()) {
|
if (associationParametersData.isTransactionDetailsRequired()) {
|
||||||
sb.append(" left join m_loan_transaction as lt on journalEntry.loan_transaction_id = lt.id ")
|
sb.append(" left join m_loan_transaction as lt on journalEntry.loan_transaction_id = lt.id ")
|
||||||
.append(" left join m_savings_account_transaction as st on journalEntry.savings_transaction_id = st.id ")
|
.append(" left join m_savings_account_transaction as st on journalEntry.savings_transaction_id = st.id ")
|
||||||
|
|||||||
+6
-1
@@ -631,7 +631,12 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
|
|||||||
final boolean cashBasedAccountingEnabled = (Boolean) accountingBridgeData.get("cashBasedAccountingEnabled");
|
final boolean cashBasedAccountingEnabled = (Boolean) accountingBridgeData.get("cashBasedAccountingEnabled");
|
||||||
final boolean accrualBasedAccountingEnabled = (Boolean) accountingBridgeData.get("accrualBasedAccountingEnabled");
|
final boolean accrualBasedAccountingEnabled = (Boolean) accountingBridgeData.get("accrualBasedAccountingEnabled");
|
||||||
|
|
||||||
if (cashBasedAccountingEnabled) {
|
// A register that knows the transaction's real counterparty posts the entry itself, in one
|
||||||
|
// balanced pair against that account, and says so by wrapping the command in
|
||||||
|
// ShareAccountingSuppression.withOwnShareEntries(). Posting here as well would add a second
|
||||||
|
// entry for the same money, booked against the product's fixed Shares Reference account --
|
||||||
|
// which is what that register is avoiding in the first place.
|
||||||
|
if (cashBasedAccountingEnabled && ShareAccountingSuppression.shouldPostShareEntries()) {
|
||||||
final SharesDTO sharesDTO = this.helper.populateSharesDtoFromMap(accountingBridgeData, cashBasedAccountingEnabled,
|
final SharesDTO sharesDTO = this.helper.populateSharesDtoFromMap(accountingBridgeData, cashBasedAccountingEnabled,
|
||||||
accrualBasedAccountingEnabled);
|
accrualBasedAccountingEnabled);
|
||||||
final AccountingProcessorForShares accountingProcessorForShares = this.accountingProcessorForSharesFactory
|
final AccountingProcessorForShares accountingProcessorForShares = this.accountingProcessorForSharesFactory
|
||||||
|
|||||||
+157
@@ -0,0 +1,157 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.accounting.journalentry.service;
|
||||||
|
|
||||||
|
import java.sql.Date;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mints the transaction id that ties the rows of one posting together in acc_gl_journal_entry.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Every feature here that posts a journal entry by direct JDBC used to invent this id by hand, and the two
|
||||||
|
* shapes that emerged were each wrong in their own way. Some concatenated a business row's own primary key
|
||||||
|
* ({@code "DIVROUND" + dividendPayOutId}); a primary key is only unique while its sequence keeps climbing,
|
||||||
|
* so a reset hands the same number out twice - which is exactly how two unrelated share withdrawals came to
|
||||||
|
* share one transaction id and render as a single doubled voucher. Others concatenated
|
||||||
|
* {@code System.nanoTime()}, which is unique but says nothing to whoever reads it off a screen
|
||||||
|
* ({@code "CASHMIG-1-20260913-923935527932300"}).
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* This generator replaces both with one readable shape, {@code PREFIX-YYMMDD-NNNN}:
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* SHWGL-260916-0001 the first share-withdrawal GL settlement posted on 16 Sep 2026
|
||||||
|
* DIVRND-260916-0007 the seventh dividend rounding posted that day
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* The prefix names the event, the date is the tenant's business date, and the serial restarts at 0001 each
|
||||||
|
* day. That makes a transaction id self-describing: a reader can tell what it was and when it happened
|
||||||
|
* without looking anything up.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Uniqueness does not depend on any business table. The serial comes from {@code m_ledger_txn_sequence}, a
|
||||||
|
* counter that belongs to no entity, so no entity's sequence can make it repeat. The counter is bumped by a
|
||||||
|
* single {@code INSERT ... ON CONFLICT DO UPDATE}, which takes and releases the row lock atomically, so two
|
||||||
|
* users posting at the same instant are serialised by the database rather than handed the same number - the
|
||||||
|
* same mechanism {@code m_voucher_sequence} already uses for voucher numbers.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* The counter alone would still repeat if that table were ever truncated or rewound by hand, which is
|
||||||
|
* precisely the accident being defended against, so the minted id is also checked against the ledger before
|
||||||
|
* being handed back and the counter is advanced past anything already in use. That makes a duplicate
|
||||||
|
* impossible by construction rather than by convention: the id is only returned once no row holds it.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Ids already in the ledger keep their old shape. Nothing reconstructs a custom id to find its rows again
|
||||||
|
* (every call site mints one, posts with it, and never derives it a second time), so old and new shapes
|
||||||
|
* coexist without anything needing to read both.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Postings made by Fineract's own command path are not covered here and keep their native
|
||||||
|
* {@code "S"/"L"/"SH"/"C" + transaction id} form, which {@code AccountingProcessorHelper} derives and
|
||||||
|
* several readers reconstruct. Those readers are hardened at the query instead, by resolving to the most
|
||||||
|
* recently posted rows rather than assuming the text is unique.
|
||||||
|
*/
|
||||||
|
public final class LedgerTransactionId {
|
||||||
|
|
||||||
|
/** Guards against an impossible-in-practice runaway if the ledger and the counter disagree. */
|
||||||
|
private static final int MAX_PROBES = 50;
|
||||||
|
|
||||||
|
private static final DateTimeFormatter YYMMDD = DateTimeFormatter.ofPattern("yyMMdd");
|
||||||
|
|
||||||
|
private LedgerTransactionId() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the next transaction id for this kind of posting, e.g. {@code SHWGL-260916-0001}.
|
||||||
|
*
|
||||||
|
* @param prefix
|
||||||
|
* short uppercase code naming the event, from {@link LedgerTxnPrefix}
|
||||||
|
*/
|
||||||
|
public static String next(final JdbcTemplate jdbcTemplate, final String prefix) {
|
||||||
|
// Tenant timezone, not the server's - the day the counter resets on has to be the branch's
|
||||||
|
// business day, otherwise a late-evening posting lands in the wrong series.
|
||||||
|
final LocalDate today = LocalDate.now(DateUtils.getDateTimeZoneOfTenant());
|
||||||
|
final String datePart = today.format(YYMMDD);
|
||||||
|
|
||||||
|
for (int probe = 0; probe < MAX_PROBES; probe++) {
|
||||||
|
final int serial = nextSerial(jdbcTemplate, prefix, today);
|
||||||
|
final String candidate = String.format("%s-%s-%04d", prefix, datePart, serial);
|
||||||
|
if (!isTaken(jdbcTemplate, candidate)) {
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
|
// Only reachable if the counter was rewound behind the ledger by hand. Bumping again walks
|
||||||
|
// it forward until it clears whatever is already posted, which self-heals the counter.
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("Could not mint a free ledger transaction id for prefix " + prefix + " after " + MAX_PROBES
|
||||||
|
+ " attempts. The m_ledger_txn_sequence counter for this prefix is far behind the entries already posted today.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the id for a posting that has to be reproducible, e.g. {@code SAVINT-260916-P0002}.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Some postings are not one-shot: a pooled interest run pays hundreds of members, and a run that
|
||||||
|
* stops halfway is resumed rather than restarted. Those resumed legs belong to the posting that
|
||||||
|
* started them, so the id has to come out the same on the second pass - a counter would hand the
|
||||||
|
* remainder a different id and split one posting across two transactions. This builds the id from
|
||||||
|
* what identifies the run instead: the same prefix, date and discriminator always produce the same
|
||||||
|
* string, and no counter is consumed.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Uniqueness rests on the caller's own discriminator being unique for that prefix and date (the
|
||||||
|
* product being posted, say), which is what makes the id reproducible in the first place. Use
|
||||||
|
* {@link #next} for everything else - a posting that happens once wants a counter, not a formula.
|
||||||
|
* The {@code P} marks the tail as a discriminator so it is not misread as a serial.
|
||||||
|
*
|
||||||
|
* @param date
|
||||||
|
* the date the posting belongs to, which is not always today - interest can be posted
|
||||||
|
* for an earlier day
|
||||||
|
* @param discriminator
|
||||||
|
* what makes this run distinct from another on the same date, e.g. the product id
|
||||||
|
*/
|
||||||
|
public static String forDatedSeries(final String prefix, final LocalDate date, final long discriminator) {
|
||||||
|
return String.format("%s-%s-P%04d", prefix, date.format(YYMMDD), discriminator);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reserves the next counter value for one (prefix, day) series.
|
||||||
|
*
|
||||||
|
* The INSERT ... ON CONFLICT DO UPDATE both creates the series on its first use of the day and
|
||||||
|
* increments it thereafter. Being a single statement it is atomic, so no explicit lock is needed.
|
||||||
|
*/
|
||||||
|
private static int nextSerial(final JdbcTemplate jdbcTemplate, final String prefix, final LocalDate day) {
|
||||||
|
return jdbcTemplate.queryForObject("""
|
||||||
|
INSERT INTO m_ledger_txn_sequence (prefix, series_date, last_number)
|
||||||
|
VALUES (?,?,1)
|
||||||
|
ON CONFLICT (prefix, series_date)
|
||||||
|
DO UPDATE SET last_number = m_ledger_txn_sequence.last_number + 1
|
||||||
|
RETURNING last_number
|
||||||
|
""", Integer.class, prefix, Date.valueOf(day));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isTaken(final JdbcTemplate jdbcTemplate, final String transactionId) {
|
||||||
|
final Boolean taken = jdbcTemplate.queryForObject("SELECT EXISTS (SELECT 1 FROM acc_gl_journal_entry WHERE transaction_id = ?)",
|
||||||
|
Boolean.class, transactionId);
|
||||||
|
return Boolean.TRUE.equals(taken);
|
||||||
|
}
|
||||||
|
}
|
||||||
+87
@@ -0,0 +1,87 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.accounting.journalentry.service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The event codes that open a transaction id minted by {@link LedgerTransactionId}.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* They live together in one place so a reader can decode any transaction id on a screen from a single list,
|
||||||
|
* and so no two features can drift into naming the same event differently - which had already happened:
|
||||||
|
* dividend forfeiture was posting under {@code DIVFORF} from one service and {@code DIVFORFEIT} from
|
||||||
|
* another, for the same event.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Codes are uppercase, up to eight characters, and grouped by the module that raises them. A code is part of
|
||||||
|
* the audit trail once it has been posted, so treat these as append-only: add a new one for a new event
|
||||||
|
* rather than renaming an existing one, which would leave already-posted entries speaking a language nothing
|
||||||
|
* else uses any more.
|
||||||
|
*/
|
||||||
|
public final class LedgerTxnPrefix {
|
||||||
|
|
||||||
|
private LedgerTxnPrefix() {}
|
||||||
|
|
||||||
|
// A clerk's share withdrawal has no code here on purpose: it posts under the transaction id the
|
||||||
|
// native redeem command already minted ("SH" + share transaction id), because its debit leg is
|
||||||
|
// that command's own and the two have to group as one balanced entry.
|
||||||
|
|
||||||
|
// ── Share tranche funding ─────────────────────────────────────────────────
|
||||||
|
/** Additional share tranche: reversal of the stock reference posting. */
|
||||||
|
public static final String SHARE_TRANCHE_REFERENCE = "SHTREF";
|
||||||
|
/** Additional share tranche funded from the member's savings account. */
|
||||||
|
public static final String SHARE_TRANCHE_SAVINGS = "SHTSAV";
|
||||||
|
|
||||||
|
// ── Share collection and advances ─────────────────────────────────────────
|
||||||
|
/** Share application money collected. */
|
||||||
|
public static final String SHARE_COLLECTION = "SHCOL";
|
||||||
|
/** Share advance collected against a future allotment. */
|
||||||
|
public static final String SHARE_ADVANCE = "SHADV";
|
||||||
|
/** Share advance applied to an allotment. */
|
||||||
|
public static final String SHARE_ADVANCE_APPLIED = "SHAPP";
|
||||||
|
|
||||||
|
// ── Dividend ──────────────────────────────────────────────────────────────
|
||||||
|
/** Dividend claim paid out to a member. */
|
||||||
|
public static final String DIVIDEND_CLAIM = "DIVCLM";
|
||||||
|
/** Dividend declaration posted. */
|
||||||
|
public static final String DIVIDEND_DECLARED = "DIVDCL";
|
||||||
|
/** Dividend declaration approved. */
|
||||||
|
public static final String DIVIDEND_APPROVED = "DIVAPR";
|
||||||
|
/** Dividend payout closed off. */
|
||||||
|
public static final String DIVIDEND_CLOSED = "DIVCLS";
|
||||||
|
/** Rounding difference on a dividend payout. */
|
||||||
|
public static final String DIVIDEND_ROUNDING = "DIVRND";
|
||||||
|
/** Unclaimed dividend forfeited. */
|
||||||
|
public static final String DIVIDEND_FORFEIT = "DIVFRF";
|
||||||
|
|
||||||
|
// ── Branch day and cash ───────────────────────────────────────────────────
|
||||||
|
/** Opening cash migrated into the branch day register. */
|
||||||
|
public static final String CASH_MIGRATION = "CSHMIG";
|
||||||
|
/** Rounding difference on a clerk's day closure. */
|
||||||
|
public static final String CLOSURE_ROUNDING = "CLSRND";
|
||||||
|
|
||||||
|
// ── Year end ──────────────────────────────────────────────────────────────
|
||||||
|
/** Year-end transfer of income into the profit account. */
|
||||||
|
public static final String YEAR_END_PROFIT = "YEPFT";
|
||||||
|
/** Year-end closure of an income or expense account. */
|
||||||
|
public static final String YEAR_END_CLOSE = "YECLS";
|
||||||
|
|
||||||
|
// ── Savings ───────────────────────────────────────────────────────────────
|
||||||
|
/** Pooled savings interest posting for one product and date. */
|
||||||
|
public static final String SAVINGS_INTEREST_POOLED = "SAVINT";
|
||||||
|
}
|
||||||
+83
@@ -0,0 +1,83 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.accounting.journalentry.service;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lets a register that posts a share transaction's accounting itself tell the platform not to post its
|
||||||
|
* own.
|
||||||
|
*
|
||||||
|
* <h3>Why this exists</h3>
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Fineract books every share transaction against a fixed "Shares Reference" account taken from the
|
||||||
|
* product's GL mapping: a redemption posts Dr Shares Equity / Cr Shares Reference, whatever the money
|
||||||
|
* actually did. That account is a placeholder for a counterparty the platform does not know, and in a
|
||||||
|
* real core banking ledger there is no such thing — a redemption paid in cash credits the cash
|
||||||
|
* account, and one settled by transfer credits the account it was transferred to. Naming a single
|
||||||
|
* asset account for both leaves every redemption sitting against a GL the money never touched, which
|
||||||
|
* then has to be corrected by hand.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* The governed clerk registers already know the real counterparty, because the clerk keyed it: the
|
||||||
|
* linked savings account, or the GL picked on the transfer's credit row. They post the redemption
|
||||||
|
* themselves, correctly, in one balanced entry. Before this flag existed they had to let the platform
|
||||||
|
* post its version first and then reverse the half that was wrong, which left a dead Cr Shares
|
||||||
|
* Reference row behind on every redemption and made the ledger read as though cash had moved.
|
||||||
|
*
|
||||||
|
* <h3>Why a flag and not the product's accounting rule</h3>
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Turning the share product's accounting off entirely ({@code m_share_product.accounting_type = NONE})
|
||||||
|
* would silence the platform everywhere, including the share account screen's own Redeem action, which
|
||||||
|
* no register covers — those redemptions would post nothing at all and go unnoticed, because that
|
||||||
|
* branch fails silently by design. Scoping the suppression to the one call that is about to post its
|
||||||
|
* own entry leaves every other path exactly as it is.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* A ThreadLocal rather than a request attribute, and restoring the previous value rather than clearing
|
||||||
|
* it, for the same reasons as {@code VoucherService.withOwnVoucher} — a batch job has no request to
|
||||||
|
* hang the flag on, and nesting must not switch the suppression off early for an outer caller.
|
||||||
|
*/
|
||||||
|
public final class ShareAccountingSuppression {
|
||||||
|
|
||||||
|
private static final ThreadLocal<Boolean> CALLER_POSTS_SHARE_ENTRIES = ThreadLocal.withInitial(() -> Boolean.FALSE);
|
||||||
|
|
||||||
|
private ShareAccountingSuppression() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs {@code command} with the platform's own share journal entries suppressed, for a caller that
|
||||||
|
* posts the transaction's accounting itself.
|
||||||
|
*/
|
||||||
|
public static <T> T withOwnShareEntries(final Supplier<T> command) {
|
||||||
|
final boolean previous = CALLER_POSTS_SHARE_ENTRIES.get();
|
||||||
|
CALLER_POSTS_SHARE_ENTRIES.set(Boolean.TRUE);
|
||||||
|
try {
|
||||||
|
return command.get();
|
||||||
|
} finally {
|
||||||
|
CALLER_POSTS_SHARE_ENTRIES.set(previous);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** False only while a caller inside {@link #withOwnShareEntries} is posting its own entries. */
|
||||||
|
public static boolean shouldPostShareEntries() {
|
||||||
|
return !CALLER_POSTS_SHARE_ENTRIES.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
+19
-1
@@ -294,8 +294,14 @@ public class ProductToGLAccountMappingWritePlatformServiceImpl implements Produc
|
|||||||
SavingProductAccountingParams.TRANSFERS_SUSPENSE.getValue(), savingProductId,
|
SavingProductAccountingParams.TRANSFERS_SUSPENSE.getValue(), savingProductId,
|
||||||
CashAccountsForSavings.TRANSFERS_SUSPENSE.getValue());
|
CashAccountsForSavings.TRANSFERS_SUSPENSE.getValue());
|
||||||
|
|
||||||
|
// FD and RD products switch dormancy on with "dormancyAlert" (DepositProductAssembler derives the product's
|
||||||
|
// tracking flag from it) and never send isDormancyTrackingActive, so reading only that dropped the escheat
|
||||||
|
// account the screen had asked for - the product then tracked dormancy with no escheat account mapped.
|
||||||
final Boolean isDormancyTrackingActive = this.fromApiJsonHelper.extractBooleanNamed(isDormancyTrackingActiveParamName, element);
|
final Boolean isDormancyTrackingActive = this.fromApiJsonHelper.extractBooleanNamed(isDormancyTrackingActiveParamName, element);
|
||||||
if (null != isDormancyTrackingActive && isDormancyTrackingActive) {
|
final Boolean dormancyAlert = this.fromApiJsonHelper.parameterExists("dormancyAlert", element)
|
||||||
|
? this.fromApiJsonHelper.extractBooleanNamed("dormancyAlert", element)
|
||||||
|
: null;
|
||||||
|
if (Boolean.TRUE.equals(isDormancyTrackingActive) || Boolean.TRUE.equals(dormancyAlert)) {
|
||||||
this.savingsProductToGLAccountMappingHelper.saveSavingsToLiabilityAccountMapping(element,
|
this.savingsProductToGLAccountMappingHelper.saveSavingsToLiabilityAccountMapping(element,
|
||||||
SavingProductAccountingParams.ESCHEAT_LIABILITY.getValue(), savingProductId,
|
SavingProductAccountingParams.ESCHEAT_LIABILITY.getValue(), savingProductId,
|
||||||
CashAccountsForSavings.ESCHEAT_LIABILITY.getValue());
|
CashAccountsForSavings.ESCHEAT_LIABILITY.getValue());
|
||||||
@@ -329,6 +335,18 @@ public class ProductToGLAccountMappingWritePlatformServiceImpl implements Produc
|
|||||||
break;
|
break;
|
||||||
case CASH_BASED:
|
case CASH_BASED:
|
||||||
saveSavingsBaseAccountMapping(savingProductId, accountType, command, element);
|
saveSavingsBaseAccountMapping(savingProductId, accountType, command, element);
|
||||||
|
// Interest Payable is saved on cash too, and optionally: interest posting routes
|
||||||
|
// through it on either basis (see AccountingProcessorHelper
|
||||||
|
// .createInterestPostingJournalEntriesForSavings), so that interest declared but not
|
||||||
|
// yet credited to the member reads as the bank's own liability rather than appearing
|
||||||
|
// only at the moment it is paid. Mapped only when the screen supplies it - a product
|
||||||
|
// naming none still posts straight to Savings Control, as it always did.
|
||||||
|
if (this.fromApiJsonHelper.parameterExists(SavingProductAccountingParams.INTEREST_PAYABLE.getValue(),
|
||||||
|
element)) {
|
||||||
|
this.savingsProductToGLAccountMappingHelper.saveSavingsToLiabilityAccountMapping(element,
|
||||||
|
SavingProductAccountingParams.INTEREST_PAYABLE.getValue(), savingProductId,
|
||||||
|
AccrualAccountsForSavings.INTEREST_PAYABLE.getValue());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACCRUAL_PERIODIC:
|
case ACCRUAL_PERIODIC:
|
||||||
|
|||||||
+4
-2
@@ -12,6 +12,8 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.fineract.accounting.common.DividendGlAccountResolver;
|
import org.apache.fineract.accounting.common.DividendGlAccountResolver;
|
||||||
import org.apache.fineract.accounting.glaccount.validation.GLAccountTransactionGuard;
|
import org.apache.fineract.accounting.glaccount.validation.GLAccountTransactionGuard;
|
||||||
|
import org.apache.fineract.accounting.journalentry.service.LedgerTransactionId;
|
||||||
|
import org.apache.fineract.accounting.journalentry.service.LedgerTxnPrefix;
|
||||||
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
|
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
|
||||||
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
||||||
import org.springframework.dao.EmptyResultDataAccessException;
|
import org.springframework.dao.EmptyResultDataAccessException;
|
||||||
@@ -117,7 +119,7 @@ public class IncomeProfitTransferService {
|
|||||||
final String currencyCode = resolveCurrency(incomeGlId);
|
final String currencyCode = resolveCurrency(incomeGlId);
|
||||||
final LocalDateTime now = LocalDateTime.now(DateUtils.getDateTimeZoneOfTenant());
|
final LocalDateTime now = LocalDateTime.now(DateUtils.getDateTimeZoneOfTenant());
|
||||||
final LocalDate postingDate = range[1];
|
final LocalDate postingDate = range[1];
|
||||||
final String txnId = "YEPROFIT-" + System.nanoTime();
|
final String txnId = LedgerTransactionId.next(this.jdbcTemplate, LedgerTxnPrefix.YEAR_END_PROFIT);
|
||||||
final String desc = "Year-end closing " + financialYear + " — " + incomeGl.get("name") + " to profit"
|
final String desc = "Year-end closing " + financialYear + " — " + incomeGl.get("name") + " to profit"
|
||||||
+ (note != null ? " | " + note : "");
|
+ (note != null ? " | " + note : "");
|
||||||
|
|
||||||
@@ -210,7 +212,7 @@ public class IncomeProfitTransferService {
|
|||||||
final String currencyCode = resolveCurrency(glId);
|
final String currencyCode = resolveCurrency(glId);
|
||||||
final LocalDateTime now = LocalDateTime.now(DateUtils.getDateTimeZoneOfTenant());
|
final LocalDateTime now = LocalDateTime.now(DateUtils.getDateTimeZoneOfTenant());
|
||||||
final LocalDate postingDate = range[1];
|
final LocalDate postingDate = range[1];
|
||||||
final String txnId = "YECLOSE-" + financialYear + "-" + gl.get("gl_code") + "-" + System.nanoTime();
|
final String txnId = LedgerTransactionId.next(this.jdbcTemplate, LedgerTxnPrefix.YEAR_END_CLOSE);
|
||||||
final String descr = "Year-end closing " + financialYear + " — " + gl.get("name") + " to profit"
|
final String descr = "Year-end closing " + financialYear + " — " + gl.get("name") + " to profit"
|
||||||
+ (note != null ? " | " + note : "");
|
+ (note != null ? " | " + note : "");
|
||||||
|
|
||||||
|
|||||||
+3
@@ -35,6 +35,7 @@ import org.apache.fineract.cob.data.OldestCOBProcessedLoanDTO;
|
|||||||
import org.apache.fineract.cob.service.LoanCOBCatchUpService;
|
import org.apache.fineract.cob.service.LoanCOBCatchUpService;
|
||||||
import org.apache.fineract.infrastructure.core.exception.JobIsNotFoundOrNotEnabledException;
|
import org.apache.fineract.infrastructure.core.exception.JobIsNotFoundOrNotEnabledException;
|
||||||
import org.apache.fineract.infrastructure.jobs.service.JobName;
|
import org.apache.fineract.infrastructure.jobs.service.JobName;
|
||||||
|
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Path("/v1/loans")
|
@Path("/v1/loans")
|
||||||
@@ -44,6 +45,7 @@ import org.springframework.stereotype.Component;
|
|||||||
public class LoanCOBCatchUpApiResource {
|
public class LoanCOBCatchUpApiResource {
|
||||||
|
|
||||||
private final Optional<LoanCOBCatchUpService> loanCOBCatchUpServiceOp;
|
private final Optional<LoanCOBCatchUpService> loanCOBCatchUpServiceOp;
|
||||||
|
private final PlatformSecurityContext context;
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("oldest-cob-closed")
|
@Path("oldest-cob-closed")
|
||||||
@@ -64,6 +66,7 @@ public class LoanCOBCatchUpApiResource {
|
|||||||
@ApiResponse(responseCode = "202", description = "Catch Up has been started")
|
@ApiResponse(responseCode = "202", description = "Catch Up has been started")
|
||||||
@ApiResponse(responseCode = "400", description = "Catch Up is already running")
|
@ApiResponse(responseCode = "400", description = "Catch Up is already running")
|
||||||
public Response executeLoanCOBCatchUp() {
|
public Response executeLoanCOBCatchUp() {
|
||||||
|
this.context.authenticatedUser().validateHasPermissionTo("EXECUTE_LOANCOBCATCHUP");
|
||||||
return loanCOBCatchUpServiceOp.map(loanCOBCatchUpService -> {
|
return loanCOBCatchUpServiceOp.map(loanCOBCatchUpService -> {
|
||||||
if (loanCOBCatchUpService.isCatchUpRunning().isCatchUpRunning()) {
|
if (loanCOBCatchUpService.isCatchUpRunning().isCatchUpRunning()) {
|
||||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||||
|
|||||||
+49
-8
@@ -165,9 +165,11 @@ public class SecurityConfig {
|
|||||||
// envelope's RSA signature/encryption (NpciCryptoUtil) inside the handler.
|
// envelope's RSA signature/encryption (NpciCryptoUtil) inside the handler.
|
||||||
.requestMatchers(API_MATCHER.matcher(HttpMethod.POST, "/api/*/npci/**")).permitAll()
|
.requestMatchers(API_MATCHER.matcher(HttpMethod.POST, "/api/*/npci/**")).permitAll()
|
||||||
// Client account summary, third-party callers — a partner integration calls this
|
// Client account summary, third-party callers — a partner integration calls this
|
||||||
// with an X-Api-Key header instead of a Fineract username/password (issued via
|
// with an X-Api-Key header instead of a Fineract username/password. The key itself
|
||||||
// POST /v1/apiclients, super-user only). Same posture as IMPS/NPCI above: the
|
// is issued by inserting directly into m_api_client in the tenant-store database
|
||||||
// outer gate stays open for this one narrow GET path, and
|
// (see ApiClientAdminApiResource — its POST /v1/apiclients is deliberately disabled,
|
||||||
|
// since any bank's own super user reaching it could mint a platform-wide key). Same
|
||||||
|
// posture as IMPS/NPCI above: the outer gate stays open for this one narrow GET path, and
|
||||||
// ClientAllAccountsApiResource#retrieveByClientNo is what actually authenticates
|
// ClientAllAccountsApiResource#retrieveByClientNo is what actually authenticates
|
||||||
// the caller (ApiClientCredentialService checks the key's hash, active flag and
|
// the caller (ApiClientCredentialService checks the key's hash, active flag and
|
||||||
// IP allowlist) — a request with no key and no Fineract login still gets nothing,
|
// IP allowlist) — a request with no key and no Fineract login still gets nothing,
|
||||||
@@ -222,7 +224,10 @@ public class SecurityConfig {
|
|||||||
// currency
|
// currency
|
||||||
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/currencies"))
|
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/currencies"))
|
||||||
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_CURRENCY")
|
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_CURRENCY")
|
||||||
.requestMatchers(API_MATCHER.matcher(HttpMethod.POST, "/api/*/currencies"))
|
// the actual currency-update endpoint is PUT (CurrenciesApiResource has no @POST method) -
|
||||||
|
// this matcher previously targeted POST, which meant PUT fell through to the generic
|
||||||
|
// fullyAuthenticated() catch-all with no permission check at all.
|
||||||
|
.requestMatchers(API_MATCHER.matcher(HttpMethod.PUT, "/api/*/currencies"))
|
||||||
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "UPDATE_CURRENCY")
|
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "UPDATE_CURRENCY")
|
||||||
// notes: read
|
// notes: read
|
||||||
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/clients/*/notes"))
|
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/clients/*/notes"))
|
||||||
@@ -355,11 +360,18 @@ public class SecurityConfig {
|
|||||||
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/import/*"))
|
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/import/*"))
|
||||||
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_IMPORT")
|
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_IMPORT")
|
||||||
// payment type
|
// payment type
|
||||||
|
// NOTE: POST previously required "UPDATE_PAYMENTTYPE" (wrong authority for create), with a
|
||||||
|
// second, unreachable matcher for the same POST pattern requiring "DELETE_PAYMENTTYPE" - and
|
||||||
|
// no PUT/DELETE matcher existed at all, so those requests fell through to the generic
|
||||||
|
// fullyAuthenticated() catch-all below with no permission check. Corrected to one matcher
|
||||||
|
// per method, each requiring its own correct permission code.
|
||||||
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/paymenttypes/*"))
|
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/paymenttypes/*"))
|
||||||
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_PAYMENTTYPE")
|
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_PAYMENTTYPE")
|
||||||
.requestMatchers(API_MATCHER.matcher(HttpMethod.POST, "/api/*/paymenttypes"))
|
.requestMatchers(API_MATCHER.matcher(HttpMethod.POST, "/api/*/paymenttypes"))
|
||||||
|
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "CREATE_PAYMENTTYPE")
|
||||||
|
.requestMatchers(API_MATCHER.matcher(HttpMethod.PUT, "/api/*/paymenttypes/*"))
|
||||||
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "UPDATE_PAYMENTTYPE")
|
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "UPDATE_PAYMENTTYPE")
|
||||||
.requestMatchers(API_MATCHER.matcher(HttpMethod.POST, "/api/*/paymenttypes"))
|
.requestMatchers(API_MATCHER.matcher(HttpMethod.DELETE, "/api/*/paymenttypes/*"))
|
||||||
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "DELETE_PAYMENTTYPE")
|
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "DELETE_PAYMENTTYPE")
|
||||||
// mix: taxonomy
|
// mix: taxonomy
|
||||||
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/mixtaxonomy/*"))
|
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/mixtaxonomy/*"))
|
||||||
@@ -390,12 +402,41 @@ public class SecurityConfig {
|
|||||||
.requestMatchers(API_MATCHER.matcher(HttpMethod.DELETE, "/api/*/mixreport/*"))
|
.requestMatchers(API_MATCHER.matcher(HttpMethod.DELETE, "/api/*/mixreport/*"))
|
||||||
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "DELETE_MIX_REPORT")
|
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "DELETE_MIX_REPORT")
|
||||||
// working days
|
// working days
|
||||||
|
// NOTE: previously "READ_WORKING_DAYS"/"UPDATE_WORKING_DAYS" (with an underscore between
|
||||||
|
// WORKING and DAYS), which did not match the actual seeded permission codes
|
||||||
|
// (READ_WORKINGDAYS / UPDATE_WORKINGDAYS) - corrected to the real codes.
|
||||||
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/workingdays"))
|
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/workingdays"))
|
||||||
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_WORKING_DAYS")
|
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_WORKINGDAYS")
|
||||||
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/workingdays/template"))
|
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/workingdays/template"))
|
||||||
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_WORKING_DAYS")
|
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_WORKINGDAYS")
|
||||||
.requestMatchers(API_MATCHER.matcher(HttpMethod.PUT, "/api/*/workingdays"))
|
.requestMatchers(API_MATCHER.matcher(HttpMethod.PUT, "/api/*/workingdays"))
|
||||||
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "UPDATE_WORKING_DAYS")
|
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "UPDATE_WORKINGDAYS")
|
||||||
|
// sponsor banks
|
||||||
|
// NOTE: no matcher previously existed at all for this path - POST/PUT both fell
|
||||||
|
// through to the generic fullyAuthenticated() catch-all below with no permission
|
||||||
|
// check whatsoever.
|
||||||
|
.requestMatchers(API_MATCHER.matcher(HttpMethod.POST, "/api/*/sponsorbanks"))
|
||||||
|
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "CREATE_SPONSORBANK")
|
||||||
|
.requestMatchers(API_MATCHER.matcher(HttpMethod.PUT, "/api/*/sponsorbanks/*"))
|
||||||
|
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "UPDATE_SPONSORBANK")
|
||||||
|
// sponsor DD GST/GL settings
|
||||||
|
// NOTE: no matcher previously existed at all for this path either. gl-mapping is a
|
||||||
|
// genuine upsert (one call both creates and updates the single settings row), so it is
|
||||||
|
// covered by one UPDATE_SPONSORDDGLMAPPING matcher rather than a separate CREATE one.
|
||||||
|
.requestMatchers(API_MATCHER.matcher(HttpMethod.POST, "/api/*/sponsordd/gl-mapping"))
|
||||||
|
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "UPDATE_SPONSORDDGLMAPPING")
|
||||||
|
// bank profile (institution profile)
|
||||||
|
// NOTE: no matcher previously existed at all for this path - the PUT relied solely on
|
||||||
|
// the in-resource validateHasPermissionTo() check, which this change replaces with the
|
||||||
|
// command-source pipeline. Added here for the same defense-in-depth already applied to
|
||||||
|
// Currency/Payment Type/Working Days.
|
||||||
|
.requestMatchers(API_MATCHER.matcher(HttpMethod.PUT, "/api/*/institutionprofile"))
|
||||||
|
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "UPDATE_INSTITUTIONPROFILE")
|
||||||
|
// branch profile
|
||||||
|
// NOTE: no matcher previously existed at all for this path either, same rationale as
|
||||||
|
// institution profile above.
|
||||||
|
.requestMatchers(API_MATCHER.matcher(HttpMethod.PUT, "/api/*/branchprofile/*"))
|
||||||
|
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "UPDATE_BRANCHPROFILE")
|
||||||
|
|
||||||
.requestMatchers(API_MATCHER.matcher(HttpMethod.POST, "/api/*/twofactor/validate")).fullyAuthenticated()
|
.requestMatchers(API_MATCHER.matcher(HttpMethod.POST, "/api/*/twofactor/validate")).fullyAuthenticated()
|
||||||
.requestMatchers(API_MATCHER.matcher("/api/*/twofactor")).fullyAuthenticated()
|
.requestMatchers(API_MATCHER.matcher("/api/*/twofactor")).fullyAuthenticated()
|
||||||
|
|||||||
+20
-14
@@ -20,7 +20,6 @@ package org.apache.fineract.infrastructure.security.apiclient;
|
|||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.ws.rs.Consumes;
|
import jakarta.ws.rs.Consumes;
|
||||||
import jakarta.ws.rs.DELETE;
|
import jakarta.ws.rs.DELETE;
|
||||||
@@ -35,17 +34,26 @@ import jakarta.ws.rs.core.Response;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
|
|
||||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||||
import org.apache.fineract.useradministration.domain.AppUser;
|
import org.apache.fineract.useradministration.domain.AppUser;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Admin-only management of the third-party API keys {@link ApiClientCredentialService} authenticates.
|
* Admin-only management of the third-party API keys {@link ApiClientCredentialService} authenticates.
|
||||||
* This resource itself requires a normal Fineract login, same as everything else -- ordinary
|
* List/deactivate/reactivate still require a normal Fineract login restricted to a super user
|
||||||
* username/password, restricted to a super user (ALL_FUNCTIONS). Only the endpoints that use a minted
|
* (ALL_FUNCTIONS) -- but minting a NEW key ({@link #create}) is disabled here entirely, on purpose.
|
||||||
* key to skip login (e.g. GET /v1/clientaccounts) are the ones exempted in SecurityConfig; issuing that
|
*
|
||||||
* key in the first place is not something to hand to just anyone.
|
* {@code ALL_FUNCTIONS} is a per-TENANT role grant -- and {@code TenantMenuAccessApiResource}'s whole
|
||||||
|
* point is that a bank's own super user (or a role simply misconfigured to carry ALL_FUNCTIONS, as the
|
||||||
|
* "Clerk" role was found to in two tenants this session) must never be able to lift its own menu-access
|
||||||
|
* ceiling. If this endpoint minted keys for any ALL_FUNCTIONS holder, that same bank super user could
|
||||||
|
* call {@code POST /v1/apiclients} and hand themselves a brand-new platform-operator credential -- one
|
||||||
|
* that authenticates against every tenant, not just their own -- completely bypassing the ceiling this
|
||||||
|
* key mechanism exists to enforce. A super user being able to read/deactivate the client list is fine
|
||||||
|
* (visibility and revocation are not privilege escalation); being able to mint a fresh one is exactly
|
||||||
|
* the escalation path being closed. New keys are issued the same way this fix issued the first one: a
|
||||||
|
* direct insert into {@code m_api_client} (see {@link ApiClientCredentialService#createClient}), by
|
||||||
|
* whoever already has direct database access -- never over HTTP.
|
||||||
*/
|
*/
|
||||||
@Path("/v1/apiclients")
|
@Path("/v1/apiclients")
|
||||||
@Component
|
@Component
|
||||||
@@ -55,20 +63,18 @@ public class ApiClientAdminApiResource {
|
|||||||
|
|
||||||
private final PlatformSecurityContext context;
|
private final PlatformSecurityContext context;
|
||||||
private final ApiClientCredentialService credentialService;
|
private final ApiClientCredentialService credentialService;
|
||||||
private final FromJsonHelper fromJsonHelper;
|
|
||||||
private final Gson gson = new GsonBuilder().serializeNulls().create();
|
private final Gson gson = new GsonBuilder().serializeNulls().create();
|
||||||
|
|
||||||
|
/** Disabled -- see the class comment. Minting a key is a direct-database operation only. */
|
||||||
@POST
|
@POST
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public String create(final String body) {
|
public String create(final String body) {
|
||||||
final AppUser user = requireSuperUser();
|
requireSuperUser();
|
||||||
final JsonElement root = fromJsonHelper.parse(body);
|
throw new WebApplicationException(Response.status(403)
|
||||||
final String clientName = fromJsonHelper.extractStringNamed("clientName", root);
|
.entity("{\"message\":\"Minting a new platform API key over HTTP is disabled. "
|
||||||
final String allowedIps = fromJsonHelper.extractStringNamed("allowedIps", root);
|
+ "Insert directly into m_api_client in the tenant-store database instead.\"}")
|
||||||
|
.type(MediaType.APPLICATION_JSON).build());
|
||||||
final Map<String, Object> result = credentialService.createClient(clientName, allowedIps, user.getId());
|
|
||||||
return gson.toJson(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
|
|||||||
+5
@@ -130,8 +130,13 @@ public class TellerManagementReadPlatformServiceImpl implements TellerManagement
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<TellerData> getTellers(Long officeId) {
|
public Collection<TellerData> getTellers(Long officeId) {
|
||||||
|
if (officeId == null) {
|
||||||
return retrieveAllTellers(false);
|
return retrieveAllTellers(false);
|
||||||
}
|
}
|
||||||
|
// The tellers of that one branch. The officeId used to be ignored, so the head office, whose
|
||||||
|
// hierarchy covers every branch, counted each branch's vault and cashiers as its own at day close.
|
||||||
|
return retrieveAllTellers(false).stream().filter(t -> officeId.equals(t.getOfficeId())).toList();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<CashierData> getCashiersForTeller(Long tellerId, LocalDate fromDate, LocalDate toDate) {
|
public Collection<CashierData> getCashiersForTeller(Long tellerId, LocalDate fromDate, LocalDate toDate) {
|
||||||
|
|||||||
+6
-4
@@ -70,10 +70,6 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer
|
|||||||
try {
|
try {
|
||||||
this.context.authenticatedUser();
|
this.context.authenticatedUser();
|
||||||
|
|
||||||
if (this.tellerRepositoryWrapper.existsAny()) {
|
|
||||||
throw new TellerAlreadyExistsException();
|
|
||||||
}
|
|
||||||
|
|
||||||
final Long officeId = command.longValueOfParameterNamed("officeId");
|
final Long officeId = command.longValueOfParameterNamed("officeId");
|
||||||
|
|
||||||
this.fromApiJsonDeserializer.validateForCreateAndUpdateTeller(command.json());
|
this.fromApiJsonDeserializer.validateForCreateAndUpdateTeller(command.json());
|
||||||
@@ -81,6 +77,12 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer
|
|||||||
// final Office parent =
|
// final Office parent =
|
||||||
// validateUserPriviledgeOnOfficeAndRetrieve(currentUser, officeId);
|
// validateUserPriviledgeOnOfficeAndRetrieve(currentUser, officeId);
|
||||||
final Office tellerOffice = this.officeRepositoryWrapper.findOneWithNotFoundDetection(officeId);
|
final Office tellerOffice = this.officeRepositoryWrapper.findOneWithNotFoundDetection(officeId);
|
||||||
|
|
||||||
|
// One teller (vault) per branch, not one for the whole bank: each branch holds and settles
|
||||||
|
// its own cash, so a second branch needs a vault of its own.
|
||||||
|
if (this.tellerRepositoryWrapper.existsInOffice(officeId)) {
|
||||||
|
throw new TellerAlreadyExistsException(tellerOffice.getName());
|
||||||
|
}
|
||||||
final Teller teller = Teller.fromJson(tellerOffice, command);
|
final Teller teller = Teller.fromJson(tellerOffice, command);
|
||||||
|
|
||||||
// pre save to generate id for use in office hierarchy
|
// pre save to generate id for use in office hierarchy
|
||||||
|
|||||||
+12
-15
@@ -27,15 +27,15 @@ import jakarta.ws.rs.PUT;
|
|||||||
import jakarta.ws.rs.Path;
|
import jakarta.ws.rs.Path;
|
||||||
import jakarta.ws.rs.Produces;
|
import jakarta.ws.rs.Produces;
|
||||||
import jakarta.ws.rs.core.MediaType;
|
import jakarta.ws.rs.core.MediaType;
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.fineract.command.core.CommandPipeline;
|
import org.apache.fineract.commands.domain.CommandWrapper;
|
||||||
import org.apache.fineract.organisation.workingdays.command.WorkingDaysUpdateCommand;
|
import org.apache.fineract.commands.service.CommandWrapperBuilder;
|
||||||
|
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||||
|
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||||
import org.apache.fineract.organisation.workingdays.data.WorkingDaysData;
|
import org.apache.fineract.organisation.workingdays.data.WorkingDaysData;
|
||||||
import org.apache.fineract.organisation.workingdays.data.WorkingDaysUpdateRequest;
|
import org.apache.fineract.organisation.workingdays.data.WorkingDaysUpdateRequest;
|
||||||
import org.apache.fineract.organisation.workingdays.data.WorkingDaysUpdateRequestValidator;
|
import org.apache.fineract.organisation.workingdays.data.WorkingDaysUpdateRequestValidator;
|
||||||
import org.apache.fineract.organisation.workingdays.data.WorkingDaysUpdateResponse;
|
|
||||||
import org.apache.fineract.organisation.workingdays.service.WorkingDaysReadPlatformService;
|
import org.apache.fineract.organisation.workingdays.service.WorkingDaysReadPlatformService;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -50,7 +50,8 @@ public class WorkingDaysApiResource {
|
|||||||
|
|
||||||
private final WorkingDaysReadPlatformService workingDaysReadPlatformService;
|
private final WorkingDaysReadPlatformService workingDaysReadPlatformService;
|
||||||
private final WorkingDaysUpdateRequestValidator workingDaysUpdateRequestValidator;
|
private final WorkingDaysUpdateRequestValidator workingDaysUpdateRequestValidator;
|
||||||
private final CommandPipeline commandPipeline;
|
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||||
|
private final DefaultToApiJsonSerializer<WorkingDaysUpdateRequest> toApiJsonSerializer;
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@@ -65,17 +66,13 @@ public class WorkingDaysApiResource {
|
|||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
@Operation(summary = "Update a Working Day", description = "Mandatory Fields\n"
|
@Operation(summary = "Update a Working Day", description = "Mandatory Fields\n"
|
||||||
+ "recurrence,repaymentRescheduleType,extendTermForDailyRepayments,locale")
|
+ "recurrence,repaymentRescheduleType,extendTermForDailyRepayments,locale")
|
||||||
public WorkingDaysUpdateResponse update(@Valid WorkingDaysUpdateRequest request) {
|
public String update(@Valid final WorkingDaysUpdateRequest request) {
|
||||||
|
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateWorkingDays()
|
||||||
|
.withJson(toApiJsonSerializer.serialize(request)).build();
|
||||||
|
|
||||||
final var command = new WorkingDaysUpdateCommand();
|
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||||
|
|
||||||
command.setCommandId(System.currentTimeMillis());
|
return toApiJsonSerializer.serialize(result);
|
||||||
command.setCreatedAt(Instant.now());
|
|
||||||
command.setPayload(request);
|
|
||||||
|
|
||||||
final Supplier<WorkingDaysUpdateResponse> response = commandPipeline.send(command);
|
|
||||||
|
|
||||||
return response.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
|
|||||||
+29
-21
@@ -18,38 +18,46 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.fineract.organisation.workingdays.handler;
|
package org.apache.fineract.organisation.workingdays.handler;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import lombok.RequiredArgsConstructor;
|
import org.apache.fineract.commands.annotation.CommandType;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
|
||||||
import org.apache.fineract.command.core.Command;
|
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
||||||
import org.apache.fineract.command.core.CommandHandler;
|
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
|
||||||
import org.apache.fineract.organisation.workingdays.data.WorkingDaysUpdateRequest;
|
import org.apache.fineract.organisation.workingdays.data.WorkingDaysUpdateRequest;
|
||||||
import org.apache.fineract.organisation.workingdays.data.WorkingDaysUpdateResponse;
|
|
||||||
import org.apache.fineract.organisation.workingdays.service.WorkingDaysWritePlatformService;
|
import org.apache.fineract.organisation.workingdays.service.WorkingDaysWritePlatformService;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@Slf4j
|
@Service
|
||||||
@Component
|
@CommandType(entity = "WORKINGDAYS", action = "UPDATE")
|
||||||
@RequiredArgsConstructor
|
public class UpdateWorkingDaysCommandHandler implements NewCommandSourceHandler {
|
||||||
public class UpdateWorkingDaysCommandHandler implements CommandHandler<WorkingDaysUpdateRequest, WorkingDaysUpdateResponse> {
|
|
||||||
|
|
||||||
private final WorkingDaysWritePlatformService workingDaysWritePlatformService;
|
private final WorkingDaysWritePlatformService workingDaysWritePlatformService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public UpdateWorkingDaysCommandHandler(final WorkingDaysWritePlatformService workingDaysWritePlatformService) {
|
||||||
|
this.workingDaysWritePlatformService = workingDaysWritePlatformService;
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public WorkingDaysUpdateResponse handle(Command<WorkingDaysUpdateRequest> command) {
|
public CommandProcessingResult processCommand(final JsonCommand command) {
|
||||||
WorkingDaysUpdateRequest request = command.getPayload();
|
|
||||||
Map<String, Object> changes = this.workingDaysWritePlatformService.updateWorkingDays(request);
|
|
||||||
if (changes == null) {
|
|
||||||
changes = Collections.emptyMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
return WorkingDaysUpdateResponse.builder().resourceId((Long) changes.get("resourceId")).changes(changes)
|
final WorkingDaysUpdateRequest request = WorkingDaysUpdateRequest.builder()
|
||||||
.recurrence(request.getRecurrence()).repaymentRescheduleType(request.getRepaymentRescheduleType())
|
.recurrence(command.stringValueOfParameterNamed("recurrence"))
|
||||||
.extendTermForDailyRepayments(request.getExtendTermForDailyRepayments())
|
.repaymentRescheduleType(command.integerValueSansLocaleOfParameterNamed("repaymentRescheduleType"))
|
||||||
.extendTermForRepaymentsOnHolidays(request.getExtendTermForRepaymentsOnHolidays()).build();
|
.extendTermForDailyRepayments(command.booleanObjectValueOfParameterNamed("extendTermForDailyRepayments"))
|
||||||
|
.extendTermForRepaymentsOnHolidays(command.booleanObjectValueOfParameterNamed("extendTermForRepaymentsOnHolidays"))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
final Map<String, Object> changes = this.workingDaysWritePlatformService.updateWorkingDays(request);
|
||||||
|
|
||||||
|
return new CommandProcessingResultBuilder() //
|
||||||
|
.withCommandId(command.commandId()) //
|
||||||
|
.with(changes) //
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+152
@@ -0,0 +1,152 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.portfolio.account.service;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.UUID;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
|
||||||
|
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
||||||
|
import org.apache.fineract.portfolio.client.service.KycRestrictionGuard;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.jdbc.support.GeneratedKeyHolder;
|
||||||
|
import org.springframework.jdbc.support.KeyHolder;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A book debit: money leaves a savings or current account by book entry, not as cash.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Posts NO journal entry. The caller posts the one entry that describes the real movement (a DD, a collection...).
|
||||||
|
* Debiting through a cash withdrawal instead made the withdrawal post its own Dr control / Cr Cash-at-Vault entry --
|
||||||
|
* cash that never moved -- which callers then hid by flagging it reversed, leaving an entry in the ledger that no
|
||||||
|
* report shows.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* It keeps the rules a withdrawal applies: the account must be active, the amount must fit in the available balance
|
||||||
|
* (balance less funds on hold), and a dormant account or a lapsed re-KYC stops the debit. Joins the caller's
|
||||||
|
* transaction, so a later failure rolls the debit back with everything else.
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class AccountBookDebitService {
|
||||||
|
|
||||||
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
private final KycRestrictionGuard kycRestrictionGuard;
|
||||||
|
|
||||||
|
/** Debits a savings account; returns the m_savings_account_transaction id. */
|
||||||
|
public long debitSavings(final Long accountId, final BigDecimal amount, final Long officeId, final LocalDate txnDate,
|
||||||
|
final Long userId) {
|
||||||
|
final BigDecimal balance = checkedBalance("m_savings_account", "Savings", accountId, amount);
|
||||||
|
kycRestrictionGuard.check(accountId, KycRestrictionGuard.Operation.DEBIT);
|
||||||
|
|
||||||
|
final java.sql.Date sqlDate = java.sql.Date.valueOf(txnDate);
|
||||||
|
final OffsetDateTime now = OffsetDateTime.now(DateUtils.getDateTimeZoneOfTenant());
|
||||||
|
final KeyHolder kh = new GeneratedKeyHolder();
|
||||||
|
jdbcTemplate.update(con -> {
|
||||||
|
final PreparedStatement ps = con.prepareStatement("INSERT INTO m_savings_account_transaction "
|
||||||
|
+ "(savings_account_id, office_id, payment_detail_id, transaction_type_enum, is_reversed, transaction_date, amount, "
|
||||||
|
+ "submitted_on_date, ref_no, running_balance_derived, is_lien_transaction, created_by, last_modified_by, "
|
||||||
|
+ "created_on_utc, last_modified_on_utc) VALUES (?, ?, NULL, 2, false, ?, ?, ?, ?, ?, false, ?, ?, ?, ?)",
|
||||||
|
new String[] { "id" });
|
||||||
|
ps.setLong(1, accountId);
|
||||||
|
ps.setLong(2, officeId);
|
||||||
|
ps.setDate(3, sqlDate);
|
||||||
|
ps.setBigDecimal(4, amount);
|
||||||
|
ps.setDate(5, sqlDate);
|
||||||
|
ps.setString(6, refNo());
|
||||||
|
ps.setBigDecimal(7, balance.subtract(amount));
|
||||||
|
ps.setLong(8, userId);
|
||||||
|
ps.setLong(9, userId);
|
||||||
|
ps.setObject(10, now);
|
||||||
|
ps.setObject(11, now);
|
||||||
|
return ps;
|
||||||
|
}, kh);
|
||||||
|
jdbcTemplate.update("UPDATE m_savings_account SET account_balance_derived = account_balance_derived - ?, "
|
||||||
|
+ "total_withdrawals_derived = COALESCE(total_withdrawals_derived, 0) + ? WHERE id = ?", amount, amount, accountId);
|
||||||
|
return Objects.requireNonNull(kh.getKey()).longValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Debits a current account; returns the m_current_account_transaction id. */
|
||||||
|
public long debitCurrent(final Long accountId, final BigDecimal amount, final Long officeId, final LocalDate txnDate,
|
||||||
|
final Long userId, final String note) {
|
||||||
|
final BigDecimal balance = checkedBalance("m_current_account", "Current", accountId, amount);
|
||||||
|
kycRestrictionGuard.checkCurrentAccount(accountId, KycRestrictionGuard.Operation.DEBIT);
|
||||||
|
|
||||||
|
final java.sql.Date sqlDate = java.sql.Date.valueOf(txnDate);
|
||||||
|
final String remarks = note == null || note.isBlank() ? "Book debit" : (note.length() > 490 ? note.substring(0, 490) : note);
|
||||||
|
final KeyHolder kh = new GeneratedKeyHolder();
|
||||||
|
jdbcTemplate.update(con -> {
|
||||||
|
final PreparedStatement ps = con.prepareStatement("INSERT INTO m_current_account_transaction "
|
||||||
|
+ "(current_account_id, office_id, transaction_type_enum, transaction_date, amount, is_reversed, is_reversal, "
|
||||||
|
+ "is_manual, is_lien_transaction, ref_no, submitted_on_date, running_balance_derived, remarks, created_date, created_by) "
|
||||||
|
+ "VALUES (?, ?, 2, ?, ?, false, false, false, false, ?, ?, ?, ?, CURRENT_TIMESTAMP, ?)", new String[] { "id" });
|
||||||
|
ps.setLong(1, accountId);
|
||||||
|
ps.setLong(2, officeId);
|
||||||
|
ps.setDate(3, sqlDate);
|
||||||
|
ps.setBigDecimal(4, amount);
|
||||||
|
ps.setString(5, refNo());
|
||||||
|
ps.setDate(6, sqlDate);
|
||||||
|
ps.setBigDecimal(7, balance.subtract(amount));
|
||||||
|
ps.setString(8, remarks);
|
||||||
|
ps.setLong(9, userId);
|
||||||
|
return ps;
|
||||||
|
}, kh);
|
||||||
|
jdbcTemplate.update("UPDATE m_current_account SET account_balance_derived = account_balance_derived - ?, "
|
||||||
|
+ "total_withdrawals_derived = COALESCE(total_withdrawals_derived, 0) + ? WHERE id = ?", amount, amount, accountId);
|
||||||
|
return Objects.requireNonNull(kh.getKey()).longValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The account's balance, after checking it is active and can cover {@code amount} from what is not on hold. */
|
||||||
|
private BigDecimal checkedBalance(final String table, final String kind, final Long accountId, final BigDecimal amount) {
|
||||||
|
final List<Map<String, Object>> rows = jdbcTemplate.queryForList(
|
||||||
|
"SELECT status_enum, account_balance_derived, on_hold_funds_derived FROM " + table + " WHERE id = ?", accountId);
|
||||||
|
if (rows.isEmpty()) {
|
||||||
|
throw new GeneralPlatformDomainRuleException("error.msg.account.not.found", kind + " account " + accountId + " not found.",
|
||||||
|
accountId);
|
||||||
|
}
|
||||||
|
final int status = ((Number) rows.get(0).get("status_enum")).intValue();
|
||||||
|
if (status != 300) {
|
||||||
|
throw new GeneralPlatformDomainRuleException("error.msg.account.not.active",
|
||||||
|
kind + " account " + accountId + " is not active.", accountId);
|
||||||
|
}
|
||||||
|
final BigDecimal balance = rows.get(0).get("account_balance_derived") == null ? BigDecimal.ZERO
|
||||||
|
: (BigDecimal) rows.get(0).get("account_balance_derived");
|
||||||
|
final BigDecimal onHold = rows.get(0).get("on_hold_funds_derived") == null ? BigDecimal.ZERO
|
||||||
|
: (BigDecimal) rows.get(0).get("on_hold_funds_derived");
|
||||||
|
final BigDecimal available = balance.subtract(onHold);
|
||||||
|
if (available.compareTo(amount) < 0) {
|
||||||
|
throw new GeneralPlatformDomainRuleException("error.msg.account.insufficient.balance",
|
||||||
|
"Insufficient available balance in " + kind.toLowerCase() + " account " + accountId + ". Available: " + available
|
||||||
|
+ ", Requested: " + amount,
|
||||||
|
accountId);
|
||||||
|
}
|
||||||
|
return balance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String refNo() {
|
||||||
|
return UUID.randomUUID().toString().replace("-", "").substring(0, 20);
|
||||||
|
}
|
||||||
|
}
|
||||||
+60
-21
@@ -27,6 +27,7 @@ import static org.apache.fineract.portfolio.account.api.AccountTransfersApiConst
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.math.MathContext;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -44,6 +45,7 @@ import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
|||||||
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
|
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
|
||||||
import org.apache.fineract.infrastructure.core.domain.ExternalId;
|
import org.apache.fineract.infrastructure.core.domain.ExternalId;
|
||||||
import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
|
import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
|
||||||
|
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
||||||
import org.apache.fineract.infrastructure.core.service.ExternalIdFactory;
|
import org.apache.fineract.infrastructure.core.service.ExternalIdFactory;
|
||||||
import org.apache.fineract.organisation.monetary.domain.Money;
|
import org.apache.fineract.organisation.monetary.domain.Money;
|
||||||
import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
|
import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
|
||||||
@@ -57,6 +59,7 @@ import org.apache.fineract.portfolio.account.domain.AccountTransferRepository;
|
|||||||
import org.apache.fineract.portfolio.account.domain.AccountTransferTransaction;
|
import org.apache.fineract.portfolio.account.domain.AccountTransferTransaction;
|
||||||
import org.apache.fineract.portfolio.account.domain.AccountTransferType;
|
import org.apache.fineract.portfolio.account.domain.AccountTransferType;
|
||||||
import org.apache.fineract.portfolio.account.exception.DifferentCurrenciesException;
|
import org.apache.fineract.portfolio.account.exception.DifferentCurrenciesException;
|
||||||
|
import org.apache.fineract.portfolio.client.service.KycRestrictionGuard;
|
||||||
import org.apache.fineract.portfolio.currentaccount.domain.CurrentAccount;
|
import org.apache.fineract.portfolio.currentaccount.domain.CurrentAccount;
|
||||||
import org.apache.fineract.portfolio.currentaccount.domain.CurrentAccountRepository;
|
import org.apache.fineract.portfolio.currentaccount.domain.CurrentAccountRepository;
|
||||||
import org.apache.fineract.portfolio.currentaccount.domain.CurrentAccountTransaction;
|
import org.apache.fineract.portfolio.currentaccount.domain.CurrentAccountTransaction;
|
||||||
@@ -73,11 +76,13 @@ import org.apache.fineract.portfolio.paymentdetail.domain.PaymentDetail;
|
|||||||
import org.apache.fineract.portfolio.savings.SavingsTransactionBooleanValues;
|
import org.apache.fineract.portfolio.savings.SavingsTransactionBooleanValues;
|
||||||
import org.apache.fineract.portfolio.savings.domain.GSIMRepositoy;
|
import org.apache.fineract.portfolio.savings.domain.GSIMRepositoy;
|
||||||
import org.apache.fineract.portfolio.savings.domain.GroupSavingsIndividualMonitoring;
|
import org.apache.fineract.portfolio.savings.domain.GroupSavingsIndividualMonitoring;
|
||||||
|
import org.apache.fineract.portfolio.savings.domain.RecurringDepositAccount;
|
||||||
import org.apache.fineract.portfolio.savings.domain.SavingsAccount;
|
import org.apache.fineract.portfolio.savings.domain.SavingsAccount;
|
||||||
import org.apache.fineract.portfolio.savings.domain.SavingsAccountAssembler;
|
import org.apache.fineract.portfolio.savings.domain.SavingsAccountAssembler;
|
||||||
import org.apache.fineract.portfolio.savings.domain.SavingsAccountTransaction;
|
import org.apache.fineract.portfolio.savings.domain.SavingsAccountTransaction;
|
||||||
import org.apache.fineract.portfolio.savings.service.SavingsAccountDomainService;
|
import org.apache.fineract.portfolio.savings.service.SavingsAccountDomainService;
|
||||||
import org.apache.fineract.portfolio.savings.service.SavingsAccountWritePlatformService;
|
import org.apache.fineract.portfolio.savings.service.SavingsAccountWritePlatformService;
|
||||||
|
import org.apache.fineract.portfolio.tds.service.SavingsInterestTdsService;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@@ -100,6 +105,8 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
|
|||||||
private final CurrentAccountRepository currentAccountRepository;
|
private final CurrentAccountRepository currentAccountRepository;
|
||||||
private final CurrentAccountTransactionRepository currentAccountTransactionRepository;
|
private final CurrentAccountTransactionRepository currentAccountTransactionRepository;
|
||||||
private final AccountingProcessorHelper accountingProcessorHelper;
|
private final AccountingProcessorHelper accountingProcessorHelper;
|
||||||
|
private final KycRestrictionGuard kycRestrictionGuard;
|
||||||
|
private final SavingsInterestTdsService savingsInterestTdsService;
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
@@ -145,6 +152,7 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
|
|||||||
|
|
||||||
final SavingsAccountTransaction deposit = this.savingsAccountDomainService.handleDeposit(toSavingsAccount, fmt, transactionDate,
|
final SavingsAccountTransaction deposit = this.savingsAccountDomainService.handleDeposit(toSavingsAccount, fmt, transactionDate,
|
||||||
transactionAmount, paymentDetail, isAccountTransfer, isRegularTransaction, backdatedTxnsAllowedTill);
|
transactionAmount, paymentDetail, isAccountTransfer, isRegularTransaction, backdatedTxnsAllowedTill);
|
||||||
|
applyToRecurringDepositSchedule(toSavingsAccount, deposit);
|
||||||
|
|
||||||
if (!fromSavingsAccount.getCurrency().getCode().equals(toSavingsAccount.getCurrency().getCode())) {
|
if (!fromSavingsAccount.getCurrency().getCode().equals(toSavingsAccount.getCurrency().getCode())) {
|
||||||
throw new DifferentCurrenciesException(fromSavingsAccount.getCurrency().getCode(),
|
throw new DifferentCurrenciesException(fromSavingsAccount.getCurrency().getCode(),
|
||||||
@@ -200,6 +208,7 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
|
|||||||
|
|
||||||
final SavingsAccountTransaction deposit = this.savingsAccountDomainService.handleDeposit(toSavingsAccount, fmt, transactionDate,
|
final SavingsAccountTransaction deposit = this.savingsAccountDomainService.handleDeposit(toSavingsAccount, fmt, transactionDate,
|
||||||
transactionAmount, paymentDetail, isAccountTransfer, isRegularTransaction, backdatedTxnsAllowedTill);
|
transactionAmount, paymentDetail, isAccountTransfer, isRegularTransaction, backdatedTxnsAllowedTill);
|
||||||
|
applyToRecurringDepositSchedule(toSavingsAccount, deposit);
|
||||||
|
|
||||||
final AccountTransferDetails accountTransferDetails = this.accountTransferAssembler.assembleLoanToSavingsTransfer(command,
|
final AccountTransferDetails accountTransferDetails = this.accountTransferAssembler.assembleLoanToSavingsTransfer(command,
|
||||||
fromLoanAccount, toSavingsAccount, deposit, loanRefundTransaction);
|
fromLoanAccount, toSavingsAccount, deposit, loanRefundTransaction);
|
||||||
@@ -405,11 +414,15 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
|
|||||||
final SavingsAccountTransaction deposit = this.savingsAccountDomainService.handleDeposit(toSavingsAccount,
|
final SavingsAccountTransaction deposit = this.savingsAccountDomainService.handleDeposit(toSavingsAccount,
|
||||||
accountTransferDTO.getFmt(), transactionDate, accountTransferDTO.getTransactionAmount(),
|
accountTransferDTO.getFmt(), transactionDate, accountTransferDTO.getTransactionAmount(),
|
||||||
accountTransferDTO.getPaymentDetail(), isAccountTransfer, isRegularTransaction, backdatedTxnsAllowedTill);
|
accountTransferDTO.getPaymentDetail(), isAccountTransfer, isRegularTransaction, backdatedTxnsAllowedTill);
|
||||||
|
applyToRecurringDepositSchedule(toSavingsAccount, deposit);
|
||||||
|
|
||||||
accountTransferDetails = this.accountTransferAssembler.assembleSavingsToSavingsTransfer(accountTransferDTO, fromSavingsAccount,
|
accountTransferDetails = this.accountTransferAssembler.assembleSavingsToSavingsTransfer(accountTransferDTO, fromSavingsAccount,
|
||||||
toSavingsAccount, withdrawal, deposit);
|
toSavingsAccount, withdrawal, deposit);
|
||||||
this.accountTransferDetailRepository.saveAndFlush(accountTransferDetails);
|
this.accountTransferDetailRepository.saveAndFlush(accountTransferDetails);
|
||||||
transferTransactionId = accountTransferDetails.getId();
|
transferTransactionId = accountTransferDetails.getId();
|
||||||
|
// FD/RD interest reaching a savings account is where TDS is tracked and, once due, deducted.
|
||||||
|
this.savingsInterestTdsService.onTransfer(fromSavingsAccount, toSavingsAccount, deposit,
|
||||||
|
AccountTransferType.fromInt(accountTransferDTO.getTransferType()));
|
||||||
|
|
||||||
} else if (isLoanToSavingsAccountTransfer(accountTransferDTO.getFromAccountType(), accountTransferDTO.getToAccountType())) {
|
} else if (isLoanToSavingsAccountTransfer(accountTransferDTO.getFromAccountType(), accountTransferDTO.getToAccountType())) {
|
||||||
|
|
||||||
@@ -447,6 +460,7 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
|
|||||||
final SavingsAccountTransaction deposit = this.savingsAccountDomainService.handleDeposit(toSavingsAccount,
|
final SavingsAccountTransaction deposit = this.savingsAccountDomainService.handleDeposit(toSavingsAccount,
|
||||||
accountTransferDTO.getFmt(), accountTransferDTO.getTransactionDate(), accountTransferDTO.getTransactionAmount(),
|
accountTransferDTO.getFmt(), accountTransferDTO.getTransactionDate(), accountTransferDTO.getTransactionAmount(),
|
||||||
accountTransferDTO.getPaymentDetail(), isAccountTransfer, isRegularTransaction, backdatedTxnsAllowedTill);
|
accountTransferDTO.getPaymentDetail(), isAccountTransfer, isRegularTransaction, backdatedTxnsAllowedTill);
|
||||||
|
applyToRecurringDepositSchedule(toSavingsAccount, deposit);
|
||||||
accountTransferDetails = this.accountTransferAssembler.assembleLoanToSavingsTransfer(accountTransferDTO, fromLoanAccount,
|
accountTransferDetails = this.accountTransferAssembler.assembleLoanToSavingsTransfer(accountTransferDTO, fromLoanAccount,
|
||||||
toSavingsAccount, deposit, loanTransaction);
|
toSavingsAccount, deposit, loanTransaction);
|
||||||
this.accountTransferDetailRepository.saveAndFlush(accountTransferDetails);
|
this.accountTransferDetailRepository.saveAndFlush(accountTransferDetails);
|
||||||
@@ -472,7 +486,7 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
|
|||||||
|
|
||||||
final CurrentAccountTransaction withdrawal = performCurrentWithdrawal(fromCurrentAccount,
|
final CurrentAccountTransaction withdrawal = performCurrentWithdrawal(fromCurrentAccount,
|
||||||
accountTransferDTO.getTransactionAmount(), accountTransferDTO.getTransactionDate(),
|
accountTransferDTO.getTransactionAmount(), accountTransferDTO.getTransactionDate(),
|
||||||
toSavingsAccount.productId(), toSavingsAccount.getId());
|
toSavingsAccount.productId(), false, toSavingsAccount.getId());
|
||||||
|
|
||||||
// skipAccountingPostings=true: current account withdrawal leg (C-txn) already posts
|
// skipAccountingPostings=true: current account withdrawal leg (C-txn) already posts
|
||||||
// DR CURRENT ACCOUNT / CR SAVING INDIVIDUAL directly — each with its own account number.
|
// DR CURRENT ACCOUNT / CR SAVING INDIVIDUAL directly — each with its own account number.
|
||||||
@@ -481,6 +495,7 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
|
|||||||
accountTransferDTO.getFmt(), accountTransferDTO.getTransactionDate(),
|
accountTransferDTO.getFmt(), accountTransferDTO.getTransactionDate(),
|
||||||
accountTransferDTO.getTransactionAmount(), accountTransferDTO.getPaymentDetail(),
|
accountTransferDTO.getTransactionAmount(), accountTransferDTO.getPaymentDetail(),
|
||||||
isAccountTransfer, isRegularTransaction, backdatedTxnsAllowedTill, true);
|
isAccountTransfer, isRegularTransaction, backdatedTxnsAllowedTill, true);
|
||||||
|
applyToRecurringDepositSchedule(toSavingsAccount, deposit);
|
||||||
|
|
||||||
if (accountTransferDetails == null) {
|
if (accountTransferDetails == null) {
|
||||||
accountTransferDetails = AccountTransferDetails.currentToSavingsTransfer(
|
accountTransferDetails = AccountTransferDetails.currentToSavingsTransfer(
|
||||||
@@ -517,7 +532,7 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
|
|||||||
|
|
||||||
performCurrentDeposit(toCurrentAccount, accountTransferDTO.getTransactionAmount(),
|
performCurrentDeposit(toCurrentAccount, accountTransferDTO.getTransactionAmount(),
|
||||||
accountTransferDTO.getTransactionDate(),
|
accountTransferDTO.getTransactionDate(),
|
||||||
fromSavingsAccount.productId(), fromSavingsAccount.getId());
|
fromSavingsAccount.productId(), false, fromSavingsAccount.getId());
|
||||||
|
|
||||||
if (accountTransferDetails == null) {
|
if (accountTransferDetails == null) {
|
||||||
accountTransferDetails = AccountTransferDetails.savingsToCurrentTransfer(
|
accountTransferDetails = AccountTransferDetails.savingsToCurrentTransfer(
|
||||||
@@ -545,10 +560,10 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
|
|||||||
|
|
||||||
performCurrentWithdrawal(fromCurrentAccount, accountTransferDTO.getTransactionAmount(),
|
performCurrentWithdrawal(fromCurrentAccount, accountTransferDTO.getTransactionAmount(),
|
||||||
accountTransferDTO.getTransactionDate(),
|
accountTransferDTO.getTransactionDate(),
|
||||||
toCurrentAccount.getProductId(), toCurrentAccount.getId());
|
toCurrentAccount.getProductId(), true, toCurrentAccount.getId());
|
||||||
performCurrentDeposit(toCurrentAccount, accountTransferDTO.getTransactionAmount(),
|
performCurrentDeposit(toCurrentAccount, accountTransferDTO.getTransactionAmount(),
|
||||||
accountTransferDTO.getTransactionDate(),
|
accountTransferDTO.getTransactionDate(),
|
||||||
fromCurrentAccount.getProductId(), fromCurrentAccount.getId());
|
fromCurrentAccount.getProductId(), true, fromCurrentAccount.getId());
|
||||||
|
|
||||||
if (accountTransferDetails == null) {
|
if (accountTransferDetails == null) {
|
||||||
accountTransferDetails = AccountTransferDetails.currentToCurrentTransfer(
|
accountTransferDetails = AccountTransferDetails.currentToCurrentTransfer(
|
||||||
@@ -642,6 +657,26 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
|
|||||||
return accountTransferDetails;
|
return accountTransferDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Money transferred into a recurring deposit is an installment payment, exactly like a counter deposit through
|
||||||
|
* DepositAccountDomainServiceJpa#handleRDDeposit. The generic deposit above only credits the balance, so without
|
||||||
|
* this the deposit's schedule kept showing the installment as unpaid and overdue, and its projected maturity
|
||||||
|
* amount never moved - for manual transfers, standing instructions and RD Auto Debit alike. Any other destination
|
||||||
|
* is left untouched.
|
||||||
|
*/
|
||||||
|
private void applyToRecurringDepositSchedule(final SavingsAccount toSavingsAccount, final SavingsAccountTransaction deposit) {
|
||||||
|
if (!(toSavingsAccount instanceof RecurringDepositAccount recurringDeposit)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final boolean isPreMatureClosure = false;
|
||||||
|
recurringDeposit.updateDepositAmount(deposit.getAmount());
|
||||||
|
recurringDeposit.handleScheduleInstallments(deposit);
|
||||||
|
recurringDeposit.updateMaturityDateAndAmount(MathContext.DECIMAL64, isPreMatureClosure,
|
||||||
|
this.configurationDomainService.isSavingsInterestPostingAtCurrentPeriodEnd(),
|
||||||
|
this.configurationDomainService.retrieveFinancialYearBeginningMonth());
|
||||||
|
recurringDeposit.updateOverduePayments(DateUtils.getBusinessLocalDate());
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isLoanToSavingsAccountTransfer(final PortfolioAccountType fromAccountType, final PortfolioAccountType toAccountType) {
|
private boolean isLoanToSavingsAccountTransfer(final PortfolioAccountType fromAccountType, final PortfolioAccountType toAccountType) {
|
||||||
return fromAccountType.isLoanAccount() && toAccountType.isSavingsAccount();
|
return fromAccountType.isLoanAccount() && toAccountType.isSavingsAccount();
|
||||||
}
|
}
|
||||||
@@ -681,6 +716,8 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
|
|||||||
*/
|
*/
|
||||||
private CurrentAccountTransaction performCurrentWithdrawalForLoan(final CurrentAccount account, final BigDecimal amount,
|
private CurrentAccountTransaction performCurrentWithdrawalForLoan(final CurrentAccount account, final BigDecimal amount,
|
||||||
final LocalDate txnDate) {
|
final LocalDate txnDate) {
|
||||||
|
// Money leaving a current account by transfer is refused on a dormant one, as a withdrawal is.
|
||||||
|
kycRestrictionGuard.checkCurrentAccount(account.getId(), KycRestrictionGuard.Operation.TRANSFER);
|
||||||
final BigDecimal balance = account.getAccountBalanceDerived() != null ? account.getAccountBalanceDerived() : BigDecimal.ZERO;
|
final BigDecimal balance = account.getAccountBalanceDerived() != null ? account.getAccountBalanceDerived() : BigDecimal.ZERO;
|
||||||
final BigDecimal onHold = account.getOnHoldFundsDerived() != null ? account.getOnHoldFundsDerived() : BigDecimal.ZERO;
|
final BigDecimal onHold = account.getOnHoldFundsDerived() != null ? account.getOnHoldFundsDerived() : BigDecimal.ZERO;
|
||||||
final BigDecimal available = balance.subtract(onHold);
|
final BigDecimal available = balance.subtract(onHold);
|
||||||
@@ -699,10 +736,9 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
|
|||||||
currentAccountRepository.save(account);
|
currentAccountRepository.save(account);
|
||||||
if (account.getProductId() != null && txn.getId() != null) {
|
if (account.getProductId() != null && txn.getId() != null) {
|
||||||
final String currentTxnId = "CA" + txn.getId();
|
final String currentTxnId = "CA" + txn.getId();
|
||||||
accountingProcessorHelper.createCashBasedJournalEntriesAndReversalsForSavings(account.getOffice(),
|
accountingProcessorHelper.createCurrentControlToFinancialActivityJournalEntries(account.getOffice(),
|
||||||
account.getCurrencyCode(), CashAccountsForSavings.SAVINGS_CONTROL.getValue(),
|
account.getCurrencyCode(), account.getProductId(), FinancialActivity.LIABILITY_TRANSFER.getValue(),
|
||||||
FinancialActivity.LIABILITY_TRANSFER.getValue(), account.getProductId(), null,
|
account.getId(), currentTxnId, txnDate, amount);
|
||||||
account.getId(), currentTxnId, txnDate, amount, false);
|
|
||||||
}
|
}
|
||||||
return txn;
|
return txn;
|
||||||
}
|
}
|
||||||
@@ -712,7 +748,9 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
|
|||||||
* Throws {@link GeneralPlatformDomainRuleException} if balance is insufficient.
|
* Throws {@link GeneralPlatformDomainRuleException} if balance is insufficient.
|
||||||
*/
|
*/
|
||||||
private CurrentAccountTransaction performCurrentWithdrawal(final CurrentAccount account, final BigDecimal amount,
|
private CurrentAccountTransaction performCurrentWithdrawal(final CurrentAccount account, final BigDecimal amount,
|
||||||
final LocalDate txnDate, final Long counterpartProductId, final Long counterpartEntityId) {
|
final LocalDate txnDate, final Long counterpartProductId, final boolean counterpartIsCurrent,
|
||||||
|
final Long counterpartEntityId) {
|
||||||
|
kycRestrictionGuard.checkCurrentAccount(account.getId(), KycRestrictionGuard.Operation.TRANSFER);
|
||||||
final BigDecimal balance = account.getAccountBalanceDerived() != null ? account.getAccountBalanceDerived() : BigDecimal.ZERO;
|
final BigDecimal balance = account.getAccountBalanceDerived() != null ? account.getAccountBalanceDerived() : BigDecimal.ZERO;
|
||||||
final BigDecimal onHold = account.getOnHoldFundsDerived() != null ? account.getOnHoldFundsDerived() : BigDecimal.ZERO;
|
final BigDecimal onHold = account.getOnHoldFundsDerived() != null ? account.getOnHoldFundsDerived() : BigDecimal.ZERO;
|
||||||
final BigDecimal available = balance.subtract(onHold);
|
final BigDecimal available = balance.subtract(onHold);
|
||||||
@@ -730,7 +768,8 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
|
|||||||
(account.getTotalWithdrawalsDerived() != null ? account.getTotalWithdrawalsDerived() : BigDecimal.ZERO).add(amount));
|
(account.getTotalWithdrawalsDerived() != null ? account.getTotalWithdrawalsDerived() : BigDecimal.ZERO).add(amount));
|
||||||
currentAccountRepository.save(account);
|
currentAccountRepository.save(account);
|
||||||
// Post journal entries: DR current account GL, CR counterpart GL — each with correct entity/account number
|
// Post journal entries: DR current account GL, CR counterpart GL — each with correct entity/account number
|
||||||
postCurrentAccountTransferJournalEntries(account, txn, amount, txnDate, true, counterpartProductId, counterpartEntityId);
|
postCurrentAccountTransferJournalEntries(account, txn, amount, txnDate, true, counterpartProductId, counterpartIsCurrent,
|
||||||
|
counterpartEntityId);
|
||||||
return txn;
|
return txn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -738,7 +777,9 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
|
|||||||
* Deposit amount into a current account and save the transaction.
|
* Deposit amount into a current account and save the transaction.
|
||||||
*/
|
*/
|
||||||
private CurrentAccountTransaction performCurrentDeposit(final CurrentAccount account, final BigDecimal amount,
|
private CurrentAccountTransaction performCurrentDeposit(final CurrentAccount account, final BigDecimal amount,
|
||||||
final LocalDate txnDate, final Long counterpartProductId, final Long counterpartEntityId) {
|
final LocalDate txnDate, final Long counterpartProductId, final boolean counterpartIsCurrent,
|
||||||
|
final Long counterpartEntityId) {
|
||||||
|
kycRestrictionGuard.checkCurrentAccount(account.getId(), KycRestrictionGuard.Operation.CREDIT);
|
||||||
final BigDecimal balance = account.getAccountBalanceDerived() != null ? account.getAccountBalanceDerived() : BigDecimal.ZERO;
|
final BigDecimal balance = account.getAccountBalanceDerived() != null ? account.getAccountBalanceDerived() : BigDecimal.ZERO;
|
||||||
final CurrentAccountTransaction txn = CurrentAccountTransaction.deposit(account, account.getOffice(), amount, txnDate, null);
|
final CurrentAccountTransaction txn = CurrentAccountTransaction.deposit(account, account.getOffice(), amount, txnDate, null);
|
||||||
final BigDecimal newBalance = balance.add(amount);
|
final BigDecimal newBalance = balance.add(amount);
|
||||||
@@ -749,7 +790,8 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
|
|||||||
(account.getTotalDepositsDerived() != null ? account.getTotalDepositsDerived() : BigDecimal.ZERO).add(amount));
|
(account.getTotalDepositsDerived() != null ? account.getTotalDepositsDerived() : BigDecimal.ZERO).add(amount));
|
||||||
currentAccountRepository.save(account);
|
currentAccountRepository.save(account);
|
||||||
// Post journal entries: DR counterpart GL, CR current account GL — each with correct entity/account number
|
// Post journal entries: DR counterpart GL, CR current account GL — each with correct entity/account number
|
||||||
postCurrentAccountTransferJournalEntries(account, txn, amount, txnDate, false, counterpartProductId, counterpartEntityId);
|
postCurrentAccountTransferJournalEntries(account, txn, amount, txnDate, false, counterpartProductId, counterpartIsCurrent,
|
||||||
|
counterpartEntityId);
|
||||||
return txn;
|
return txn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -783,7 +825,7 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
|
|||||||
*/
|
*/
|
||||||
private void postCurrentAccountTransferJournalEntries(final CurrentAccount account, final CurrentAccountTransaction txn,
|
private void postCurrentAccountTransferJournalEntries(final CurrentAccount account, final CurrentAccountTransaction txn,
|
||||||
final BigDecimal amount, final LocalDate txnDate, final boolean isWithdrawal,
|
final BigDecimal amount, final LocalDate txnDate, final boolean isWithdrawal,
|
||||||
final Long counterpartProductId, final Long counterpartEntityId) {
|
final Long counterpartProductId, final boolean counterpartIsCurrent, final Long counterpartEntityId) {
|
||||||
if (account.getProductId() == null || txn.getId() == null) {
|
if (account.getProductId() == null || txn.getId() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -794,17 +836,13 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
|
|||||||
final String currentTxnId = "CA" + txn.getId();
|
final String currentTxnId = "CA" + txn.getId();
|
||||||
if (isWithdrawal) {
|
if (isWithdrawal) {
|
||||||
// DR: current account GL CR: counterpart (savings/current) GL
|
// DR: current account GL CR: counterpart (savings/current) GL
|
||||||
accountingProcessorHelper.createDirectTransferJournalEntriesForSavings(
|
accountingProcessorHelper.createDirectTransferJournalEntries(account.getOffice(), account.getCurrencyCode(),
|
||||||
account.getOffice(), account.getCurrencyCode(),
|
account.getProductId(), true, account.getId(), counterpartProductId, counterpartIsCurrent, counterpartEntityId,
|
||||||
account.getProductId(), account.getId(),
|
|
||||||
counterpartProductId, counterpartEntityId,
|
|
||||||
currentTxnId, txnDate, amount);
|
currentTxnId, txnDate, amount);
|
||||||
} else {
|
} else {
|
||||||
// DR: counterpart (savings/current) GL CR: current account GL
|
// DR: counterpart (savings/current) GL CR: current account GL
|
||||||
accountingProcessorHelper.createDirectTransferJournalEntriesForSavings(
|
accountingProcessorHelper.createDirectTransferJournalEntries(account.getOffice(), account.getCurrencyCode(),
|
||||||
account.getOffice(), account.getCurrencyCode(),
|
counterpartProductId, counterpartIsCurrent, counterpartEntityId, account.getProductId(), true, account.getId(),
|
||||||
counterpartProductId, counterpartEntityId,
|
|
||||||
account.getProductId(), account.getId(),
|
|
||||||
currentTxnId, txnDate, amount);
|
currentTxnId, txnDate, amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -847,6 +885,7 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
|
|||||||
|
|
||||||
final SavingsAccountTransaction deposit = this.savingsAccountDomainService.handleDeposit(toSavingsAccount, fmt, transactionDate,
|
final SavingsAccountTransaction deposit = this.savingsAccountDomainService.handleDeposit(toSavingsAccount, fmt, transactionDate,
|
||||||
transactionAmount, paymentDetail, true, true, backdatedTxnsAllowedTill);
|
transactionAmount, paymentDetail, true, true, backdatedTxnsAllowedTill);
|
||||||
|
applyToRecurringDepositSchedule(toSavingsAccount, deposit);
|
||||||
|
|
||||||
final AccountTransferDetails accountTransferDetails = this.accountTransferAssembler.assembleLoanToSavingsTransfer(command,
|
final AccountTransferDetails accountTransferDetails = this.accountTransferAssembler.assembleLoanToSavingsTransfer(command,
|
||||||
fromLoanAccount, toSavingsAccount, deposit, loanRefundTransaction);
|
fromLoanAccount, toSavingsAccount, deposit, loanRefundTransaction);
|
||||||
|
|||||||
+6
-2
@@ -37,6 +37,7 @@ import org.apache.fineract.portfolio.account.domain.AccountTransferRepository;
|
|||||||
import org.apache.fineract.portfolio.account.domain.StandingInstructionAssembler;
|
import org.apache.fineract.portfolio.account.domain.StandingInstructionAssembler;
|
||||||
import org.apache.fineract.portfolio.account.domain.StandingInstructionRepository;
|
import org.apache.fineract.portfolio.account.domain.StandingInstructionRepository;
|
||||||
import org.apache.fineract.portfolio.account.mapper.AccountTransfersMapper;
|
import org.apache.fineract.portfolio.account.mapper.AccountTransfersMapper;
|
||||||
|
import org.apache.fineract.portfolio.client.service.KycRestrictionGuard;
|
||||||
import org.apache.fineract.portfolio.account.service.AccountAssociationsReadPlatformService;
|
import org.apache.fineract.portfolio.account.service.AccountAssociationsReadPlatformService;
|
||||||
import org.apache.fineract.portfolio.account.service.AccountAssociationsReadPlatformServiceImpl;
|
import org.apache.fineract.portfolio.account.service.AccountAssociationsReadPlatformServiceImpl;
|
||||||
import org.apache.fineract.portfolio.account.service.AccountTransfersReadPlatformService;
|
import org.apache.fineract.portfolio.account.service.AccountTransfersReadPlatformService;
|
||||||
@@ -60,6 +61,7 @@ import org.apache.fineract.portfolio.savings.domain.GSIMRepositoy;
|
|||||||
import org.apache.fineract.portfolio.savings.domain.SavingsAccountAssembler;
|
import org.apache.fineract.portfolio.savings.domain.SavingsAccountAssembler;
|
||||||
import org.apache.fineract.portfolio.savings.service.SavingsAccountDomainService;
|
import org.apache.fineract.portfolio.savings.service.SavingsAccountDomainService;
|
||||||
import org.apache.fineract.portfolio.savings.service.SavingsAccountWritePlatformService;
|
import org.apache.fineract.portfolio.savings.service.SavingsAccountWritePlatformService;
|
||||||
|
import org.apache.fineract.portfolio.tds.service.SavingsInterestTdsService;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -96,12 +98,14 @@ public class AccountConfiguration {
|
|||||||
GSIMRepositoy gsimRepository, ConfigurationDomainService configurationDomainService, ExternalIdFactory externalIdFactory,
|
GSIMRepositoy gsimRepository, ConfigurationDomainService configurationDomainService, ExternalIdFactory externalIdFactory,
|
||||||
FineractProperties fineractProperties, CurrentAccountRepository currentAccountRepository,
|
FineractProperties fineractProperties, CurrentAccountRepository currentAccountRepository,
|
||||||
CurrentAccountTransactionRepository currentAccountTransactionRepository,
|
CurrentAccountTransactionRepository currentAccountTransactionRepository,
|
||||||
AccountingProcessorHelper accountingProcessorHelper) {
|
AccountingProcessorHelper accountingProcessorHelper, KycRestrictionGuard kycRestrictionGuard,
|
||||||
|
SavingsInterestTdsService savingsInterestTdsService) {
|
||||||
return new AccountTransfersWritePlatformServiceImpl(accountTransfersDataValidator, accountTransferAssembler,
|
return new AccountTransfersWritePlatformServiceImpl(accountTransfersDataValidator, accountTransferAssembler,
|
||||||
accountTransferRepository, savingsAccountAssembler, savingsAccountDomainService, loanAccountAssembler,
|
accountTransferRepository, savingsAccountAssembler, savingsAccountDomainService, loanAccountAssembler,
|
||||||
loanAccountDomainService, savingsAccountWritePlatformService, accountTransferDetailRepository, loanReadPlatformService,
|
loanAccountDomainService, savingsAccountWritePlatformService, accountTransferDetailRepository, loanReadPlatformService,
|
||||||
gsimRepository, configurationDomainService, externalIdFactory, fineractProperties,
|
gsimRepository, configurationDomainService, externalIdFactory, fineractProperties,
|
||||||
currentAccountRepository, currentAccountTransactionRepository, accountingProcessorHelper);
|
currentAccountRepository, currentAccountTransactionRepository, accountingProcessorHelper, kycRestrictionGuard,
|
||||||
|
savingsInterestTdsService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|||||||
+3
-1
@@ -61,6 +61,8 @@ public interface ShareAccountApiConstants {
|
|||||||
String externalid_paramname = "externalId";
|
String externalid_paramname = "externalId";
|
||||||
|
|
||||||
String resolutionnumber_paramname = "resolutionNumber";
|
String resolutionnumber_paramname = "resolutionNumber";
|
||||||
|
/** Date of the board meeting that passed the resolution. */
|
||||||
|
String resolutiondate_paramname = "resolutionDate";
|
||||||
|
|
||||||
String currency_paramname = "currencyCode";
|
String currency_paramname = "currencyCode";
|
||||||
|
|
||||||
@@ -146,7 +148,7 @@ public interface ShareAccountApiConstants {
|
|||||||
|
|
||||||
Set<String> supportedParameters = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(locale_paramname, dateformat_paramname,
|
Set<String> supportedParameters = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(locale_paramname, dateformat_paramname,
|
||||||
id_paramname, clientid_paramname, productid_paramname, submitteddate_paramname, approveddate_paramname, externalid_paramname,
|
id_paramname, clientid_paramname, productid_paramname, submitteddate_paramname, approveddate_paramname, externalid_paramname,
|
||||||
resolutionnumber_paramname, currency_paramname, digitsafterdecimal_paramname, inmultiplesof_paramname,
|
resolutionnumber_paramname, resolutiondate_paramname, currency_paramname, digitsafterdecimal_paramname, inmultiplesof_paramname,
|
||||||
requestedshares_paramname, savingsaccountid_paramname, lockinperiod_paramname, lockperiodfrequencytype_paramname,
|
requestedshares_paramname, savingsaccountid_paramname, lockinperiod_paramname, lockperiodfrequencytype_paramname,
|
||||||
minimumactiveperiod_paramname, minimumactiveperiodfrequencytype_paramname,
|
minimumactiveperiod_paramname, minimumactiveperiodfrequencytype_paramname,
|
||||||
allowdividendcalculationforinactiveclients_paramname, charges_paramname, applicationdate_param, purchaseddate_paramname,
|
allowdividendcalculationforinactiveclients_paramname, charges_paramname, applicationdate_param, purchaseddate_paramname,
|
||||||
|
|||||||
+10
@@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.fineract.portfolio.aml.api;
|
package org.apache.fineract.portfolio.aml.api;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -30,4 +31,13 @@ public class AlertReviewRequest {
|
|||||||
|
|
||||||
private String disposition;
|
private String disposition;
|
||||||
private String notes;
|
private String notes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The rules being decided, when the officer is deciding some of them rather than the whole alert.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Absent or empty means the decision covers the transaction and every rule it matched, which is what the row-level
|
||||||
|
* Whitelist and Suspicious buttons send and what this endpoint has always done.
|
||||||
|
*/
|
||||||
|
private List<String> ruleCodes;
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-1
@@ -71,7 +71,13 @@ public class AmlAlertApiResource {
|
|||||||
description = "disposition WHITELIST closes the alert as a false positive; ESCALATE creates an STR case for Principal Officer review.")
|
description = "disposition WHITELIST closes the alert as a false positive; ESCALATE creates an STR case for Principal Officer review.")
|
||||||
public String review(@PathParam("alertId") final Long alertId, final AlertReviewRequest request) {
|
public String review(@PathParam("alertId") final Long alertId, final AlertReviewRequest request) {
|
||||||
this.context.authenticatedUser().validateHasPermissionTo("REVIEW_AML_ALERT");
|
this.context.authenticatedUser().validateHasPermissionTo("REVIEW_AML_ALERT");
|
||||||
if ("ESCALATE".equalsIgnoreCase(request.getDisposition())) {
|
final boolean escalating = "ESCALATE".equalsIgnoreCase(request.getDisposition());
|
||||||
|
if (request.getRuleCodes() != null && !request.getRuleCodes().isEmpty()) {
|
||||||
|
// Deciding named rules within the alert. The alert's own status follows from what is left undecided, so
|
||||||
|
// it is not set here.
|
||||||
|
this.writePlatformService.reviewRules(alertId, request.getRuleCodes(), escalating ? "ESCALATE" : "WHITELIST",
|
||||||
|
request.getNotes());
|
||||||
|
} else if (escalating) {
|
||||||
this.writePlatformService.escalate(alertId, request.getNotes());
|
this.writePlatformService.escalate(alertId, request.getNotes());
|
||||||
} else {
|
} else {
|
||||||
this.writePlatformService.whitelist(alertId, request.getNotes());
|
this.writePlatformService.whitelist(alertId, request.getNotes());
|
||||||
|
|||||||
+11
@@ -72,6 +72,17 @@ public class AmlCtrReportApiResource {
|
|||||||
return this.lineJsonSerializer.serialize(this.readPlatformService.retrieveLines(reportId));
|
return this.lineJsonSerializer.serialize(this.readPlatformService.retrieveLines(reportId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("pending-lines")
|
||||||
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
|
@Operation(summary = "Reportable cash transactions not yet in any generated CTR",
|
||||||
|
description = "The monthly batch is a snapshot, so a transaction posted after it ran belongs to that month's filing but sits in no report. These are those transactions, shaped as lines, so a reportable one is never invisible.")
|
||||||
|
public String retrievePendingLines() {
|
||||||
|
this.context.authenticatedUser();
|
||||||
|
return this.lineJsonSerializer.serialize(this.readPlatformService.retrievePendingLines());
|
||||||
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("generate")
|
@Path("generate")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
|
|||||||
+172
@@ -0,0 +1,172 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.portfolio.aml.api;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.ws.rs.Consumes;
|
||||||
|
import jakarta.ws.rs.GET;
|
||||||
|
import jakarta.ws.rs.POST;
|
||||||
|
import jakarta.ws.rs.Path;
|
||||||
|
import jakarta.ws.rs.PathParam;
|
||||||
|
import jakarta.ws.rs.Produces;
|
||||||
|
import jakarta.ws.rs.QueryParam;
|
||||||
|
import jakarta.ws.rs.WebApplicationException;
|
||||||
|
import jakarta.ws.rs.core.MediaType;
|
||||||
|
import jakarta.ws.rs.core.Response;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||||
|
import org.apache.fineract.portfolio.aml.service.ClientRiskChangeRequestService;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moving a customer's KYC risk category, under maker-checker.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Raised from the Risk Review Report, which already works out which customers are rated below what
|
||||||
|
* their behaviour warrants. The rating moves only when a checker approves, and the change is written
|
||||||
|
* into the customer's risk history with the reason given.
|
||||||
|
*/
|
||||||
|
@Path("/v1/aml/risk-change-requests")
|
||||||
|
@Component
|
||||||
|
@Tag(name = "Client Risk Category Change",
|
||||||
|
description = "Maker-checker changes to a customer's KYC risk category, raised from the Risk Review Report.")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ClientRiskChangeApiResource {
|
||||||
|
|
||||||
|
private final PlatformSecurityContext context;
|
||||||
|
private final ClientRiskChangeRequestService service;
|
||||||
|
private final Gson gson = new GsonBuilder().serializeNulls().create();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Business-rule failures in this module are plain IllegalArgument/IllegalState exceptions, which
|
||||||
|
* Fineract's global handler does not map - left uncaught they reach the client as an opaque 500
|
||||||
|
* with no message. Wrapped so the reviewer is told what actually stopped them.
|
||||||
|
*/
|
||||||
|
private <T> T safely(final Supplier<T> action) {
|
||||||
|
try {
|
||||||
|
return action.get();
|
||||||
|
} catch (final IllegalArgumentException | IllegalStateException e) {
|
||||||
|
throw apiError(400, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private WebApplicationException apiError(final int httpStatus, final String message) {
|
||||||
|
final JsonObject body = new JsonObject();
|
||||||
|
body.addProperty("message", message);
|
||||||
|
body.addProperty("defaultUserMessage", message);
|
||||||
|
body.addProperty("httpStatus", httpStatus);
|
||||||
|
final JsonArray errors = new JsonArray();
|
||||||
|
final JsonObject err = new JsonObject();
|
||||||
|
err.addProperty("defaultUserMessage", message);
|
||||||
|
errors.add(err);
|
||||||
|
body.add("errors", errors);
|
||||||
|
return new WebApplicationException(
|
||||||
|
Response.status(httpStatus).entity(this.gson.toJson(body)).type(MediaType.APPLICATION_JSON).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
|
@Operation(summary = "List risk category change requests",
|
||||||
|
description = "Optionally filtered by status (PENDING/APPROVED/REJECTED) for the approval queue.")
|
||||||
|
public String retrieveAll(@QueryParam("status") final String status) {
|
||||||
|
this.context.authenticatedUser();
|
||||||
|
return this.gson.toJson(this.service.retrieveAll(status));
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
|
@Operation(summary = "Request a change to a customer's risk category",
|
||||||
|
description = "Maker step. Nothing moves until a checker approves.")
|
||||||
|
public CommandProcessingResult request(final RiskChangeRequest request) {
|
||||||
|
return safely(() -> this.service.request(request.getClientId(), request.getRequestedCategory(), request.getReason()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("{requestId}/approve")
|
||||||
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
|
@Operation(summary = "Approve a risk category change",
|
||||||
|
description = "Checker step: applies the new category to the customer's KYC record, moves the re-KYC due date onto that category's cycle, and writes the change into the risk history.")
|
||||||
|
public CommandProcessingResult approve(@PathParam("requestId") final Long requestId) {
|
||||||
|
return safely(() -> this.service.approve(requestId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("{requestId}/reject")
|
||||||
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
|
@Operation(summary = "Reject a risk category change", description = "Checker step. The customer's rating is left as it is.")
|
||||||
|
public CommandProcessingResult reject(@PathParam("requestId") final Long requestId, final RiskChangeRejectRequest request) {
|
||||||
|
return safely(() -> this.service.reject(requestId, request.getRejectionReason()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Request bodies. Plain beans so Jackson binds them without a serializer of their own. */
|
||||||
|
public static final class RiskChangeRequest {
|
||||||
|
|
||||||
|
private Long clientId;
|
||||||
|
private Integer requestedCategory;
|
||||||
|
private String reason;
|
||||||
|
|
||||||
|
public Long getClientId() {
|
||||||
|
return clientId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClientId(Long clientId) {
|
||||||
|
this.clientId = clientId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getRequestedCategory() {
|
||||||
|
return requestedCategory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRequestedCategory(Integer requestedCategory) {
|
||||||
|
this.requestedCategory = requestedCategory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getReason() {
|
||||||
|
return reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReason(String reason) {
|
||||||
|
this.reason = reason;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class RiskChangeRejectRequest {
|
||||||
|
|
||||||
|
private String rejectionReason;
|
||||||
|
|
||||||
|
public String getRejectionReason() {
|
||||||
|
return rejectionReason;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRejectionReason(String rejectionReason) {
|
||||||
|
this.rejectionReason = rejectionReason;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
-1
@@ -30,6 +30,16 @@ import java.time.LocalDateTime;
|
|||||||
*/
|
*/
|
||||||
public record AmlAlertData(Long id, String transactionType, Long transactionId, Long clientId, String clientDisplayName,
|
public record AmlAlertData(Long id, String transactionType, Long transactionId, Long clientId, String clientDisplayName,
|
||||||
String ruleCode, String ruleDescription, BigDecimal amount, String currencyCode, LocalDateTime raisedOn, String status,
|
String ruleCode, String ruleDescription, BigDecimal amount, String currencyCode, LocalDateTime raisedOn, String status,
|
||||||
String reviewedByUsername, LocalDateTime reviewedOn, String reviewNotes, String disposition, Integer riskCategory)
|
String reviewedByUsername, LocalDateTime reviewedOn, String reviewNotes, String disposition, Integer riskCategory,
|
||||||
|
/** Other rules the same transaction matched, comma-separated. Null when only one fired. */
|
||||||
|
String alsoMatchedRules,
|
||||||
|
/** Worst severity across every rule the transaction matched, not only the governing one. */
|
||||||
|
Integer highestSeverity,
|
||||||
|
/**
|
||||||
|
* Every rule the transaction matched, governing one first, each with its description and severity. The
|
||||||
|
* comma-separated {@code alsoMatchedRules} is kept for what already reads it; this is what the screen expands
|
||||||
|
* to show, because a bare rule code does not tell an officer what was detected or how serious it is.
|
||||||
|
*/
|
||||||
|
java.util.List<AmlMatchedRuleData> matchedRules)
|
||||||
implements Serializable {
|
implements Serializable {
|
||||||
}
|
}
|
||||||
|
|||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.portfolio.aml.data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One rule a transaction matched, as the alert screen needs to show it.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* An alert names only the rule it was raised under; the rest were a comma-separated list of codes and nothing more. An
|
||||||
|
* officer deciding what to do with a transaction has to know what each of those codes means and how serious it is -
|
||||||
|
* "NEW_ACCOUNT_HIGH_VALUE_TXN" says nothing on its own, and whether it is Medium or High changes the decision.
|
||||||
|
*
|
||||||
|
* @param governing
|
||||||
|
* whether this is the rule the alert was raised under. One transaction raises one alert, under whichever
|
||||||
|
* rule most warrants attention, so exactly one entry in the list carries this.
|
||||||
|
* @param riskCategory
|
||||||
|
* 1 Low, 2 Medium, 3 High. Null for a rule with no catalog ancestor - the CTR rules are statutory returns
|
||||||
|
* rather than graded suspicions, so they carry no band.
|
||||||
|
*/
|
||||||
|
public record AmlMatchedRuleData(String ruleCode, String ruleDescription, Integer riskCategory, boolean governing,
|
||||||
|
/** WHITELIST, ESCALATE, or null while this rule is still open. */
|
||||||
|
String disposition, String reviewedByUsername, String reviewNotes,
|
||||||
|
/** True where the officer named this rule; false where it was closed alongside one they named. */
|
||||||
|
boolean directlyDecided) implements Serializable {
|
||||||
|
}
|
||||||
+125
-8
@@ -18,15 +18,25 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.fineract.portfolio.aml.service;
|
package org.apache.fineract.portfolio.aml.service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.fineract.portfolio.aml.data.AmlAlertData;
|
import org.apache.fineract.portfolio.aml.data.AmlAlertData;
|
||||||
|
import org.apache.fineract.portfolio.aml.data.AmlMatchedRuleData;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlAlert;
|
import org.apache.fineract.portfolio.aml.domain.AmlAlert;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlAlertRepository;
|
import org.apache.fineract.portfolio.aml.domain.AmlAlertRepository;
|
||||||
|
import org.apache.fineract.portfolio.aml.domain.AmlAlertRule;
|
||||||
|
import org.apache.fineract.portfolio.aml.domain.AmlAlertRuleRepository;
|
||||||
|
import org.apache.fineract.portfolio.aml.domain.AmlTransactionRule;
|
||||||
|
import org.apache.fineract.portfolio.aml.domain.AmlTransactionRuleRepository;
|
||||||
import org.apache.fineract.portfolio.client.domain.ClientRiskRuleRepository;
|
import org.apache.fineract.portfolio.client.domain.ClientRiskRuleRepository;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@@ -38,22 +48,127 @@ public class AmlAlertReadPlatformServiceImpl implements AmlAlertReadPlatformServ
|
|||||||
|
|
||||||
private final AmlAlertRepository repository;
|
private final AmlAlertRepository repository;
|
||||||
private final ClientRiskRuleRepository clientRiskRuleRepository;
|
private final ClientRiskRuleRepository clientRiskRuleRepository;
|
||||||
|
private final AmlAlertRuleRepository alertRuleRepository;
|
||||||
|
private final AmlTransactionRuleRepository transactionRuleRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AmlAlertData> retrieve(String statusFilter) {
|
public List<AmlAlertData> retrieve(String statusFilter) {
|
||||||
final List<AmlAlert> alerts = (statusFilter == null || statusFilter.isBlank()) ? repository.findAll()
|
final List<AmlAlert> alerts = (statusFilter == null || statusFilter.isBlank()) ? repository.findAll()
|
||||||
: repository.findByStatusOrderByRaisedOnAsc(statusFilter);
|
: repository.findByStatusOrderByRaisedOnAsc(statusFilter);
|
||||||
|
// Nothing flagged is an ordinary state - a quiet period, or a bank that has just been set up - and every
|
||||||
|
// lookup below reads a list built from these alerts. An empty IN clause is a syntax error in Postgres, so
|
||||||
|
// without this the screen fails outright at the very moment it has nothing to report.
|
||||||
|
if (alerts.isEmpty()) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
// Resolved once for the whole page rather than per alert: many alerts share a rule, so a
|
// Resolved once for the whole page rather than per alert: many alerts share a rule, so a
|
||||||
// lookup inside the map step would re-read the same catalog rows repeatedly.
|
// lookup inside the map step would re-read the same catalog rows repeatedly.
|
||||||
final Map<Long, Integer> riskByRiskRuleId = riskCategoriesFor(alerts);
|
// Same reasoning for the also-matched rules, which are held on the alert as bare codes: one
|
||||||
|
// read for every code on the page, not one per alert.
|
||||||
|
// The findings beneath each alert - one row per rule, carrying that rule's own disposition. Read for the whole
|
||||||
|
// page at once rather than per alert.
|
||||||
|
final Map<Long, List<AmlAlertRule>> findingsByAlertId = this.alertRuleRepository
|
||||||
|
.findByAlertIdIn(alerts.stream().map(AmlAlert::getId).toList()).stream()
|
||||||
|
.collect(Collectors.groupingBy(f -> f.getAlert().getId()));
|
||||||
|
final Map<String, AmlTransactionRule> rulesByCode = rulesByCodeFor(alerts, findingsByAlertId);
|
||||||
|
final Map<Long, Integer> riskByRiskRuleId = riskCategoriesFor(alerts, rulesByCode.values());
|
||||||
return alerts.stream().sorted(Comparator.comparing(AmlAlert::getRaisedOn).reversed())
|
return alerts.stream().sorted(Comparator.comparing(AmlAlert::getRaisedOn).reversed())
|
||||||
.map(alert -> mapToData(alert, riskByRiskRuleId)).collect(Collectors.toList());
|
.map(alert -> mapToData(alert, riskByRiskRuleId, rulesByCode, findingsByAlertId)).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Severity of each originating catalog rule, keyed on m_client_risk_rule.id. */
|
/**
|
||||||
private Map<Long, Integer> riskCategoriesFor(final List<AmlAlert> alerts) {
|
* Every rule named anywhere on this page, keyed on its code.
|
||||||
final List<Long> sourceIds = alerts.stream().map(a -> a.getRule().getSourceClientRiskRuleId()).filter(id -> id != null).distinct()
|
*
|
||||||
.toList();
|
* <p>
|
||||||
|
* Covers the findings as well as the also-matched lists, because a finding holds only a code and the pane needs the
|
||||||
|
* description behind it.
|
||||||
|
*/
|
||||||
|
private Map<String, AmlTransactionRule> rulesByCodeFor(final List<AmlAlert> alerts,
|
||||||
|
final Map<Long, List<AmlAlertRule>> findingsByAlertId) {
|
||||||
|
final Set<String> codes = alerts.stream().map(AmlAlert::getAlsoMatchedRules).filter(s -> s != null && !s.isBlank())
|
||||||
|
.flatMap(s -> Arrays.stream(s.split(","))).map(String::trim).filter(s -> !s.isEmpty())
|
||||||
|
.collect(Collectors.toCollection(java.util.HashSet::new));
|
||||||
|
findingsByAlertId.values().stream().flatMap(List::stream).map(AmlAlertRule::getRuleCode).forEach(codes::add);
|
||||||
|
alerts.stream().map(a -> a.getRule().getRuleCode()).forEach(codes::add);
|
||||||
|
if (codes.isEmpty()) {
|
||||||
|
return Map.of();
|
||||||
|
}
|
||||||
|
final Map<String, AmlTransactionRule> byCode = new HashMap<>();
|
||||||
|
this.transactionRuleRepository.findByRuleCodeIn(codes).forEach(rule -> byCode.put(rule.getRuleCode(), rule));
|
||||||
|
return byCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Every rule the transaction matched, governing one first, each carrying its description and severity.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* A rule whose catalog ancestor is missing still appears, with a null severity rather than being dropped: the
|
||||||
|
* officer needs to see that it fired. A code with no rule behind it at all - a rule deleted since the alert was
|
||||||
|
* raised - keeps its code as the description, because the alert is a record of what happened and editing the rule
|
||||||
|
* set afterwards does not change that.
|
||||||
|
*/
|
||||||
|
private List<AmlMatchedRuleData> matchedRulesOf(final AmlAlert alert, final Map<Long, Integer> riskByRiskRuleId,
|
||||||
|
final Map<String, AmlTransactionRule> rulesByCode, final Map<Long, List<AmlAlertRule>> findingsByAlertId) {
|
||||||
|
final List<AmlAlertRule> findings = findingsByAlertId.get(alert.getId());
|
||||||
|
if (findings != null && !findings.isEmpty()) {
|
||||||
|
// Governing rule first, then by code, so the pane does not reorder itself between reads.
|
||||||
|
return findings.stream()
|
||||||
|
.sorted(Comparator.comparing(AmlAlertRule::isGoverning).reversed().thenComparing(AmlAlertRule::getRuleCode))
|
||||||
|
.map(f -> new AmlMatchedRuleData(f.getRuleCode(), describe(f.getRuleCode(), rulesByCode), f.getRiskCategory(),
|
||||||
|
f.isGoverning(), f.getDisposition(),
|
||||||
|
f.getReviewedBy() == null ? null : f.getReviewedBy().getUsername(), f.getReviewNotes(),
|
||||||
|
f.isDirectlyDecided()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
// No findings rows: an alert raised before they existed and not covered by the backfill. Rebuilt from the flat
|
||||||
|
// fields so the pane still shows what fired, with no per-rule disposition to report.
|
||||||
|
final List<AmlMatchedRuleData> matched = new ArrayList<>();
|
||||||
|
final Long governingSourceId = alert.getRule().getSourceClientRiskRuleId();
|
||||||
|
matched.add(new AmlMatchedRuleData(alert.getRule().getRuleCode(), alert.getRule().getDescription(),
|
||||||
|
governingSourceId == null ? null : riskByRiskRuleId.get(governingSourceId), true, null, null, null, false));
|
||||||
|
|
||||||
|
final String also = alert.getAlsoMatchedRules();
|
||||||
|
if (also == null || also.isBlank()) {
|
||||||
|
return matched;
|
||||||
|
}
|
||||||
|
for (final String raw : also.split(",")) {
|
||||||
|
final String code = raw.trim();
|
||||||
|
if (code.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final AmlTransactionRule rule = rulesByCode.get(code);
|
||||||
|
final Long sourceId = rule == null ? null : rule.getSourceClientRiskRuleId();
|
||||||
|
matched.add(new AmlMatchedRuleData(code, describe(code, rulesByCode),
|
||||||
|
sourceId == null ? null : riskByRiskRuleId.get(sourceId), false, null, null, null, false));
|
||||||
|
}
|
||||||
|
return matched;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A rule's description, or its code when the rule itself is gone.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* An alert records what was detected at the time; a rule retired since then does not erase the finding, so the code
|
||||||
|
* stands in rather than the row disappearing.
|
||||||
|
*/
|
||||||
|
private String describe(final String ruleCode, final Map<String, AmlTransactionRule> rulesByCode) {
|
||||||
|
final AmlTransactionRule rule = rulesByCode.get(ruleCode);
|
||||||
|
return rule == null || rule.getDescription() == null ? ruleCode : rule.getDescription();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Severity of each originating catalog rule, keyed on m_client_risk_rule.id.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Covers the also-matched rules as well as the governing ones. Resolving only the governing rules left every
|
||||||
|
* also-matched rule reporting a null severity, which is exactly the thing the expanded row exists to show.
|
||||||
|
*/
|
||||||
|
private Map<Long, Integer> riskCategoriesFor(final List<AmlAlert> alerts, final Collection<AmlTransactionRule> alsoMatched) {
|
||||||
|
final List<Long> sourceIds = Stream
|
||||||
|
.concat(alerts.stream().map(a -> a.getRule().getSourceClientRiskRuleId()),
|
||||||
|
alsoMatched.stream().map(AmlTransactionRule::getSourceClientRiskRuleId))
|
||||||
|
.filter(id -> id != null).distinct().toList();
|
||||||
final Map<Long, Integer> byId = new HashMap<>();
|
final Map<Long, Integer> byId = new HashMap<>();
|
||||||
if (sourceIds.isEmpty()) {
|
if (sourceIds.isEmpty()) {
|
||||||
return byId;
|
return byId;
|
||||||
@@ -62,13 +177,15 @@ public class AmlAlertReadPlatformServiceImpl implements AmlAlertReadPlatformServ
|
|||||||
return byId;
|
return byId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AmlAlertData mapToData(AmlAlert alert, Map<Long, Integer> riskByRiskRuleId) {
|
private AmlAlertData mapToData(AmlAlert alert, Map<Long, Integer> riskByRiskRuleId, Map<String, AmlTransactionRule> rulesByCode,
|
||||||
|
Map<Long, List<AmlAlertRule>> findingsByAlertId) {
|
||||||
final Long sourceRiskRuleId = alert.getRule().getSourceClientRiskRuleId();
|
final Long sourceRiskRuleId = alert.getRule().getSourceClientRiskRuleId();
|
||||||
final Integer riskCategory = sourceRiskRuleId == null ? null : riskByRiskRuleId.get(sourceRiskRuleId);
|
final Integer riskCategory = sourceRiskRuleId == null ? null : riskByRiskRuleId.get(sourceRiskRuleId);
|
||||||
return new AmlAlertData(alert.getId(), alert.getTransactionType().name(), alert.getTransactionId(), alert.getClient().getId(),
|
return new AmlAlertData(alert.getId(), alert.getTransactionType().name(), alert.getTransactionId(), alert.getClient().getId(),
|
||||||
alert.getClient().getDisplayName(), alert.getRule().getRuleCode(), alert.getRule().getDescription(), alert.getAmount(),
|
alert.getClient().getDisplayName(), alert.getRule().getRuleCode(), alert.getRule().getDescription(), alert.getAmount(),
|
||||||
alert.getCurrencyCode(), alert.getRaisedOn(), alert.getStatus().name(),
|
alert.getCurrencyCode(), alert.getRaisedOn(), alert.getStatus().name(),
|
||||||
alert.getReviewedBy() == null ? null : alert.getReviewedBy().getUsername(), alert.getReviewedOn(),
|
alert.getReviewedBy() == null ? null : alert.getReviewedBy().getUsername(), alert.getReviewedOn(),
|
||||||
alert.getReviewNotes(), alert.getDisposition() == null ? null : alert.getDisposition().name(), riskCategory);
|
alert.getReviewNotes(), alert.getDisposition() == null ? null : alert.getDisposition().name(), riskCategory,
|
||||||
|
alert.getAlsoMatchedRules(), alert.getHighestSeverity(), matchedRulesOf(alert, riskByRiskRuleId, rulesByCode, findingsByAlertId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+26
@@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.fineract.portfolio.aml.service;
|
package org.apache.fineract.portfolio.aml.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlAlert;
|
import org.apache.fineract.portfolio.aml.domain.AmlAlert;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlStrCase;
|
import org.apache.fineract.portfolio.aml.domain.AmlStrCase;
|
||||||
|
|
||||||
@@ -27,4 +28,29 @@ public interface AmlAlertWritePlatformService {
|
|||||||
AmlAlert whitelist(Long alertId, String notes);
|
AmlAlert whitelist(Long alertId, String notes);
|
||||||
|
|
||||||
AmlStrCase escalate(Long alertId, String notes);
|
AmlStrCase escalate(Long alertId, String notes);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escalates several alerts into a single STR case.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* For a case raised off a customer's repeated behaviour rather than one transaction. Escalating each alert
|
||||||
|
* separately would put one case per transaction in front of the Principal Officer, each holding a fragment of a
|
||||||
|
* pattern that only means anything taken together - and a customer reviewed again a month later would add several
|
||||||
|
* more. An STR to FIU-IND reports the activity, so the case has to hold all of it.
|
||||||
|
*
|
||||||
|
* @param alertIds
|
||||||
|
* the alerts the pattern is made of; any already covered by a case keep that case
|
||||||
|
* @return the case covering them, or null when every alert was already covered
|
||||||
|
*/
|
||||||
|
AmlStrCase escalateAsOneCase(List<Long> alertIds, String notes);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decides individual rules within one alert, leaving the rest open.
|
||||||
|
*
|
||||||
|
* @param ruleCodes
|
||||||
|
* the rules being decided now
|
||||||
|
* @param disposition
|
||||||
|
* WHITELIST or ESCALATE, applied to each of them
|
||||||
|
*/
|
||||||
|
AmlAlert reviewRules(Long alertId, List<String> ruleCodes, String disposition, String notes);
|
||||||
}
|
}
|
||||||
|
|||||||
+183
-2
@@ -19,12 +19,21 @@
|
|||||||
package org.apache.fineract.portfolio.aml.service;
|
package org.apache.fineract.portfolio.aml.service;
|
||||||
|
|
||||||
import jakarta.persistence.EntityNotFoundException;
|
import jakarta.persistence.EntityNotFoundException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlAlert;
|
import org.apache.fineract.portfolio.aml.domain.AmlAlert;
|
||||||
|
import org.apache.fineract.portfolio.aml.domain.AmlAlertDisposition;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlAlertRepository;
|
import org.apache.fineract.portfolio.aml.domain.AmlAlertRepository;
|
||||||
|
import org.apache.fineract.portfolio.aml.domain.AmlAlertRule;
|
||||||
|
import org.apache.fineract.portfolio.aml.domain.AmlAlertRuleRepository;
|
||||||
|
import org.apache.fineract.portfolio.aml.domain.AmlAlertStatus;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlStrCase;
|
import org.apache.fineract.portfolio.aml.domain.AmlStrCase;
|
||||||
|
import org.apache.fineract.portfolio.aml.domain.AmlStrCaseAlert;
|
||||||
|
import org.apache.fineract.portfolio.aml.domain.AmlStrCaseAlertRepository;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlStrCaseRepository;
|
import org.apache.fineract.portfolio.aml.domain.AmlStrCaseRepository;
|
||||||
|
import org.apache.fineract.useradministration.domain.AppUser;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@@ -34,28 +43,200 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
public class AmlAlertWritePlatformServiceImpl implements AmlAlertWritePlatformService {
|
public class AmlAlertWritePlatformServiceImpl implements AmlAlertWritePlatformService {
|
||||||
|
|
||||||
private final AmlAlertRepository alertRepository;
|
private final AmlAlertRepository alertRepository;
|
||||||
|
private final AmlAlertRuleRepository alertRuleRepository;
|
||||||
private final AmlStrCaseRepository strCaseRepository;
|
private final AmlStrCaseRepository strCaseRepository;
|
||||||
|
private final AmlStrCaseAlertRepository strCaseAlertRepository;
|
||||||
private final PlatformSecurityContext context;
|
private final PlatformSecurityContext context;
|
||||||
private final ClientRiskEscalationService clientRiskEscalationService;
|
private final ClientRiskEscalationService clientRiskEscalationService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AmlAlert whitelist(Long alertId, String notes) {
|
public AmlAlert whitelist(Long alertId, String notes) {
|
||||||
final AmlAlert alert = loadAlert(alertId);
|
final AmlAlert alert = loadForDisposal(alertId);
|
||||||
alert.whitelist(context.authenticatedUser(), notes);
|
alert.whitelist(context.authenticatedUser(), notes);
|
||||||
|
decideAllFindings(alertId, AmlAlertDisposition.WHITELIST, notes, true);
|
||||||
return alertRepository.save(alert);
|
return alertRepository.save(alert);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AmlStrCase escalate(Long alertId, String notes) {
|
public AmlStrCase escalate(Long alertId, String notes) {
|
||||||
final AmlAlert alert = loadAlert(alertId);
|
// loadForDisposal has already refused an alert that was decided, so this can only be reached on an open one.
|
||||||
|
// An STR is about the transaction, and one transaction gets one case.
|
||||||
|
final AmlAlert alert = loadForDisposal(alertId);
|
||||||
alert.escalate(context.authenticatedUser(), notes);
|
alert.escalate(context.authenticatedUser(), notes);
|
||||||
|
decideAllFindings(alertId, AmlAlertDisposition.ESCALATE, notes, true);
|
||||||
alertRepository.save(alert);
|
alertRepository.save(alert);
|
||||||
|
return strCaseRepository.findByAlertId(alertId).orElseGet(() -> openStrCase(alert));
|
||||||
|
}
|
||||||
|
|
||||||
|
private AmlStrCase openStrCase(final AmlAlert alert) {
|
||||||
final AmlStrCase strCase = strCaseRepository.save(AmlStrCase.openFor(alert));
|
final AmlStrCase strCase = strCaseRepository.save(AmlStrCase.openFor(alert));
|
||||||
|
// Recorded in the link table as well as on alert_id, so every case describes what it covers the same way -
|
||||||
|
// a single-transaction case covering one alert, a pattern case covering several.
|
||||||
|
strCaseAlertRepository.save(AmlStrCaseAlert.link(strCase, alert));
|
||||||
clientRiskEscalationService.onStrCaseEscalated(strCase);
|
clientRiskEscalationService.onStrCaseEscalated(strCase);
|
||||||
return strCase;
|
return strCase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AmlStrCase escalateAsOneCase(final List<Long> alertIds, final String notes) {
|
||||||
|
if (alertIds == null || alertIds.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final AppUser currentUser = context.authenticatedUser();
|
||||||
|
AmlStrCase strCase = null;
|
||||||
|
|
||||||
|
for (final Long alertId : alertIds) {
|
||||||
|
final AmlAlert alert = loadForDisposal(alertId);
|
||||||
|
|
||||||
|
// An alert already inside a case keeps it. Two cases holding one transaction would reach FIU-IND twice
|
||||||
|
// under two references, and the older case is the one an officer may already have worked on.
|
||||||
|
final AmlStrCaseAlert existing = strCaseAlertRepository.findByAlert_Id(alertId).orElse(null);
|
||||||
|
if (existing != null) {
|
||||||
|
if (strCase == null) {
|
||||||
|
strCase = existing.getStrCase();
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
alert.escalate(currentUser, notes);
|
||||||
|
decideAllFindings(alertId, AmlAlertDisposition.ESCALATE, notes, true);
|
||||||
|
alertRepository.save(alert);
|
||||||
|
|
||||||
|
if (strCase == null) {
|
||||||
|
// Opened from the first alert that needed one, which is the oldest: the case is dated and referenced
|
||||||
|
// from where the pattern starts rather than from whichever alert happened to be escalated last.
|
||||||
|
strCase = strCaseRepository.save(AmlStrCase.openFor(alert));
|
||||||
|
clientRiskEscalationService.onStrCaseEscalated(strCase);
|
||||||
|
}
|
||||||
|
strCaseAlertRepository.save(AmlStrCaseAlert.link(strCase, alert));
|
||||||
|
}
|
||||||
|
|
||||||
|
return strCase;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Records a decision against individual rules within one alert.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* A transaction can trip six rules where five are explained by the customer's declared business and the sixth is
|
||||||
|
* not. Deciding those separately is the point; the alert's own status is then derived from what is left - it stays
|
||||||
|
* open while any rule is undecided, because a case with an open finding is not a closed case.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Escalating any rule opens the STR case for the transaction, and only one: an STR is about the transaction, not
|
||||||
|
* about each rule that described it. Escalating a second rule on an alert already escalated adds the finding
|
||||||
|
* without opening a duplicate case.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public AmlAlert reviewRules(final Long alertId, final List<String> ruleCodes, final String disposition, final String notes) {
|
||||||
|
final AmlAlert alert = loadForDisposal(alertId);
|
||||||
|
final AmlAlertDisposition decision = AmlAlertDisposition.valueOf(disposition);
|
||||||
|
final List<AmlAlertRule> findings = alertRuleRepository.findByAlertId(alertId);
|
||||||
|
|
||||||
|
final Set<String> requested = Set.copyOf(ruleCodes);
|
||||||
|
// A finding already decided is left alone, for the same reason the alert itself is: the decision recorded
|
||||||
|
// against a rule is the bank's answer on it, and a second pass writing over it would leave the file showing
|
||||||
|
// only whatever was sent last. Asked to decide rules that are all already decided, this refuses rather than
|
||||||
|
// silently doing nothing.
|
||||||
|
final List<AmlAlertRule> targeted = findings.stream()
|
||||||
|
.filter(f -> requested.contains(f.getRuleCode()) && !f.isDecided()).toList();
|
||||||
|
if (targeted.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"No open rules matching " + String.join(", ", ruleCodes) + " on alert " + alertId + " — already decided");
|
||||||
|
}
|
||||||
|
for (final AmlAlertRule finding : targeted) {
|
||||||
|
finding.decide(decision, context.authenticatedUser(), notes, true);
|
||||||
|
alertRuleRepository.save(finding);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Re-read state across every finding, including the ones just written, to decide where the alert now stands.
|
||||||
|
final boolean anyEscalated = findings.stream().anyMatch(AmlAlertRule::isEscalated);
|
||||||
|
final boolean wasEscalated = AmlAlertStatus.ESCALATED.equals(alert.getStatus());
|
||||||
|
|
||||||
|
// Suspicion carries the transaction, whatever else is still open. Waiting for every rule to be decided meant
|
||||||
|
// an officer could mark a withdrawal suspicious and watch the row sit there as RAISED with no STR case, purely
|
||||||
|
// because a second, innocuous rule had not been clicked - the one outcome that must never be delayed. One
|
||||||
|
// suspicious finding makes the transaction suspicious; the remaining rules are then recorded against a case
|
||||||
|
// that is already open.
|
||||||
|
if (anyEscalated) {
|
||||||
|
alert.escalate(context.authenticatedUser(), notes);
|
||||||
|
// The findings left open were carried into the escalation, so nothing is left dangling behind a decided
|
||||||
|
// case - but recorded as carried, not as named. The officer condemned the rule they ticked; the rest were
|
||||||
|
// closed to keep the case consistent, and the record must not claim otherwise.
|
||||||
|
decideAllFindings(alertId, AmlAlertDisposition.ESCALATE, notes, false);
|
||||||
|
alertRepository.save(alert);
|
||||||
|
if (!wasEscalated) {
|
||||||
|
final AmlStrCase strCase = strCaseRepository.save(AmlStrCase.openFor(alert));
|
||||||
|
clientRiskEscalationService.onStrCaseEscalated(strCase);
|
||||||
|
}
|
||||||
|
return alert;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clearing is the opposite: it only holds once nothing is left to look at. A transaction is not cleared while
|
||||||
|
// one of its rules is still unexamined.
|
||||||
|
//
|
||||||
|
// Statutory rules are not part of that test. A CTR carries no severity because it is not a graded suspicion -
|
||||||
|
// it is a return owed on the amount, filed whether or not the customer is above suspicion - so it is never
|
||||||
|
// offered to the officer to decide. Counting it as unexamined would leave the alert permanently unclearable,
|
||||||
|
// waiting on a judgement that is not the officer's to make.
|
||||||
|
if (!findings.stream().filter(f -> f.getRiskCategory() != null).allMatch(AmlAlertRule::isDecided)) {
|
||||||
|
return alertRepository.save(alert);
|
||||||
|
}
|
||||||
|
alert.whitelist(context.authenticatedUser(), notes);
|
||||||
|
return alertRepository.save(alert);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Carries a whole-alert decision down to every finding still open beneath it.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Deciding the alert decides everything in it. Without this a case closed from the row would leave its findings
|
||||||
|
* blank, and the expanded pane would show a whitelisted alert whose rules all still read as undecided. Findings
|
||||||
|
* already decided individually keep the decision the officer made about them.
|
||||||
|
*/
|
||||||
|
private void decideAllFindings(final Long alertId, final AmlAlertDisposition disposition, final String notes,
|
||||||
|
final boolean directlyDecided) {
|
||||||
|
for (final AmlAlertRule finding : alertRuleRepository.findByAlertId(alertId)) {
|
||||||
|
if (!finding.isDecided()) {
|
||||||
|
finding.decide(disposition, context.authenticatedUser(), notes, directlyDecided);
|
||||||
|
alertRuleRepository.save(finding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads an alert the current officer is entitled to dispose of.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* An alert another officer has open is theirs until they decide it or hand it back. Two officers reaching their
|
||||||
|
* own verdicts on one transaction is the failure this prevents - both writes succeed, and the case ends up
|
||||||
|
* recorded as whatever the second one happened to choose. Refusing here rather than in the screen is what makes
|
||||||
|
* it a rule: the screen hides the buttons, but the endpoint is what enforces it.
|
||||||
|
*/
|
||||||
|
private AmlAlert loadForDisposal(final Long alertId) {
|
||||||
|
final AmlAlert alert = loadAlert(alertId);
|
||||||
|
|
||||||
|
// A disposition is final. Whitelisting or escalating an alert is the bank's recorded answer to a flagged
|
||||||
|
// transaction - an escalation has already opened an STR case and re-rated the customer - and letting a second
|
||||||
|
// officer write over it would leave the file saying whatever was submitted last, with the earlier decision and
|
||||||
|
// the reasoning behind it simply gone. Anything that genuinely has to be revisited is reopened deliberately,
|
||||||
|
// through the STR case, where the change is itself recorded.
|
||||||
|
final AmlAlertStatus status = alert.getStatus();
|
||||||
|
if (AmlAlertStatus.WHITELISTED.equals(status) || AmlAlertStatus.ESCALATED.equals(status)) {
|
||||||
|
throw new IllegalStateException("Alert " + alertId + " was already " + status.name().toLowerCase() + " by "
|
||||||
|
+ (alert.getReviewedBy() == null ? "another officer" : alert.getReviewedBy().getUsername())
|
||||||
|
+ " and cannot be decided again");
|
||||||
|
}
|
||||||
|
|
||||||
|
final AppUser current = context.authenticatedUser();
|
||||||
|
if (alert.isHeldByAnother(current)) {
|
||||||
|
throw new IllegalStateException("Alert " + alertId + " is being reviewed by "
|
||||||
|
+ alert.getReviewedBy().getUsername() + " and cannot be decided by another officer until they release it");
|
||||||
|
}
|
||||||
|
return alert;
|
||||||
|
}
|
||||||
|
|
||||||
private AmlAlert loadAlert(Long alertId) {
|
private AmlAlert loadAlert(Long alertId) {
|
||||||
return alertRepository.findById(alertId)
|
return alertRepository.findById(alertId)
|
||||||
.orElseThrow(() -> new EntityNotFoundException("AML alert " + alertId + " does not exist"));
|
.orElseThrow(() -> new EntityNotFoundException("AML alert " + alertId + " does not exist"));
|
||||||
|
|||||||
+17
-2
@@ -26,11 +26,13 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlCtrReport;
|
import org.apache.fineract.portfolio.aml.domain.AmlCtrReport;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlCtrReportLine;
|
import org.apache.fineract.portfolio.aml.domain.AmlCtrReportLine;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlCtrReportLineRepository;
|
import org.apache.fineract.portfolio.aml.domain.AmlCtrReportLineRepository;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlCtrReportRepository;
|
import org.apache.fineract.portfolio.aml.domain.AmlCtrReportRepository;
|
||||||
|
import org.apache.fineract.portfolio.aml.domain.AmlCtrReportStatus;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlTransactionType;
|
import org.apache.fineract.portfolio.aml.domain.AmlTransactionType;
|
||||||
import org.apache.fineract.portfolio.aml.repository.AmlLoanTransactionQueryRepository;
|
import org.apache.fineract.portfolio.aml.repository.AmlLoanTransactionQueryRepository;
|
||||||
import org.apache.fineract.portfolio.aml.repository.AmlSavingsTransactionQueryRepository;
|
import org.apache.fineract.portfolio.aml.repository.AmlSavingsTransactionQueryRepository;
|
||||||
@@ -66,8 +68,21 @@ public class AmlCtrReportGenerationService {
|
|||||||
|
|
||||||
public AmlCtrReport generateForMonth(YearMonth month) {
|
public AmlCtrReport generateForMonth(YearMonth month) {
|
||||||
final String reportMonth = month.toString();
|
final String reportMonth = month.toString();
|
||||||
if (ctrReportRepository.findByReportMonth(reportMonth).isPresent()) {
|
// A month can be rebuilt while its report is still a draft, and must not be once it has been submitted.
|
||||||
throw new IllegalStateException("CTR report for " + reportMonth + " has already been generated");
|
// Refusing outright was the safer-looking rule and the wrong one: the batch is a snapshot, so a cash
|
||||||
|
// transaction posted after it ran belonged to that month's filing and could never be added to it - the report
|
||||||
|
// was permanently short of a transaction the bank is obliged to report. Regenerating a draft replaces its
|
||||||
|
// lines with what the month now holds; a submitted report is left exactly as filed.
|
||||||
|
final Optional<AmlCtrReport> existing = ctrReportRepository.findByReportMonth(reportMonth);
|
||||||
|
if (existing.isPresent()) {
|
||||||
|
final AmlCtrReport report = existing.get();
|
||||||
|
if (AmlCtrReportStatus.SUBMITTED.equals(report.getStatus())) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"CTR report for " + reportMonth + " has been submitted to FIU-IND and cannot be regenerated");
|
||||||
|
}
|
||||||
|
ctrReportLineRepository.deleteAll(ctrReportLineRepository.findByCtrReport_Id(report.getId()));
|
||||||
|
ctrReportRepository.delete(report);
|
||||||
|
ctrReportRepository.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
final LocalDate start = month.atDay(1);
|
final LocalDate start = month.atDay(1);
|
||||||
|
|||||||
+9
@@ -33,4 +33,13 @@ public interface AmlCtrReportReadPlatformService {
|
|||||||
* one month's report, or null for every generated month
|
* one month's report, or null for every generated month
|
||||||
*/
|
*/
|
||||||
List<AmlCtrReportLineData> retrieveLines(Long reportId);
|
List<AmlCtrReportLineData> retrieveLines(Long reportId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reportable cash transactions that no generated report contains yet.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* The monthly batch is a snapshot; anything posted after it runs belongs to that month's filing but sits in no
|
||||||
|
* report until the month is regenerated. These are those transactions, so a reportable one is never invisible.
|
||||||
|
*/
|
||||||
|
List<AmlCtrReportLineData> retrievePendingLines();
|
||||||
}
|
}
|
||||||
|
|||||||
+77
-8
@@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.fineract.portfolio.aml.service;
|
package org.apache.fineract.portfolio.aml.service;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -28,6 +29,7 @@ import org.apache.fineract.portfolio.aml.data.AmlCtrReportLineData;
|
|||||||
import org.apache.fineract.portfolio.aml.domain.AmlCtrReport;
|
import org.apache.fineract.portfolio.aml.domain.AmlCtrReport;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlCtrReportRepository;
|
import org.apache.fineract.portfolio.aml.domain.AmlCtrReportRepository;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@@ -68,6 +70,56 @@ public class AmlCtrReportReadPlatformServiceImpl implements AmlCtrReportReadPlat
|
|||||||
LEFT JOIN m_savings_account sa ON sa.id = t.savings_account_id
|
LEFT JOIN m_savings_account sa ON sa.id = t.savings_account_id
|
||||||
""";
|
""";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cash transactions that a CTR must name but that no generated report contains yet.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* The monthly batch takes a snapshot the moment it runs. A ₹15,00,000 cash deposit posted after that run belongs
|
||||||
|
* to the same month's filing and appears nowhere - not in the report, not on the FIU screen - until someone thinks
|
||||||
|
* to regenerate. A reportable transaction that is invisible is the one failure this report cannot have, so it is
|
||||||
|
* listed here as pending: shaped exactly like a generated line, with no report behind it.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Individually-reportable transactions only. A connected group is an arithmetic fact about a whole month and
|
||||||
|
* cannot be decided while the month is still running.
|
||||||
|
*/
|
||||||
|
private static final String PENDING_LINES_SQL = """
|
||||||
|
SELECT NULL::bigint AS id, NULL::bigint AS ctr_report_id,
|
||||||
|
to_char(t.transaction_date, 'YYYY-MM') AS report_month,
|
||||||
|
'SAVINGS' AS transaction_type, t.id AS transaction_id,
|
||||||
|
c.id AS client_id, c.display_name AS client_name, t.amount, false AS is_connected_group,
|
||||||
|
sa.account_no AS account_no, o.name AS branch_name, t.transaction_date,
|
||||||
|
CASE WHEN t.transaction_type_enum = 1 THEN 'Deposit'
|
||||||
|
WHEN t.transaction_type_enum = 2 THEN 'Withdrawal' END AS direction,
|
||||||
|
sa.activatedon_date AS account_opened_on,
|
||||||
|
sa.closedon_date AS account_closed_on,
|
||||||
|
CASE sa.status_enum WHEN 100 THEN 'SUBMITTED' WHEN 200 THEN 'APPROVED'
|
||||||
|
WHEN 300 THEN 'ACTIVE' WHEN 400 THEN 'WITHDRAWN' WHEN 500 THEN 'REJECTED'
|
||||||
|
WHEN 600 THEN 'CLOSED' WHEN 700 THEN 'PRE-MATURE CLOSED'
|
||||||
|
WHEN 800 THEN 'MATURED' END AS account_status,
|
||||||
|
k.ckyc_number AS ckyc_number,
|
||||||
|
COALESCE(NULLIF(c.external_id, ''), c.account_no) AS client_external_id,
|
||||||
|
COALESCE(c.legal_form_enum, 1) = 1 AS individual
|
||||||
|
FROM m_savings_account_transaction t
|
||||||
|
JOIN m_savings_account sa ON sa.id = t.savings_account_id
|
||||||
|
JOIN m_client c ON c.id = sa.client_id
|
||||||
|
LEFT JOIN m_office o ON o.id = c.office_id
|
||||||
|
LEFT JOIN m_client_kyc k ON k.client_id = c.id
|
||||||
|
JOIN m_payment_detail pd ON pd.id = t.payment_detail_id
|
||||||
|
JOIN m_payment_type pt ON pt.id = pd.payment_type_id
|
||||||
|
WHERE pt.is_cash_payment = true
|
||||||
|
AND t.is_reversed = false
|
||||||
|
AND t.transaction_type_enum IN (1, 2)
|
||||||
|
AND t.amount >= ?
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1 FROM m_aml_ctr_report_line el
|
||||||
|
WHERE el.transaction_type = 'SAVINGS' AND el.transaction_id = t.id)
|
||||||
|
ORDER BY t.transaction_date DESC, t.amount DESC, t.id
|
||||||
|
""";
|
||||||
|
|
||||||
|
/** The CTR line: ₹10,00,000 in a single cash transaction. Mirrors AmlCtrReportGenerationService. */
|
||||||
|
private static final BigDecimal CTR_THRESHOLD = new BigDecimal("1000000");
|
||||||
|
|
||||||
private final AmlCtrReportRepository repository;
|
private final AmlCtrReportRepository repository;
|
||||||
private final JdbcTemplate jdbcTemplate;
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
@@ -88,17 +140,34 @@ public class AmlCtrReportReadPlatformServiceImpl implements AmlCtrReportReadPlat
|
|||||||
// Largest first: the line most likely to be questioned is the one the reviewer reads first.
|
// Largest first: the line most likely to be questioned is the one the reviewer reads first.
|
||||||
sql.append(" ORDER BY r.report_month DESC, l.amount DESC, l.id ");
|
sql.append(" ORDER BY r.report_month DESC, l.amount DESC, l.id ");
|
||||||
|
|
||||||
return jdbcTemplate.query(sql.toString(), (rs, rowNum) -> new AmlCtrReportLineData(rs.getLong("id"),
|
return jdbcTemplate.query(sql.toString(), LINE_MAPPER, args.toArray());
|
||||||
rs.getLong("ctr_report_id"), rs.getString("report_month"), rs.getString("transaction_type"),
|
}
|
||||||
rs.getObject("transaction_id") == null ? null : rs.getLong("transaction_id"), rs.getLong("client_id"),
|
|
||||||
rs.getString("client_name"), rs.getString("account_no"), rs.getString("branch_name"),
|
/**
|
||||||
rs.getDate("transaction_date") == null ? null : rs.getDate("transaction_date").toLocalDate(),
|
* Reportable cash transactions no generated report contains yet.
|
||||||
rs.getString("direction"), rs.getBigDecimal("amount"), rs.getBoolean("is_connected_group"),
|
*
|
||||||
|
* <p>
|
||||||
|
* Shaped as lines so the FIU screen can show them beside the filed ones, but with a null id and report id: they
|
||||||
|
* are not in a filing, and nothing here pretends they are. The filing is still made by generating the month, which
|
||||||
|
* is what makes them disappear from this list.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<AmlCtrReportLineData> retrievePendingLines() {
|
||||||
|
return jdbcTemplate.query(PENDING_LINES_SQL, LINE_MAPPER, CTR_THRESHOLD);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Shared by both queries, which select the same columns so a pending line renders like a filed one. */
|
||||||
|
private static final RowMapper<AmlCtrReportLineData> LINE_MAPPER = (rs, rowNum) -> new AmlCtrReportLineData(
|
||||||
|
rs.getObject("id") == null ? null : rs.getLong("id"),
|
||||||
|
rs.getObject("ctr_report_id") == null ? null : rs.getLong("ctr_report_id"), rs.getString("report_month"),
|
||||||
|
rs.getString("transaction_type"), rs.getObject("transaction_id") == null ? null : rs.getLong("transaction_id"),
|
||||||
|
rs.getLong("client_id"), rs.getString("client_name"), rs.getString("account_no"), rs.getString("branch_name"),
|
||||||
|
rs.getDate("transaction_date") == null ? null : rs.getDate("transaction_date").toLocalDate(), rs.getString("direction"),
|
||||||
|
rs.getBigDecimal("amount"), rs.getBoolean("is_connected_group"),
|
||||||
rs.getDate("account_opened_on") == null ? null : rs.getDate("account_opened_on").toLocalDate(),
|
rs.getDate("account_opened_on") == null ? null : rs.getDate("account_opened_on").toLocalDate(),
|
||||||
rs.getDate("account_closed_on") == null ? null : rs.getDate("account_closed_on").toLocalDate(),
|
rs.getDate("account_closed_on") == null ? null : rs.getDate("account_closed_on").toLocalDate(),
|
||||||
rs.getString("account_status"), rs.getString("ckyc_number"), rs.getString("client_external_id"),
|
rs.getString("account_status"), rs.getString("ckyc_number"), rs.getString("client_external_id"),
|
||||||
rs.getBoolean("individual")), args.toArray());
|
rs.getBoolean("individual"));
|
||||||
}
|
|
||||||
|
|
||||||
private AmlCtrReportData mapToData(AmlCtrReport report) {
|
private AmlCtrReportData mapToData(AmlCtrReport report) {
|
||||||
return new AmlCtrReportData(report.getId(), report.getReportMonth(), report.getGeneratedOn(), report.getRecordCount(),
|
return new AmlCtrReportData(report.getId(), report.getReportMonth(), report.getGeneratedOn(), report.getRecordCount(),
|
||||||
|
|||||||
+8
-4
@@ -79,9 +79,11 @@ public class AmlRecurringAlertReadPlatformServiceImpl implements AmlRecurringAle
|
|||||||
final List<AmlAlertData> alerts = byClient.get(clientId);
|
final List<AmlAlertData> alerts = byClient.get(clientId);
|
||||||
final AmlRecurringReview lastReview = this.reviewRepository.findByClient_IdOrderByReviewedOnDesc(clientId).stream().findFirst()
|
final AmlRecurringReview lastReview = this.reviewRepository.findByClient_IdOrderByReviewedOnDesc(clientId).stream().findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
// Reviewed at a lower count means new alerts have landed since — the customer has to
|
// A standing review holds the customer out until its window runs out, or until their behaviour has moved
|
||||||
// come back, otherwise one early review would silence them permanently.
|
// on far enough that it no longer describes them - see AmlRecurringReview#stillStands. It used to lapse on
|
||||||
final boolean needsReview = lastReview == null || alerts.size() > lastReview.getAlertCountAtReview();
|
// the very next alert, which brought a customer whose ordinary business trips a rule weekly straight back
|
||||||
|
// the day after being reviewed, for the officer to re-read the explanation they had just written.
|
||||||
|
final boolean needsReview = lastReview == null || !lastReview.stillStands(alerts.size());
|
||||||
if (onlyNeedingReview && !needsReview) {
|
if (onlyNeedingReview && !needsReview) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -91,7 +93,9 @@ public class AmlRecurringAlertReadPlatformServiceImpl implements AmlRecurringAle
|
|||||||
summary.riskCategory(), alerts.size(),
|
summary.riskCategory(), alerts.size(),
|
||||||
(int) alerts.stream().filter(a -> a.riskCategory() != null && a.riskCategory() == HIGH_RISK).count(),
|
(int) alerts.stream().filter(a -> a.riskCategory() != null && a.riskCategory() == HIGH_RISK).count(),
|
||||||
(int) alerts.stream().map(AmlAlertData::ruleCode).distinct().count(),
|
(int) alerts.stream().map(AmlAlertData::ruleCode).distinct().count(),
|
||||||
(int) alerts.stream().filter(a -> "RAISED".equals(a.status()) || "UNDER_REVIEW".equals(a.status())).count(),
|
// Open means undecided, not a named status: a status this count does not list would otherwise be
|
||||||
|
// dropped from the customer's open figure while the alert still sits in the feed awaiting review.
|
||||||
|
(int) alerts.stream().filter(a -> !"WHITELISTED".equals(a.status()) && !"ESCALATED".equals(a.status())).count(),
|
||||||
(int) alerts.stream().filter(a -> "ESCALATED".equals(a.status())).count(),
|
(int) alerts.stream().filter(a -> "ESCALATED".equals(a.status())).count(),
|
||||||
alerts.stream().map(AmlAlertData::amount).filter(x -> x != null).reduce(BigDecimal.ZERO, BigDecimal::add),
|
alerts.stream().map(AmlAlertData::amount).filter(x -> x != null).reduce(BigDecimal.ZERO, BigDecimal::add),
|
||||||
alerts.stream().map(AmlAlertData::raisedOn).min(Comparator.naturalOrder()).orElse(null),
|
alerts.stream().map(AmlAlertData::raisedOn).min(Comparator.naturalOrder()).orElse(null),
|
||||||
|
|||||||
+54
@@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.fineract.portfolio.aml.service;
|
package org.apache.fineract.portfolio.aml.service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -26,6 +27,8 @@ import org.apache.fineract.infrastructure.core.data.ApiParameterError;
|
|||||||
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
|
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
|
||||||
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
|
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||||
|
import org.apache.fineract.portfolio.aml.domain.AmlAlert;
|
||||||
|
import org.apache.fineract.portfolio.aml.domain.AmlAlertRepository;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlRecurringReview;
|
import org.apache.fineract.portfolio.aml.domain.AmlRecurringReview;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlRecurringReviewOutcome;
|
import org.apache.fineract.portfolio.aml.domain.AmlRecurringReviewOutcome;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlRecurringReviewRepository;
|
import org.apache.fineract.portfolio.aml.domain.AmlRecurringReviewRepository;
|
||||||
@@ -45,6 +48,8 @@ public class AmlRecurringAlertWritePlatformServiceImpl implements AmlRecurringAl
|
|||||||
private final AmlRecurringAlertReadPlatformService readPlatformService;
|
private final AmlRecurringAlertReadPlatformService readPlatformService;
|
||||||
private final ClientRepositoryWrapper clientRepository;
|
private final ClientRepositoryWrapper clientRepository;
|
||||||
private final PlatformSecurityContext context;
|
private final PlatformSecurityContext context;
|
||||||
|
private final AmlAlertRepository alertRepository;
|
||||||
|
private final AmlAlertWritePlatformService alertWritePlatformService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
@@ -59,9 +64,58 @@ public class AmlRecurringAlertWritePlatformServiceImpl implements AmlRecurringAl
|
|||||||
|
|
||||||
final AmlRecurringReview review = AmlRecurringReview.record(client, alertCount, parsedOutcome, notes.trim(),
|
final AmlRecurringReview review = AmlRecurringReview.record(client, alertCount, parsedOutcome, notes.trim(),
|
||||||
this.context.authenticatedUser());
|
this.context.authenticatedUser());
|
||||||
|
|
||||||
|
// The outcome now does what its name says. It used to do nothing at all: all three choices wrote the same row
|
||||||
|
// and the alerts were left exactly as they were, so an officer who chose ESCALATED believed they had raised an
|
||||||
|
// STR while the alerts sat untouched and no case ever reached the Principal Officer.
|
||||||
|
final int actioned = applyOutcomeToOpenAlerts(clientId, parsedOutcome, notes.trim(), window);
|
||||||
|
review.recordAlertsActioned(actioned);
|
||||||
|
|
||||||
return this.reviewRepository.saveAndFlush(review).getId();
|
return this.reviewRepository.saveAndFlush(review).getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Carries the reviewer's conclusion through to the customer's open alerts.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* CLEARED every open alert is whitelisted - the behaviour was explained, so nothing is left outstanding
|
||||||
|
* ESCALATED every open alert is escalated, which opens an STR case for the Principal Officer
|
||||||
|
* MONITOR nothing is disposed of - the point of monitoring is that the alerts stay open
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* Each alert is disposed of individually rather than in bulk, because whitelist() and escalate() already carry the
|
||||||
|
* audit trail, the per-rule findings and the STR-case handling that a review has to leave behind. Reproducing any
|
||||||
|
* of that here would be a second, quieter path to the same records.
|
||||||
|
*/
|
||||||
|
private int applyOutcomeToOpenAlerts(final Long clientId, final AmlRecurringReviewOutcome outcome, final String notes,
|
||||||
|
final int windowDays) {
|
||||||
|
|
||||||
|
if (AmlRecurringReviewOutcome.MONITOR.equals(outcome)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
final LocalDateTime since = LocalDateTime.now().minusDays(windowDays);
|
||||||
|
final List<AmlAlert> openAlerts = this.alertRepository.findOpenAlertsForClientSince(clientId, since);
|
||||||
|
|
||||||
|
final String trail = "Recurring-behaviour review: " + notes;
|
||||||
|
|
||||||
|
if (AmlRecurringReviewOutcome.ESCALATED.equals(outcome)) {
|
||||||
|
// One case for the whole pattern, not one per transaction. What is being reported is the customer's
|
||||||
|
// repeated activity, and the Principal Officer investigating it needs the transactions that make it up
|
||||||
|
// together - a case per alert would hand them four fragments of one story, and five more the next time
|
||||||
|
// this customer was reviewed.
|
||||||
|
this.alertWritePlatformService.escalateAsOneCase(openAlerts.stream().map(AmlAlert::getId).toList(), trail);
|
||||||
|
return openAlerts.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
int actioned = 0;
|
||||||
|
for (final AmlAlert alert : openAlerts) {
|
||||||
|
this.alertWritePlatformService.whitelist(alert.getId(), trail);
|
||||||
|
actioned++;
|
||||||
|
}
|
||||||
|
return actioned;
|
||||||
|
}
|
||||||
|
|
||||||
private AmlRecurringReviewOutcome validate(final Long clientId, final String outcome, final String notes) {
|
private AmlRecurringReviewOutcome validate(final Long clientId, final String outcome, final String notes) {
|
||||||
final List<ApiParameterError> errors = new ArrayList<>();
|
final List<ApiParameterError> errors = new ArrayList<>();
|
||||||
final DataValidatorBuilder validator = new DataValidatorBuilder(errors).resource(RESOURCE);
|
final DataValidatorBuilder validator = new DataValidatorBuilder(errors).resource(RESOURCE);
|
||||||
|
|||||||
+123
-4
@@ -20,17 +20,27 @@ package org.apache.fineract.portfolio.aml.service;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
||||||
import org.apache.fineract.portfolio.aml.data.AmlDirection;
|
import org.apache.fineract.portfolio.aml.data.AmlDirection;
|
||||||
import org.apache.fineract.portfolio.aml.data.AmlTransactionContext;
|
import org.apache.fineract.portfolio.aml.data.AmlTransactionContext;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlAlert;
|
import org.apache.fineract.portfolio.aml.domain.AmlAlert;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlAlertRepository;
|
import org.apache.fineract.portfolio.aml.domain.AmlAlertRepository;
|
||||||
|
import org.apache.fineract.portfolio.aml.domain.AmlAlertRule;
|
||||||
|
import org.apache.fineract.portfolio.aml.domain.AmlAlertRuleRepository;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlAppliesTo;
|
import org.apache.fineract.portfolio.aml.domain.AmlAppliesTo;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlTransactionRule;
|
import org.apache.fineract.portfolio.aml.domain.AmlTransactionRule;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlTransactionRuleRepository;
|
import org.apache.fineract.portfolio.aml.domain.AmlTransactionRuleRepository;
|
||||||
import org.apache.fineract.portfolio.client.domain.ClientKyc;
|
import org.apache.fineract.portfolio.client.domain.ClientKyc;
|
||||||
import org.apache.fineract.portfolio.client.domain.ClientKycRepository;
|
import org.apache.fineract.portfolio.client.domain.ClientKycRepository;
|
||||||
|
import org.apache.fineract.portfolio.client.domain.ClientRiskRule;
|
||||||
|
import org.apache.fineract.portfolio.client.domain.ClientRiskRuleRepository;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@@ -51,9 +61,39 @@ public class AmlRuleEvaluationServiceImpl implements AmlRuleEvaluationService {
|
|||||||
private static final int MEDIUM_RISK = 2;
|
private static final int MEDIUM_RISK = 2;
|
||||||
private static final int HIGH_RISK = 3;
|
private static final int HIGH_RISK = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rules that carry a filing obligation in their own right, whatever else the transaction also
|
||||||
|
* matched.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* A CTR is not a suspicion - it is a return the bank owes FIU-IND on any cash transaction at or
|
||||||
|
* above ten lakh, and it is filed whether or not the customer is above suspicion. Letting a
|
||||||
|
* behavioural rule outrank it would bury a statutory filing behind an internal observation.
|
||||||
|
*/
|
||||||
|
private static final Set<String> STATUTORY_RULE_CODES = Set.of("CTR_THRESHOLD_10L", "LARGE_CASH_TXN_25L",
|
||||||
|
"STRUCTURED_CTR_10L_MONTHLY");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Which rule an alert is raised under when a transaction matches several.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Statutory reporting first, because those must be filed. Then the largest threshold, which is
|
||||||
|
* the system's own measure of how far out of the ordinary the transaction is - a rule written
|
||||||
|
* for ₹25,00,000 is describing something graver than one written for ₹50,000. Rule code last,
|
||||||
|
* so the same transaction always reports under the same rule rather than shifting with whatever
|
||||||
|
* order the database returned.
|
||||||
|
*/
|
||||||
|
private static final Comparator<AmlTransactionRule> RULE_PRECEDENCE = Comparator
|
||||||
|
.comparing((AmlTransactionRule r) -> STATUTORY_RULE_CODES.contains(r.getRuleCode()) ? 0 : 1)
|
||||||
|
.thenComparing(r -> r.getThresholdAmount() == null ? BigDecimal.valueOf(-1) : r.getThresholdAmount(),
|
||||||
|
Comparator.reverseOrder())
|
||||||
|
.thenComparing(AmlTransactionRule::getRuleCode);
|
||||||
|
|
||||||
private final AmlTransactionRuleRepository ruleRepository;
|
private final AmlTransactionRuleRepository ruleRepository;
|
||||||
private final AmlAlertRepository alertRepository;
|
private final AmlAlertRepository alertRepository;
|
||||||
|
private final AmlAlertRuleRepository alertRuleRepository;
|
||||||
private final ClientKycRepository clientKycRepository;
|
private final ClientKycRepository clientKycRepository;
|
||||||
|
private final ClientRiskRuleRepository clientRiskRuleRepository;
|
||||||
private final AmlRecurringAlertNotificationService recurringAlertNotificationService;
|
private final AmlRecurringAlertNotificationService recurringAlertNotificationService;
|
||||||
private final AmlSubjectScopeResolver subjectScopeResolver;
|
private final AmlSubjectScopeResolver subjectScopeResolver;
|
||||||
|
|
||||||
@@ -63,15 +103,55 @@ public class AmlRuleEvaluationServiceImpl implements AmlRuleEvaluationService {
|
|||||||
candidates.addAll(ruleRepository.findByActiveTrueAndAppliesTo(context.getTransactionType().name()));
|
candidates.addAll(ruleRepository.findByActiveTrueAndAppliesTo(context.getTransactionType().name()));
|
||||||
candidates.addAll(ruleRepository.findByActiveTrueAndAppliesTo(AmlAppliesTo.ALL.name()));
|
candidates.addAll(ruleRepository.findByActiveTrueAndAppliesTo(AmlAppliesTo.ALL.name()));
|
||||||
|
|
||||||
final List<AmlAlert> raised = new ArrayList<>();
|
final List<AmlTransactionRule> matched = new ArrayList<>();
|
||||||
for (final AmlTransactionRule rule : candidates) {
|
for (final AmlTransactionRule rule : candidates) {
|
||||||
if (isHit(rule, context)) {
|
if (isHit(rule, context)) {
|
||||||
final AmlAlert alert = AmlAlert.raise(context.getTransactionType(), context.getTransactionId(), context.getClient(), rule,
|
matched.add(rule);
|
||||||
context.getAmount(), context.getCurrencyCode(), context.getOccurredOn());
|
|
||||||
raised.add(alertRepository.save(alert));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final List<AmlAlert> raised = new ArrayList<>();
|
||||||
|
if (!matched.isEmpty()) {
|
||||||
|
// One transaction, one alert. Raising one per matched rule meant a single ₹12,00,000
|
||||||
|
// cash deposit arrived as two open alerts - the CTR and the new-account rule - and the
|
||||||
|
// officer had to dispose of each. Nothing stopped them whitelisting one while
|
||||||
|
// escalating the other, leaving the same deposit recorded as both cleared and
|
||||||
|
// suspicious. A monitoring system reports a transaction once, under the rule that most
|
||||||
|
// warrants attention.
|
||||||
|
matched.sort(RULE_PRECEDENCE);
|
||||||
|
final AmlTransactionRule governing = matched.get(0);
|
||||||
|
|
||||||
|
// When the alert was raised, not the transaction's value date. The context carries the date the
|
||||||
|
// transaction is booked to, which is a LocalDate widened to midnight - so every alert on the screen read
|
||||||
|
// "00:00", and two alerts minutes apart were indistinguishable. A monitoring feed is ordered by when it
|
||||||
|
// noticed something; the value date is still on the transaction the alert points at.
|
||||||
|
final AmlAlert alert = AmlAlert.raise(context.getTransactionType(), context.getTransactionId(), context.getClient(),
|
||||||
|
governing, context.getAmount(), context.getCurrencyCode(), DateUtils.getLocalDateTimeOfTenant());
|
||||||
|
// The rules that did not govern are still recorded: an analyst needs to see that the
|
||||||
|
// deposit was both reportable and on a new account, even though it is one case.
|
||||||
|
if (matched.size() > 1) {
|
||||||
|
alert.recordAlsoMatchedRules(
|
||||||
|
matched.stream().skip(1).map(AmlTransactionRule::getRuleCode).collect(Collectors.joining(", ")));
|
||||||
|
}
|
||||||
|
// The worst band across everything that matched, not only the rule the alert was raised
|
||||||
|
// under. A statutory CTR outranks a high-severity behavioural rule when the governing
|
||||||
|
// rule is picked, so without this the screen would see "CTR, no severity" and offer the
|
||||||
|
// transaction up for a batch decision alongside ordinary low-value alerts.
|
||||||
|
final Map<Long, Integer> bandBySourceId = severityBySourceRuleId(matched);
|
||||||
|
alert.recordHighestSeverity(highestSeverityOf(bandBySourceId));
|
||||||
|
final AmlAlert saved = alertRepository.save(alert);
|
||||||
|
|
||||||
|
// One finding per rule, so each can be disposed of on its own. Severity is copied in
|
||||||
|
// rather than read back through the rule later: the alert records what was detected at
|
||||||
|
// the time, and re-banding a rule afterwards must not rewrite that.
|
||||||
|
for (final AmlTransactionRule rule : matched) {
|
||||||
|
final Long sourceId = rule.getSourceClientRiskRuleId();
|
||||||
|
alertRuleRepository.save(AmlAlertRule.of(saved, rule.getRuleCode(),
|
||||||
|
sourceId == null ? null : bandBySourceId.get(sourceId), rule == governing));
|
||||||
|
}
|
||||||
|
raised.add(saved);
|
||||||
|
}
|
||||||
|
|
||||||
// Every transaction type funnels through here, so the recurring-behaviour check is done once
|
// Every transaction type funnels through here, so the recurring-behaviour check is done once
|
||||||
// in one place rather than repeated in each of the savings / loan / transfer callers. Passing
|
// in one place rather than repeated in each of the savings / loan / transfer callers. Passing
|
||||||
// the batch size lets the service tell a first-time offender from a repeat one without
|
// the batch size lets the service tell a first-time offender from a repeat one without
|
||||||
@@ -82,6 +162,45 @@ public class AmlRuleEvaluationServiceImpl implements AmlRuleEvaluationService {
|
|||||||
return raised;
|
return raised;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The worst severity band among the rules that matched.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* A transaction rule carries no severity of its own; it inherits the risk category of the
|
||||||
|
* catalog entry it was derived from. Rules with no catalog ancestor - the CTR rules - contribute
|
||||||
|
* nothing, because a statutory return is not a graded suspicion. Null when none of the matched
|
||||||
|
* rules carried a severity at all.
|
||||||
|
*/
|
||||||
|
private Integer highestSeverityOf(final Map<Long, Integer> bandBySourceId) {
|
||||||
|
Integer worst = null;
|
||||||
|
for (final Integer band : bandBySourceId.values()) {
|
||||||
|
if (band != null && (worst == null || band > worst)) {
|
||||||
|
worst = band;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return worst;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Severity of each matched rule's catalog ancestor, keyed on {@code m_client_risk_rule.id}.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Read once and used twice - for the alert's own highest-severity figure and for the per-rule findings written
|
||||||
|
* beneath it - rather than querying the catalog twice for the same rows.
|
||||||
|
*/
|
||||||
|
private Map<Long, Integer> severityBySourceRuleId(final List<AmlTransactionRule> matched) {
|
||||||
|
final List<Long> sourceIds = matched.stream().map(AmlTransactionRule::getSourceClientRiskRuleId).filter(id -> id != null)
|
||||||
|
.distinct().toList();
|
||||||
|
if (sourceIds.isEmpty()) {
|
||||||
|
return Map.of();
|
||||||
|
}
|
||||||
|
final Map<Long, Integer> bandById = new HashMap<>();
|
||||||
|
for (final ClientRiskRule catalogRule : clientRiskRuleRepository.findAllById(sourceIds)) {
|
||||||
|
bandById.put(catalogRule.getId(), catalogRule.getRiskCategory());
|
||||||
|
}
|
||||||
|
return bandById;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isHit(AmlTransactionRule rule, AmlTransactionContext context) {
|
private boolean isHit(AmlTransactionRule rule, AmlTransactionContext context) {
|
||||||
if (!appliesToThisTransaction(rule, context)) {
|
if (!appliesToThisTransaction(rule, context)) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
+38
-1
@@ -20,9 +20,15 @@ package org.apache.fineract.portfolio.aml.service;
|
|||||||
|
|
||||||
import jakarta.persistence.EntityNotFoundException;
|
import jakarta.persistence.EntityNotFoundException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||||
|
import org.apache.fineract.portfolio.aml.domain.AmlAlert;
|
||||||
|
import org.apache.fineract.portfolio.aml.domain.AmlAlertRepository;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlStrCase;
|
import org.apache.fineract.portfolio.aml.domain.AmlStrCase;
|
||||||
|
import org.apache.fineract.portfolio.aml.domain.AmlStrCaseAlert;
|
||||||
|
import org.apache.fineract.portfolio.aml.domain.AmlStrCaseAlertRepository;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlStrCaseRepository;
|
import org.apache.fineract.portfolio.aml.domain.AmlStrCaseRepository;
|
||||||
import org.apache.fineract.portfolio.aml.domain.AmlStrConclusion;
|
import org.apache.fineract.portfolio.aml.domain.AmlStrConclusion;
|
||||||
import org.apache.fineract.useradministration.domain.AppUser;
|
import org.apache.fineract.useradministration.domain.AppUser;
|
||||||
@@ -36,6 +42,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
public class AmlStrCaseWritePlatformServiceImpl implements AmlStrCaseWritePlatformService {
|
public class AmlStrCaseWritePlatformServiceImpl implements AmlStrCaseWritePlatformService {
|
||||||
|
|
||||||
private final AmlStrCaseRepository strCaseRepository;
|
private final AmlStrCaseRepository strCaseRepository;
|
||||||
|
private final AmlStrCaseAlertRepository strCaseAlertRepository;
|
||||||
|
private final AmlAlertRepository alertRepository;
|
||||||
private final AppUserRepository appUserRepository;
|
private final AppUserRepository appUserRepository;
|
||||||
private final PlatformSecurityContext context;
|
private final PlatformSecurityContext context;
|
||||||
private final StrSlaCalculator strSlaCalculator;
|
private final StrSlaCalculator strSlaCalculator;
|
||||||
@@ -58,7 +66,36 @@ public class AmlStrCaseWritePlatformServiceImpl implements AmlStrCaseWritePlatfo
|
|||||||
? strSlaCalculator.calculateFiuDueDate(concludedOn, strCase.getClient().officeId())
|
? strSlaCalculator.calculateFiuDueDate(concludedOn, strCase.getClient().officeId())
|
||||||
: null;
|
: null;
|
||||||
strCase.conclude(principalOfficer, conclusion, investigationNotes, sourceOfFundsNotes, concludedOn, fiuDueDate);
|
strCase.conclude(principalOfficer, conclusion, investigationNotes, sourceOfFundsNotes, concludedOn, fiuDueDate);
|
||||||
return strCaseRepository.save(strCase);
|
final AmlStrCase saved = strCaseRepository.save(strCase);
|
||||||
|
|
||||||
|
// The conclusion is the answer to the referral, so it goes back to the alerts that raised it. A case concluded
|
||||||
|
// clear leaves those transactions reading as suspicious on the AML feed until this runs - the bank would have
|
||||||
|
// decided one thing and the screen an officer works from would say another.
|
||||||
|
final boolean suspicious = conclusion == AmlStrConclusion.SUSPICIOUS;
|
||||||
|
final String note = "Principal Officer concluded " + (suspicious ? "suspicious" : "clear")
|
||||||
|
+ (investigationNotes == null || investigationNotes.isBlank() ? "" : " — " + investigationNotes);
|
||||||
|
for (final AmlAlert alert : alertsOf(saved)) {
|
||||||
|
alert.applyStrConclusion(suspicious, principalOfficer, note);
|
||||||
|
alertRepository.save(alert);
|
||||||
|
}
|
||||||
|
return saved;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Every alert the case covers.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Read from the link table, which holds one row per alert: a pattern case is opened over several alerts, and
|
||||||
|
* concluding it has to answer all of them rather than only the one whose id happens to sit on the case.
|
||||||
|
*/
|
||||||
|
private List<AmlAlert> alertsOf(final AmlStrCase strCase) {
|
||||||
|
final List<AmlAlert> covered = strCaseAlertRepository.findByStrCase_IdOrderByAlert_RaisedOnAsc(strCase.getId()).stream()
|
||||||
|
.map(AmlStrCaseAlert::getAlert).collect(Collectors.toList());
|
||||||
|
// Cases opened before the link table existed carry only alert_id.
|
||||||
|
if (covered.isEmpty() && strCase.getAlert() != null) {
|
||||||
|
covered.add(strCase.getAlert());
|
||||||
|
}
|
||||||
|
return covered;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.portfolio.aml.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moving a customer's KYC risk category, under maker-checker.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* The category decides how often the customer is re-KYC'd and what AML thresholds apply to them, so
|
||||||
|
* raising or lowering one is a decision about how closely the bank watches that customer. It is
|
||||||
|
* raised from the Risk Review Report - which already works out where a rating ought to sit - and
|
||||||
|
* takes effect only when a checker agrees.
|
||||||
|
*/
|
||||||
|
public interface ClientRiskChangeRequestService {
|
||||||
|
|
||||||
|
/** Raised by the reviewer. Nothing moves until a checker approves. */
|
||||||
|
CommandProcessingResult request(Long clientId, Integer requestedCategory, String reason);
|
||||||
|
|
||||||
|
/** Applies the new category to the customer's KYC record and records the change in history. */
|
||||||
|
CommandProcessingResult approve(Long requestId);
|
||||||
|
|
||||||
|
CommandProcessingResult reject(Long requestId, String rejectionReason);
|
||||||
|
|
||||||
|
/** @param status PENDING / APPROVED / REJECTED, or null for all */
|
||||||
|
List<Map<String, Object>> retrieveAll(String status);
|
||||||
|
}
|
||||||
+241
@@ -0,0 +1,241 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.portfolio.aml.service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
|
||||||
|
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
||||||
|
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||||
|
import org.apache.fineract.portfolio.aml.domain.ClientRiskCategoryHistory;
|
||||||
|
import org.apache.fineract.portfolio.aml.domain.ClientRiskCategoryHistoryRepository;
|
||||||
|
import org.apache.fineract.portfolio.client.domain.Client;
|
||||||
|
import org.apache.fineract.portfolio.client.domain.ClientKyc;
|
||||||
|
import org.apache.fineract.portfolio.client.domain.ClientKycRepositoryWrapper;
|
||||||
|
import org.apache.fineract.portfolio.client.domain.ClientRepositoryWrapper;
|
||||||
|
import org.apache.fineract.useradministration.domain.AppUser;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.jdbc.support.GeneratedKeyHolder;
|
||||||
|
import org.springframework.jdbc.support.KeyHolder;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ClientRiskChangeRequestServiceImpl implements ClientRiskChangeRequestService {
|
||||||
|
|
||||||
|
private static final String STATUS_PENDING = "PENDING";
|
||||||
|
private static final String STATUS_APPROVED = "APPROVED";
|
||||||
|
private static final String STATUS_REJECTED = "REJECTED";
|
||||||
|
|
||||||
|
/** KycRiskCategory: 1 Low, 2 Medium, 3 High. */
|
||||||
|
private static final int LOWEST_CATEGORY = 1;
|
||||||
|
private static final int HIGHEST_CATEGORY = 3;
|
||||||
|
|
||||||
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
private final PlatformSecurityContext context;
|
||||||
|
private final ClientRepositoryWrapper clientRepository;
|
||||||
|
private final ClientKycRepositoryWrapper kycRepositoryWrapper;
|
||||||
|
private final ClientRiskCategoryHistoryRepository historyRepository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public CommandProcessingResult request(final Long clientId, final Integer requestedCategory, final String reason) {
|
||||||
|
final AppUser currentUser = this.context.authenticatedUser();
|
||||||
|
|
||||||
|
if (requestedCategory == null || requestedCategory < LOWEST_CATEGORY || requestedCategory > HIGHEST_CATEGORY) {
|
||||||
|
throw new IllegalArgumentException("Requested risk category must be Low (1), Medium (2) or High (3).");
|
||||||
|
}
|
||||||
|
if (reason == null || reason.isBlank()) {
|
||||||
|
throw new IllegalArgumentException("A reason is required to change a customer's risk category.");
|
||||||
|
}
|
||||||
|
|
||||||
|
final Client client = this.clientRepository.findOneWithNotFoundDetection(clientId);
|
||||||
|
final ClientKyc kyc = this.kycRepositoryWrapper.findByClientIdWithNotFoundDetection(clientId);
|
||||||
|
final Integer currentCategory = kyc.getRiskCategoryValue();
|
||||||
|
|
||||||
|
if (requestedCategory.equals(currentCategory)) {
|
||||||
|
throw new IllegalStateException("The customer is already on that risk category.");
|
||||||
|
}
|
||||||
|
if (!this.jdbcTemplate
|
||||||
|
.queryForList("SELECT id FROM m_client_risk_change_request WHERE client_id = ? AND status = 'PENDING'", clientId)
|
||||||
|
.isEmpty()) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"A risk category change is already pending for this customer. Wait for it to be approved or rejected.");
|
||||||
|
}
|
||||||
|
|
||||||
|
final KeyHolder kh = new GeneratedKeyHolder();
|
||||||
|
final LocalDateTime now = LocalDateTime.now(DateUtils.getDateTimeZoneOfTenant());
|
||||||
|
this.jdbcTemplate.update(con -> {
|
||||||
|
final java.sql.PreparedStatement ps = con.prepareStatement(
|
||||||
|
"INSERT INTO m_client_risk_change_request "
|
||||||
|
+ "(client_id, current_category, requested_category, reason, status, maker_id, created_date) "
|
||||||
|
+ "VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||||
|
new String[] { "id" });
|
||||||
|
ps.setLong(1, client.getId());
|
||||||
|
if (currentCategory == null) {
|
||||||
|
ps.setNull(2, java.sql.Types.INTEGER);
|
||||||
|
} else {
|
||||||
|
ps.setInt(2, currentCategory);
|
||||||
|
}
|
||||||
|
ps.setInt(3, requestedCategory);
|
||||||
|
ps.setString(4, reason);
|
||||||
|
ps.setString(5, STATUS_PENDING);
|
||||||
|
ps.setLong(6, currentUser.getId());
|
||||||
|
ps.setObject(7, now);
|
||||||
|
return ps;
|
||||||
|
}, kh);
|
||||||
|
|
||||||
|
return new CommandProcessingResultBuilder().withClientId(client.getId())
|
||||||
|
.withEntityId(Objects.requireNonNull(kh.getKey()).longValue()).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public CommandProcessingResult approve(final Long requestId) {
|
||||||
|
final AppUser currentUser = this.context.authenticatedUser();
|
||||||
|
validateCheckerRole(currentUser);
|
||||||
|
|
||||||
|
final Map<String, Object> request = findRequestOrThrow(requestId);
|
||||||
|
if (!STATUS_PENDING.equals(request.get("status"))) {
|
||||||
|
throw new IllegalStateException("Risk change request is not pending. Current status: " + request.get("status"));
|
||||||
|
}
|
||||||
|
final Long makerId = ((Number) request.get("maker_id")).longValue();
|
||||||
|
if (makerId.equals(currentUser.getId()) && !currentUser.hasAnyPermission("ALL_FUNCTIONS")) {
|
||||||
|
throw new IllegalStateException("You cannot approve your own risk category change.");
|
||||||
|
}
|
||||||
|
|
||||||
|
final Long clientId = ((Number) request.get("client_id")).longValue();
|
||||||
|
final Integer requestedCategory = ((Number) request.get("requested_category")).intValue();
|
||||||
|
|
||||||
|
final Client client = this.clientRepository.findOneWithNotFoundDetection(clientId);
|
||||||
|
final ClientKyc kyc = this.kycRepositoryWrapper.findByClientIdWithNotFoundDetection(clientId);
|
||||||
|
|
||||||
|
// Read again rather than trusted from the request: the rating may have moved since - an AML
|
||||||
|
// auto-escalation on the customer's third STR case does exactly that - and the history has
|
||||||
|
// to record where it actually moved from.
|
||||||
|
final Integer previousCategory = kyc.getRiskCategoryValue();
|
||||||
|
if (requestedCategory.equals(previousCategory)) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"The customer is already on the requested risk category; the rating moved after this request was raised.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Moves the re-KYC due date onto the new category's cycle as well: a customer rated higher
|
||||||
|
// is called back in sooner, which is most of what the rating is for.
|
||||||
|
kyc.escalateRiskCategory(requestedCategory);
|
||||||
|
this.kycRepositoryWrapper.saveAndFlush(kyc);
|
||||||
|
|
||||||
|
final LocalDateTime now = LocalDateTime.now(DateUtils.getDateTimeZoneOfTenant());
|
||||||
|
this.historyRepository.save(ClientRiskCategoryHistory.manual(client, previousCategory, requestedCategory,
|
||||||
|
(String) request.get("reason"), currentUser, now));
|
||||||
|
|
||||||
|
this.jdbcTemplate.update(
|
||||||
|
"UPDATE m_client_risk_change_request SET status = ?, checker_id = ?, checker_date = ? WHERE id = ?",
|
||||||
|
STATUS_APPROVED, currentUser.getId(), now, requestId);
|
||||||
|
|
||||||
|
return new CommandProcessingResultBuilder().withClientId(clientId).withEntityId(requestId).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public CommandProcessingResult reject(final Long requestId, final String rejectionReason) {
|
||||||
|
final AppUser currentUser = this.context.authenticatedUser();
|
||||||
|
validateCheckerRole(currentUser);
|
||||||
|
|
||||||
|
final Map<String, Object> request = findRequestOrThrow(requestId);
|
||||||
|
if (!STATUS_PENDING.equals(request.get("status"))) {
|
||||||
|
throw new IllegalStateException("Risk change request is not pending. Current status: " + request.get("status"));
|
||||||
|
}
|
||||||
|
final Long makerId = ((Number) request.get("maker_id")).longValue();
|
||||||
|
if (makerId.equals(currentUser.getId()) && !currentUser.hasAnyPermission("ALL_FUNCTIONS")) {
|
||||||
|
throw new IllegalStateException("You cannot reject your own risk category change.");
|
||||||
|
}
|
||||||
|
|
||||||
|
final LocalDateTime now = LocalDateTime.now(DateUtils.getDateTimeZoneOfTenant());
|
||||||
|
this.jdbcTemplate.update(
|
||||||
|
"UPDATE m_client_risk_change_request SET status = ?, checker_id = ?, checker_date = ?, rejection_reason = ? "
|
||||||
|
+ "WHERE id = ?",
|
||||||
|
STATUS_REJECTED, currentUser.getId(), now, rejectionReason, requestId);
|
||||||
|
|
||||||
|
return new CommandProcessingResultBuilder().withEntityId(requestId).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Map<String, Object>> retrieveAll(final String status) {
|
||||||
|
final StringBuilder sql = new StringBuilder("""
|
||||||
|
SELECT r.id AS "id",
|
||||||
|
r.client_id AS "clientId",
|
||||||
|
c.display_name AS "clientName",
|
||||||
|
c.account_no AS "cifNumber",
|
||||||
|
o.name AS "officeName",
|
||||||
|
r.current_category AS "currentCategory",
|
||||||
|
r.requested_category AS "requestedCategory",
|
||||||
|
r.reason AS "reason",
|
||||||
|
r.status AS "status",
|
||||||
|
maker.username AS "makerUsername",
|
||||||
|
to_char(r.created_date, 'YYYY-MM-DD HH24:MI') AS "createdDate",
|
||||||
|
checker.username AS "checkerUsername",
|
||||||
|
to_char(r.checker_date, 'YYYY-MM-DD HH24:MI') AS "checkerDate",
|
||||||
|
r.rejection_reason AS "rejectionReason"
|
||||||
|
FROM m_client_risk_change_request r
|
||||||
|
JOIN m_client c ON c.id = r.client_id
|
||||||
|
LEFT JOIN m_office o ON o.id = c.office_id
|
||||||
|
JOIN m_appuser maker ON maker.id = r.maker_id
|
||||||
|
LEFT JOIN m_appuser checker ON checker.id = r.checker_id
|
||||||
|
WHERE 1 = 1
|
||||||
|
""");
|
||||||
|
final List<Object> args = new ArrayList<>();
|
||||||
|
if (status != null && !status.isBlank()) {
|
||||||
|
sql.append(" AND r.status = ? ");
|
||||||
|
args.add(status);
|
||||||
|
}
|
||||||
|
sql.append(" ORDER BY r.id DESC ");
|
||||||
|
return this.jdbcTemplate.queryForList(sql.toString(), args.toArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> findRequestOrThrow(final Long requestId) {
|
||||||
|
final List<Map<String, Object>> rows = this.jdbcTemplate
|
||||||
|
.queryForList("SELECT * FROM m_client_risk_change_request WHERE id = ?", requestId);
|
||||||
|
if (rows.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Risk category change request not found.");
|
||||||
|
}
|
||||||
|
return rows.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The same checker rule the rest of the AML module uses: a rating change is a compliance
|
||||||
|
* decision, so it is approved by a manager rather than by whoever happens to be at the screen.
|
||||||
|
*/
|
||||||
|
private void validateCheckerRole(final AppUser user) {
|
||||||
|
if (user.hasAnyPermission("ALL_FUNCTIONS")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final boolean isChecker = user.getRoles().stream().map(r -> r.getName() == null ? "" : r.getName().toLowerCase().trim())
|
||||||
|
.anyMatch(n -> n.contains("manager") || n.contains("principal officer") || n.contains("compliance"));
|
||||||
|
if (!isChecker) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Only a Bank Manager, Compliance Officer or Principal Officer can approve or reject a risk category change.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+13
-3
@@ -68,6 +68,15 @@ public class JournalEntryReferralServiceImpl implements JournalEntryReferralServ
|
|||||||
* The transaction-id columns are kept as a fallback for entries that carry one but no entity. A purely manual GL
|
* The transaction-id columns are kept as a fallback for entries that carry one but no entity. A purely manual GL
|
||||||
* posting reaches none of these and comes back with a null clientId, which is what makes it unreferrable.
|
* posting reaches none of these and comes back with a null clientId, which is what makes it unreferrable.
|
||||||
*/
|
*/
|
||||||
|
// m_savings_account and m_current_account each keep their own identity sequence, so the same
|
||||||
|
// entity_id can be a real row in both -- entity_type_enum=2 (PortfolioProductType.SAVING) used to
|
||||||
|
// be written for both savings and current-account entries alike, so esa/eca could both match the
|
||||||
|
// same id and a plain COALESCE(esa.client_id, eca.client_id) would attribute an alert to whichever
|
||||||
|
// client happened to hold the same-numbered account on the OTHER ledger -- exactly the kind of
|
||||||
|
// misattribution an AML referral cannot afford. entity_type_enum=6 (PortfolioProductType.CURRENT)
|
||||||
|
// is what newer write paths tag current-account entries with instead, unambiguously; for older
|
||||||
|
// entries still tagged 2, savings_transaction_id is the one reliable signal (only a genuine
|
||||||
|
// savings transaction sets it), checked before the ambiguous current/savings guess.
|
||||||
private static final String RESOLVE_SQL = """
|
private static final String RESOLVE_SQL = """
|
||||||
SELECT je.amount AS amount,
|
SELECT je.amount AS amount,
|
||||||
je.currency_code AS currencyCode,
|
je.currency_code AS currencyCode,
|
||||||
@@ -75,8 +84,9 @@ public class JournalEntryReferralServiceImpl implements JournalEntryReferralServ
|
|||||||
je.loan_transaction_id AS loanTxnId,
|
je.loan_transaction_id AS loanTxnId,
|
||||||
je.entity_type_enum AS entityType,
|
je.entity_type_enum AS entityType,
|
||||||
COALESCE(
|
COALESCE(
|
||||||
esa.client_id,
|
CASE WHEN je.entity_type_enum = 2 AND je.savings_transaction_id IS NOT NULL THEN sa.client_id END,
|
||||||
eca.client_id,
|
CASE WHEN je.entity_type_enum = 6 THEN eca.client_id END,
|
||||||
|
CASE WHEN je.entity_type_enum = 2 THEN COALESCE(eca.client_id, esa.client_id) END,
|
||||||
eloan.client_id,
|
eloan.client_id,
|
||||||
CASE WHEN je.entity_type_enum = 5 THEN je.entity_id END,
|
CASE WHEN je.entity_type_enum = 5 THEN je.entity_id END,
|
||||||
sa.client_id,
|
sa.client_id,
|
||||||
@@ -85,7 +95,7 @@ public class JournalEntryReferralServiceImpl implements JournalEntryReferralServ
|
|||||||
) AS clientId
|
) AS clientId
|
||||||
FROM acc_gl_journal_entry je
|
FROM acc_gl_journal_entry je
|
||||||
LEFT JOIN m_savings_account esa ON esa.id = je.entity_id AND je.entity_type_enum = 2
|
LEFT JOIN m_savings_account esa ON esa.id = je.entity_id AND je.entity_type_enum = 2
|
||||||
LEFT JOIN m_current_account eca ON eca.id = je.entity_id AND je.entity_type_enum = 2
|
LEFT JOIN m_current_account eca ON eca.id = je.entity_id AND je.entity_type_enum IN (2, 6)
|
||||||
LEFT JOIN m_loan eloan ON eloan.id = je.entity_id AND je.entity_type_enum = 1
|
LEFT JOIN m_loan eloan ON eloan.id = je.entity_id AND je.entity_type_enum = 1
|
||||||
LEFT JOIN m_savings_account_transaction sat ON sat.id = je.savings_transaction_id
|
LEFT JOIN m_savings_account_transaction sat ON sat.id = je.savings_transaction_id
|
||||||
LEFT JOIN m_savings_account sa ON sa.id = sat.savings_account_id
|
LEFT JOIN m_savings_account sa ON sa.id = sat.savings_account_id
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user