Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
37c961f713 |
@@ -1,68 +0,0 @@
|
||||
-- Removes the duplicate vouchers left behind by the double-count bug.
|
||||
--
|
||||
-- Until 2026-09-03 the cashier deposit and clerk withdrawal registers did not wrap their inner
|
||||
-- savings command in VoucherService.withOwnVoucher(...), so one counter transaction raised two
|
||||
-- vouchers over the same money: the register's own (CASHIER_DEPOSIT_REQUEST / CLERK_WITHDRAWAL_
|
||||
-- REQUEST) and a second one from the savings command (SAVINGS_TRANSACTION). The cashier's Received
|
||||
-- and Payment reports counted both, doubling the day's cash.
|
||||
--
|
||||
-- The code is fixed, so no new duplicates are created. This clears the ones already recorded.
|
||||
--
|
||||
-- WHICH ONE IS DELETED: the SAVINGS_TRANSACTION voucher. The register's voucher is the keeper --
|
||||
-- it is the one the register owns, attaches its DR/CR lines to, and stamps onto
|
||||
-- m_savings_account_transaction.voucher_no. Deleting the register's voucher instead would break
|
||||
-- that link and orphan the request row.
|
||||
--
|
||||
-- Run: psql -h localhost -U postgres -d fineract_default -v ON_ERROR_STOP=1 -f cleanup_duplicate_vouchers.sql
|
||||
|
||||
BEGIN;
|
||||
|
||||
-- The duplicates: a SAVINGS_TRANSACTION voucher whose transaction is already claimed by a
|
||||
-- register voucher. Matching through savings_txn_id rather than by date or amount so that two
|
||||
-- genuinely separate transactions of the same value on the same day are never confused.
|
||||
CREATE TEMP TABLE dup_vouchers ON COMMIT DROP AS
|
||||
SELECT sav.voucher_no
|
||||
FROM m_voucher sav
|
||||
JOIN m_voucher reg
|
||||
ON reg.savings_txn_id = sav.reference_id
|
||||
AND reg.reference_type IN ('CLERK_WITHDRAWAL_REQUEST', 'CASHIER_DEPOSIT_REQUEST')
|
||||
WHERE sav.reference_type = 'SAVINGS_TRANSACTION'
|
||||
AND sav.voucher_type IN ('DEPOSIT', 'WITHDRAWAL');
|
||||
|
||||
-- Refuse to run if anything else has attached itself to a voucher about to be deleted: a
|
||||
-- verification or an attachment means someone acted on that slip, and it must be looked at by hand
|
||||
-- rather than removed silently.
|
||||
DO $$
|
||||
DECLARE
|
||||
blocked INT;
|
||||
BEGIN
|
||||
SELECT COUNT(*) INTO blocked
|
||||
FROM (SELECT voucher_no FROM m_voucher_verification
|
||||
WHERE voucher_no IN (SELECT voucher_no FROM dup_vouchers)
|
||||
UNION ALL
|
||||
SELECT voucher_no FROM m_voucher_attachment
|
||||
WHERE voucher_no IN (SELECT voucher_no FROM dup_vouchers)) x;
|
||||
IF blocked > 0 THEN
|
||||
RAISE EXCEPTION 'Aborting: % duplicate voucher(s) carry a verification or attachment. Review these by hand.', blocked;
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- Likewise refuse if a savings transaction is stamped with a voucher about to be deleted. It should
|
||||
-- carry the register's number, not the duplicate's; if it does not, the pair needs looking at.
|
||||
DO $$
|
||||
DECLARE
|
||||
stamped INT;
|
||||
BEGIN
|
||||
SELECT COUNT(*) INTO stamped FROM m_savings_account_transaction
|
||||
WHERE voucher_no IN (SELECT voucher_no FROM dup_vouchers);
|
||||
IF stamped > 0 THEN
|
||||
RAISE EXCEPTION 'Aborting: % savings transaction(s) are stamped with a duplicate voucher number.', stamped;
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
SELECT voucher_no AS "about to delete" FROM dup_vouchers ORDER BY voucher_no;
|
||||
|
||||
DELETE FROM m_voucher_line WHERE voucher_no IN (SELECT voucher_no FROM dup_vouchers);
|
||||
DELETE FROM m_voucher WHERE voucher_no IN (SELECT voucher_no FROM dup_vouchers);
|
||||
|
||||
COMMIT;
|
||||
@@ -127,6 +127,14 @@ SELECT 'Inter-Bank Cap Charge', 'INR', 0.00, 2, 3, 1, 0, 1, 0, 0, 0,
|
||||
(SELECT id FROM acc_gl_account WHERE classification_enum = 4 AND usage_enum = 1 AND disabled = 0 ORDER BY id LIMIT 1)
|
||||
WHERE NOT EXISTS (SELECT 1 FROM m_charge WHERE name = 'Inter-Bank Cap Charge' AND is_deleted = 0);
|
||||
|
||||
INSERT IGNORE INTO m_charge
|
||||
(name, currency_code, amount, charge_applies_to_enum, charge_time_enum,
|
||||
charge_calculation_enum, is_penalty, is_active, is_deleted,
|
||||
is_free_withdrawal, is_payment_type, income_or_liability_account_id)
|
||||
SELECT 'Withdrawal Facility Charge', 'INR', 5.00, 2, 3, 1, 0, 1, 0, 0, 0,
|
||||
(SELECT id FROM acc_gl_account WHERE classification_enum = 4 AND usage_enum = 1 AND disabled = 0 ORDER BY id LIMIT 1)
|
||||
WHERE NOT EXISTS (SELECT 1 FROM m_charge WHERE name = 'Withdrawal Facility Charge' AND is_deleted = 0);
|
||||
|
||||
INSERT IGNORE INTO m_charge
|
||||
(name, currency_code, amount, charge_applies_to_enum, charge_time_enum,
|
||||
charge_calculation_enum, is_penalty, is_active, is_deleted,
|
||||
@@ -160,5 +168,6 @@ VALUES
|
||||
('NEFT_FACILITY', 'NEFT Facility Charge', 5.00, 3, 2, (SELECT id FROM m_charge WHERE name = 'NEFT Facility Charge' AND is_deleted = 0 LIMIT 1)),
|
||||
('RTGS_FACILITY', 'RTGS Facility Charge', 25.00, 3, 2, (SELECT id FROM m_charge WHERE name = 'RTGS Facility Charge' AND is_deleted = 0 LIMIT 1)),
|
||||
('INTER_BANK_TOTAL_CAP','Inter-Bank Cap Charge', 0.00, 3, 2, (SELECT id FROM m_charge WHERE name = 'Inter-Bank Cap Charge' AND is_deleted = 0 LIMIT 1)),
|
||||
('WITHDRAWAL_FACILITY', 'Withdrawal Facility Charge', 5.00, 3, 2, (SELECT id FROM m_charge WHERE name = 'Withdrawal Facility Charge' AND is_deleted = 0 LIMIT 1)),
|
||||
('DEPOSIT_FACILITY_KYC','Deposit KYC Charge', 5.00, 3, 2, (SELECT id FROM m_charge WHERE name = 'Deposit KYC Charge' AND is_deleted = 0 LIMIT 1)),
|
||||
('VIRTUAL_DEBIT_CARD', 'Virtual Debit Card Charge', 199.00, 3, 2, (SELECT id FROM m_charge WHERE name = 'Virtual Debit Card Charge' AND is_deleted = 0 LIMIT 1));
|
||||
|
||||
@@ -17,6 +17,7 @@ ALTER TABLE m_current_product_facility_config
|
||||
ADD COLUMN IF NOT EXISTS neft_facility_charge_id BIGINT NULL,
|
||||
ADD COLUMN IF NOT EXISTS rtgs_facility_charge_id BIGINT NULL,
|
||||
ADD COLUMN IF NOT EXISTS inter_bank_total_cap_charge_id BIGINT NULL,
|
||||
ADD COLUMN IF NOT EXISTS withdrawal_facility_charge_id BIGINT NULL,
|
||||
ADD COLUMN IF NOT EXISTS deposit_facility_kyc_charge_id BIGINT NULL,
|
||||
ADD COLUMN IF NOT EXISTS virtual_debit_card_charge_id BIGINT NULL;
|
||||
|
||||
@@ -35,6 +36,7 @@ ALTER TABLE m_current_product_facility_config
|
||||
ADD CONSTRAINT fk_cpfc_neft_charge FOREIGN KEY (neft_facility_charge_id) REFERENCES m_charge(id),
|
||||
ADD CONSTRAINT fk_cpfc_rtgs_charge FOREIGN KEY (rtgs_facility_charge_id) REFERENCES m_charge(id),
|
||||
ADD CONSTRAINT fk_cpfc_ibtc_charge FOREIGN KEY (inter_bank_total_cap_charge_id) REFERENCES m_charge(id),
|
||||
ADD CONSTRAINT fk_cpfc_wd_charge FOREIGN KEY (withdrawal_facility_charge_id) REFERENCES m_charge(id),
|
||||
ADD CONSTRAINT fk_cpfc_dep_charge FOREIGN KEY (deposit_facility_kyc_charge_id) REFERENCES m_charge(id),
|
||||
ADD CONSTRAINT fk_cpfc_vdc_charge FOREIGN KEY (virtual_debit_card_charge_id) REFERENCES m_charge(id);
|
||||
|
||||
@@ -53,6 +55,7 @@ ALTER TABLE m_savings_product_facility_config
|
||||
ADD COLUMN IF NOT EXISTS neft_facility_charge_id BIGINT NULL,
|
||||
ADD COLUMN IF NOT EXISTS rtgs_facility_charge_id BIGINT NULL,
|
||||
ADD COLUMN IF NOT EXISTS inter_bank_total_cap_charge_id BIGINT NULL,
|
||||
ADD COLUMN IF NOT EXISTS withdrawal_facility_charge_id BIGINT NULL,
|
||||
ADD COLUMN IF NOT EXISTS deposit_facility_kyc_charge_id BIGINT NULL,
|
||||
ADD COLUMN IF NOT EXISTS virtual_debit_card_charge_id BIGINT NULL;
|
||||
|
||||
@@ -71,5 +74,6 @@ ALTER TABLE m_savings_product_facility_config
|
||||
ADD CONSTRAINT fk_spfc_neft_charge FOREIGN KEY (neft_facility_charge_id) REFERENCES m_charge(id),
|
||||
ADD CONSTRAINT fk_spfc_rtgs_charge FOREIGN KEY (rtgs_facility_charge_id) REFERENCES m_charge(id),
|
||||
ADD CONSTRAINT fk_spfc_ibtc_charge FOREIGN KEY (inter_bank_total_cap_charge_id) REFERENCES m_charge(id),
|
||||
ADD CONSTRAINT fk_spfc_wd_charge FOREIGN KEY (withdrawal_facility_charge_id) REFERENCES m_charge(id),
|
||||
ADD CONSTRAINT fk_spfc_dep_charge FOREIGN KEY (deposit_facility_kyc_charge_id) REFERENCES m_charge(id),
|
||||
ADD CONSTRAINT fk_spfc_vdc_charge FOREIGN KEY (virtual_debit_card_charge_id) REFERENCES m_charge(id);
|
||||
|
||||
+9
-20
@@ -45,22 +45,6 @@ public final class FinancialActivityAccountDataValidator {
|
||||
*/
|
||||
private final Set<String> supportedParameters = FinancialActivityAccountsJsonInputParams.getAllValues();
|
||||
|
||||
/**
|
||||
* Activities an administrator may map from the Financial Activity Mappings screen.
|
||||
*
|
||||
* Held in one place because create and update both validate against it, and the two lists had already drifted -
|
||||
* update omitted the two cash activities, and neither offered the dividend activities beyond PAYABLE_DIVIDENDS even
|
||||
* though the accounting code reads them. An activity the posting code resolves but this list omits can only ever be
|
||||
* seeded by a migration, which is how DIVIDEND_PAID and RESERVE_FOR_DIVIDEND came to exist without being editable.
|
||||
*/
|
||||
private static final Object[] MAPPABLE_FINANCIAL_ACTIVITIES = { FinancialActivity.ASSET_TRANSFER.getValue(),
|
||||
FinancialActivity.LIABILITY_TRANSFER.getValue(), FinancialActivity.CASH_AT_MAINVAULT.getValue(),
|
||||
FinancialActivity.CASH_AT_TELLER.getValue(), FinancialActivity.OPENING_BALANCES_TRANSFER_CONTRA.getValue(),
|
||||
FinancialActivity.ASSET_FUND_SOURCE.getValue(), FinancialActivity.PAYABLE_DIVIDENDS.getValue(),
|
||||
FinancialActivity.DIVIDEND_PAID.getValue(), FinancialActivity.RESERVE_FOR_DIVIDEND.getValue(),
|
||||
FinancialActivity.DIVIDEND_FORFEITED_INCOME.getValue(), FinancialActivity.DISTRIBUTABLE_PROFIT.getValue(),
|
||||
FinancialActivity.RETAINED_PROFIT.getValue(), FinancialActivity.DIVIDEND_ROUND_OFF.getValue() };
|
||||
|
||||
private final String paramNameForFinancialActivity = FinancialActivityAccountsJsonInputParams.FINANCIAL_ACTIVITY_ID.getValue();
|
||||
private final String paramNameForGLAccount = FinancialActivityAccountsJsonInputParams.GL_ACCOUNT_ID.getValue();
|
||||
|
||||
@@ -75,8 +59,11 @@ public final class FinancialActivityAccountDataValidator {
|
||||
final JsonElement element = this.fromApiJsonHelper.parse(json);
|
||||
|
||||
final Integer financialActivityId = this.fromApiJsonHelper.extractIntegerSansLocaleNamed(paramNameForFinancialActivity, element);
|
||||
baseDataValidator.reset().parameter(paramNameForFinancialActivity).value(financialActivityId).notNull()
|
||||
.isOneOfTheseValues(MAPPABLE_FINANCIAL_ACTIVITIES);
|
||||
baseDataValidator.reset().parameter(paramNameForFinancialActivity).value(financialActivityId).notNull().isOneOfTheseValues(
|
||||
FinancialActivity.ASSET_TRANSFER.getValue(), FinancialActivity.LIABILITY_TRANSFER.getValue(),
|
||||
FinancialActivity.CASH_AT_MAINVAULT.getValue(), FinancialActivity.CASH_AT_TELLER.getValue(),
|
||||
FinancialActivity.OPENING_BALANCES_TRANSFER_CONTRA.getValue(), FinancialActivity.ASSET_FUND_SOURCE.getValue(),
|
||||
FinancialActivity.PAYABLE_DIVIDENDS.getValue());
|
||||
|
||||
final Long glAccountId = this.fromApiJsonHelper.extractLongNamed(paramNameForGLAccount, element);
|
||||
baseDataValidator.reset().parameter(paramNameForGLAccount).value(glAccountId).notNull().integerGreaterThanZero();
|
||||
@@ -99,8 +86,10 @@ public final class FinancialActivityAccountDataValidator {
|
||||
if (this.fromApiJsonHelper.parameterExists(paramNameForFinancialActivity, element)) {
|
||||
final Integer financialActivityId = this.fromApiJsonHelper.extractIntegerSansLocaleNamed(paramNameForFinancialActivity,
|
||||
element);
|
||||
baseDataValidator.reset().parameter(paramNameForFinancialActivity).value(financialActivityId).ignoreIfNull()
|
||||
.isOneOfTheseValues(MAPPABLE_FINANCIAL_ACTIVITIES);
|
||||
baseDataValidator.reset().parameter(paramNameForFinancialActivity).value(financialActivityId).ignoreIfNull().isOneOfTheseValues(
|
||||
FinancialActivity.ASSET_TRANSFER.getValue(), FinancialActivity.LIABILITY_TRANSFER.getValue(),
|
||||
FinancialActivity.OPENING_BALANCES_TRANSFER_CONTRA.getValue(), FinancialActivity.ASSET_FUND_SOURCE.getValue(),
|
||||
FinancialActivity.PAYABLE_DIVIDENDS.getValue());
|
||||
}
|
||||
|
||||
if (this.fromApiJsonHelper.parameterExists(paramNameForGLAccount, element)) {
|
||||
|
||||
-5
@@ -37,7 +37,6 @@ public class JournalEntryInvalidException extends AbstractPlatformDomainRuleExce
|
||||
DEBIT_CREDIT_ACCOUNT_OR_AMOUNT_EMPTY, //
|
||||
GL_ACCOUNT_DISABLED, //
|
||||
GL_ACCOUNT_MANUAL_ENTRIES_NOT_PERMITTED, //
|
||||
GL_ACCOUNT_IS_HEADER, //
|
||||
INVALID_DEBIT_OR_CREDIT_ACCOUNTS; //
|
||||
|
||||
public String errorMessage() {
|
||||
@@ -59,8 +58,6 @@ public class JournalEntryInvalidException extends AbstractPlatformDomainRuleExce
|
||||
return "Invalid debit or credit accounts are passed";
|
||||
} else if (name().equalsIgnoreCase("GL_ACCOUNT_MANUAL_ENTRIES_NOT_PERMITTED")) {
|
||||
return "Target account does not allow manual adjustments";
|
||||
} else if (name().equalsIgnoreCase("GL_ACCOUNT_IS_HEADER")) {
|
||||
return "Target account is a Header account (a chart-of-accounts grouping node) and cannot receive a transaction directly";
|
||||
}
|
||||
return name();
|
||||
}
|
||||
@@ -82,8 +79,6 @@ public class JournalEntryInvalidException extends AbstractPlatformDomainRuleExce
|
||||
return "error.msg.glJournalEntry.invalid.debit.or.credit.accounts";
|
||||
} else if (name().equalsIgnoreCase("GL_ACCOUNT_MANUAL_ENTRIES_NOT_PERMITTED")) {
|
||||
return "error.msg.glJournalEntry.invalid.account.manual.adjustments.not.permitted";
|
||||
} else if (name().equalsIgnoreCase("GL_ACCOUNT_IS_HEADER")) {
|
||||
return "error.msg.glJournalEntry.invalid.account.is.header";
|
||||
}
|
||||
return name();
|
||||
}
|
||||
|
||||
+17
-36
@@ -181,14 +181,10 @@ public final class ProductToGLAccountMappingFromApiJsonDeserializer {
|
||||
baseDataValidator.reset().parameter(SavingProductAccountingParams.SAVINGS_REFERENCE.getValue()).value(savingsReferenceAccountId)
|
||||
.notNull().integerGreaterThanZero();
|
||||
|
||||
// Transfers In Suspense is not offered by every savings product UI, so it is validated only
|
||||
// when the client actually sends it. Omitting it leaves the mapping unset rather than failing.
|
||||
if (this.fromApiJsonHelper.parameterExists(SavingProductAccountingParams.TRANSFERS_SUSPENSE.getValue(), element)) {
|
||||
final Long transfersInSuspenseAccountId = this.fromApiJsonHelper
|
||||
.extractLongNamed(SavingProductAccountingParams.TRANSFERS_SUSPENSE.getValue(), element);
|
||||
baseDataValidator.reset().parameter(SavingProductAccountingParams.TRANSFERS_SUSPENSE.getValue())
|
||||
.value(transfersInSuspenseAccountId).notNull().integerGreaterThanZero();
|
||||
}
|
||||
final Long transfersInSuspenseAccountId = this.fromApiJsonHelper
|
||||
.extractLongNamed(SavingProductAccountingParams.TRANSFERS_SUSPENSE.getValue(), element);
|
||||
baseDataValidator.reset().parameter(SavingProductAccountingParams.TRANSFERS_SUSPENSE.getValue())
|
||||
.value(transfersInSuspenseAccountId).notNull().integerGreaterThanZero();
|
||||
|
||||
final Long interestOnSavingsAccountId = this.fromApiJsonHelper
|
||||
.extractLongNamed(SavingProductAccountingParams.INTEREST_ON_SAVINGS.getValue(), element);
|
||||
@@ -214,29 +210,20 @@ public final class ProductToGLAccountMappingFromApiJsonDeserializer {
|
||||
}
|
||||
|
||||
if (!accountType.equals(DepositAccountType.RECURRING_DEPOSIT) && !accountType.equals(DepositAccountType.FIXED_DEPOSIT)) {
|
||||
// Overdraft Control / Income From Interest / Write Off apply to overdraft-capable products
|
||||
// only, so they are validated when supplied rather than demanded from every savings product.
|
||||
if (this.fromApiJsonHelper.parameterExists(SavingProductAccountingParams.OVERDRAFT_PORTFOLIO_CONTROL.getValue(),
|
||||
element)) {
|
||||
final Long overdraftAccount = this.fromApiJsonHelper
|
||||
.extractLongNamed(SavingProductAccountingParams.OVERDRAFT_PORTFOLIO_CONTROL.getValue(), element);
|
||||
baseDataValidator.reset().parameter(SavingProductAccountingParams.OVERDRAFT_PORTFOLIO_CONTROL.getValue())
|
||||
.value(overdraftAccount).notNull().integerGreaterThanZero();
|
||||
}
|
||||
final Long overdraftAccount = this.fromApiJsonHelper
|
||||
.extractLongNamed(SavingProductAccountingParams.OVERDRAFT_PORTFOLIO_CONTROL.getValue(), element);
|
||||
baseDataValidator.reset().parameter(SavingProductAccountingParams.OVERDRAFT_PORTFOLIO_CONTROL.getValue())
|
||||
.value(overdraftAccount).notNull().integerGreaterThanZero();
|
||||
|
||||
if (this.fromApiJsonHelper.parameterExists(SavingProductAccountingParams.INCOME_FROM_INTEREST.getValue(), element)) {
|
||||
final Long incomeFromInterest = this.fromApiJsonHelper
|
||||
.extractLongNamed(SavingProductAccountingParams.INCOME_FROM_INTEREST.getValue(), element);
|
||||
baseDataValidator.reset().parameter(SavingProductAccountingParams.INCOME_FROM_INTEREST.getValue())
|
||||
.value(incomeFromInterest).notNull().integerGreaterThanZero();
|
||||
}
|
||||
final Long incomeFromInterest = this.fromApiJsonHelper
|
||||
.extractLongNamed(SavingProductAccountingParams.INCOME_FROM_INTEREST.getValue(), element);
|
||||
baseDataValidator.reset().parameter(SavingProductAccountingParams.INCOME_FROM_INTEREST.getValue()).value(incomeFromInterest)
|
||||
.notNull().integerGreaterThanZero();
|
||||
|
||||
if (this.fromApiJsonHelper.parameterExists(SavingProductAccountingParams.LOSSES_WRITTEN_OFF.getValue(), element)) {
|
||||
final Long writtenOff = this.fromApiJsonHelper
|
||||
.extractLongNamed(SavingProductAccountingParams.LOSSES_WRITTEN_OFF.getValue(), element);
|
||||
baseDataValidator.reset().parameter(SavingProductAccountingParams.LOSSES_WRITTEN_OFF.getValue()).value(writtenOff)
|
||||
.notNull().integerGreaterThanZero();
|
||||
}
|
||||
final Long writtenOff = this.fromApiJsonHelper.extractLongNamed(SavingProductAccountingParams.LOSSES_WRITTEN_OFF.getValue(),
|
||||
element);
|
||||
baseDataValidator.reset().parameter(SavingProductAccountingParams.LOSSES_WRITTEN_OFF.getValue()).value(writtenOff).notNull()
|
||||
.integerGreaterThanZero();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -279,15 +266,9 @@ public final class ProductToGLAccountMappingFromApiJsonDeserializer {
|
||||
|
||||
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(),
|
||||
element);
|
||||
baseDataValidator.reset().parameter(SharesProductAccountingParams.SHARES_REFERENCE.getValue()).value(shareReferenceId)
|
||||
baseDataValidator.reset().parameter(SharesProductAccountingParams.SHARES_REFERENCE.getValue()).value(shareReferenceId).notNull()
|
||||
.integerGreaterThanZero();
|
||||
|
||||
final Long shareSuspenseId = this.fromApiJsonHelper.extractLongNamed(SharesProductAccountingParams.SHARES_SUSPENSE.getValue(),
|
||||
|
||||
-4
@@ -426,8 +426,6 @@ public class ProductToGLAccountMappingReadPlatformServiceImpl implements Product
|
||||
accountMappingDetails.put(SavingProductAccountingDataParams.INCOME_FROM_INTEREST.getValue(), glAccountData);
|
||||
} else if (glAccountForSavings.equals(AccrualAccountsForSavings.ESCHEAT_LIABILITY)) {
|
||||
accountMappingDetails.put(SavingProductAccountingDataParams.ESCHEAT_LIABILITY.getValue(), glAccountData);
|
||||
} else if (glAccountForSavings.equals(AccrualAccountsForSavings.ROUNDING_ADJUSTMENT)) {
|
||||
accountMappingDetails.put(SavingProductAccountingDataParams.ROUNDING_ADJUSTMENT.getValue(), glAccountData);
|
||||
// Expense
|
||||
} else if (glAccountForSavings.equals(AccrualAccountsForSavings.INTEREST_ON_SAVINGS)) {
|
||||
accountMappingDetails.put(SavingProductAccountingDataParams.INTEREST_ON_SAVINGS.getValue(), glAccountData);
|
||||
@@ -472,8 +470,6 @@ public class ProductToGLAccountMappingReadPlatformServiceImpl implements Product
|
||||
accountMappingDetails.put(SavingProductAccountingDataParams.INCOME_FROM_INTEREST.getValue(), glAccountData);
|
||||
} else if (glAccountForSavings.equals(CashAccountsForSavings.ESCHEAT_LIABILITY)) {
|
||||
accountMappingDetails.put(SavingProductAccountingDataParams.ESCHEAT_LIABILITY.getValue(), glAccountData);
|
||||
} else if (glAccountForSavings.equals(CashAccountsForSavings.ROUNDING_ADJUSTMENT)) {
|
||||
accountMappingDetails.put(SavingProductAccountingDataParams.ROUNDING_ADJUSTMENT.getValue(), glAccountData);
|
||||
// Expense
|
||||
} else if (glAccountForSavings.equals(CashAccountsForSavings.INTEREST_ON_SAVINGS)) {
|
||||
accountMappingDetails.put(SavingProductAccountingDataParams.INTEREST_ON_SAVINGS.getValue(), glAccountData);
|
||||
|
||||
-18
@@ -106,20 +106,6 @@ public class SavingsProductToGLAccountMappingHelper extends ProductToGLAccountMa
|
||||
PortfolioProductType.SAVING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create-or-merge, for an expense row a product may not have yet.
|
||||
*
|
||||
* The plain merge variant assumes the mapping already exists, which is true of every expense
|
||||
* row that shipped with the product screen. A row added later — the rounding adjustment — is
|
||||
* absent on every product created before it, so editing one of those has to create the
|
||||
* mapping rather than fail looking for it.
|
||||
*/
|
||||
public void createOrmergeSavingsToExpenseAccountMappingChanges(final JsonElement element, final String paramName,
|
||||
final Long productId, final int accountTypeId, final Map<String, Object> changes) {
|
||||
createOrmergeProductToAccountMappingChanges(element, paramName, productId, accountTypeId, changes, GLAccountType.EXPENSE,
|
||||
PortfolioProductType.SAVING);
|
||||
}
|
||||
|
||||
/*** Abstractions for payments channel related to savings products ***/
|
||||
|
||||
public void savePaymentChannelToFundSourceMappings(final JsonCommand command, final JsonElement element, final Long productId,
|
||||
@@ -262,8 +248,6 @@ public class SavingsProductToGLAccountMappingHelper extends ProductToGLAccountMa
|
||||
CashAccountsForSavings.TRANSFERS_SUSPENSE.toString(), changes);
|
||||
createOrmergeSavingsToLiabilityAccountMappingChanges(element, SavingProductAccountingParams.ESCHEAT_LIABILITY.getValue(),
|
||||
savingsProductId, CashAccountsForSavings.ESCHEAT_LIABILITY.getValue(), changes);
|
||||
createOrmergeSavingsToExpenseAccountMappingChanges(element, SavingProductAccountingParams.ROUNDING_ADJUSTMENT.getValue(),
|
||||
savingsProductId, CashAccountsForSavings.ROUNDING_ADJUSTMENT.getValue(), changes);
|
||||
break;
|
||||
case ACCRUAL_PERIODIC:
|
||||
// asset
|
||||
@@ -324,8 +308,6 @@ public class SavingsProductToGLAccountMappingHelper extends ProductToGLAccountMa
|
||||
|
||||
createOrmergeSavingsToLiabilityAccountMappingChanges(element, SavingProductAccountingParams.ESCHEAT_LIABILITY.getValue(),
|
||||
savingsProductId, AccrualAccountsForSavings.ESCHEAT_LIABILITY.getValue(), changes);
|
||||
createOrmergeSavingsToExpenseAccountMappingChanges(element, SavingProductAccountingParams.ROUNDING_ADJUSTMENT.getValue(),
|
||||
savingsProductId, AccrualAccountsForSavings.ROUNDING_ADJUSTMENT.getValue(), changes);
|
||||
|
||||
break;
|
||||
case ACCRUAL_UPFRONT:
|
||||
|
||||
+3
-35
@@ -27,7 +27,6 @@ import org.apache.fineract.accounting.common.AccountingRuleType;
|
||||
import org.apache.fineract.accounting.glaccount.domain.GLAccountRepository;
|
||||
import org.apache.fineract.accounting.glaccount.domain.GLAccountRepositoryWrapper;
|
||||
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.infrastructure.codes.domain.CodeValueRepository;
|
||||
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
||||
@@ -167,9 +166,9 @@ public class ShareProductToGLAccountMappingHelper extends ProductToGLAccountMapp
|
||||
case NONE:
|
||||
break;
|
||||
case CASH_BASED:
|
||||
// asset -- the one optional mapping here, so unlike the three below it needs its own
|
||||
// handling for the case the field is now absent (see mergeOrRemoveSharesReferenceMapping).
|
||||
mergeOrRemoveSharesReferenceMapping(element, sharesProductId, changes);
|
||||
// asset
|
||||
mergeSharesToAssetAccountMappingChanges(element, SharesProductAccountingParams.SHARES_REFERENCE.getValue(), sharesProductId,
|
||||
CashAccountsForShares.SHARES_REFERENCE.getValue(), CashAccountsForShares.SHARES_REFERENCE.toString(), changes);
|
||||
|
||||
// income
|
||||
mergeSharesToIncomeAccountMappingChanges(element, SharesProductAccountingParams.INCOME_FROM_FEES.getValue(),
|
||||
@@ -195,35 +194,4 @@ public class ShareProductToGLAccountMappingHelper extends ProductToGLAccountMapp
|
||||
public void deleteSharesProductToGLAccountMapping(final Long sharesProductId) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-43
@@ -269,15 +269,7 @@ public final class AccountingConstants {
|
||||
OVERDRAFT_PORTFOLIO_CONTROL(11), //
|
||||
INCOME_FROM_INTEREST(12), //
|
||||
LOSSES_WRITTEN_OFF(13), //
|
||||
ESCHEAT_LIABILITY(14), //
|
||||
/**
|
||||
* Where the paise dropped from a cash closure are absorbed.
|
||||
*
|
||||
* Cash has no paise in circulation, so a closing balance of 9,883.79 is handed over as
|
||||
* 9,883 and the 0.79 has to land somewhere other than the member's own ledger. Numbered
|
||||
* well clear of the accrual slots so the two sets never collide as either grows.
|
||||
*/
|
||||
ROUNDING_ADJUSTMENT(26); //
|
||||
ESCHEAT_LIABILITY(14); //
|
||||
|
||||
private final Integer value;
|
||||
|
||||
@@ -325,9 +317,7 @@ public final class AccountingConstants {
|
||||
FEES_RECEIVABLE(15), //
|
||||
PENALTIES_RECEIVABLE(16), //
|
||||
INTEREST_PAYABLE(17), //
|
||||
INTEREST_RECEIVABLE(18), //
|
||||
/** Where the paise dropped from a cash closure are absorbed — see the cash enum. */
|
||||
ROUNDING_ADJUSTMENT(26);
|
||||
INTEREST_RECEIVABLE(18);
|
||||
|
||||
private final Integer value;
|
||||
|
||||
@@ -382,8 +372,7 @@ public final class AccountingConstants {
|
||||
PENALTIES_RECEIVABLE("penaltiesReceivableAccountId"), //
|
||||
INTEREST_RECEIVABLE("interestReceivableAccountId"), //
|
||||
FEES_RECEIVABLE("feesReceivableAccountId"), //
|
||||
INTEREST_PAYABLE("interestPayableAccountId"), //
|
||||
ROUNDING_ADJUSTMENT("roundingAdjustmentAccountId");
|
||||
INTEREST_PAYABLE("interestPayableAccountId");
|
||||
|
||||
private final String value;
|
||||
|
||||
@@ -421,8 +410,7 @@ public final class AccountingConstants {
|
||||
FEES_RECEIVABLE("feeReceivableAccount"), //
|
||||
PENALTIES_RECEIVABLE("penaltyReceivableAccount"), //
|
||||
INTEREST_PAYABLE("interestPayableAccount"), //
|
||||
INTEREST_RECEIVABLE("interestReceivableAccount"), //
|
||||
ROUNDING_ADJUSTMENT("roundingAdjustmentAccount"); //
|
||||
INTEREST_RECEIVABLE("interestReceivableAccount"); //
|
||||
|
||||
private final String value;
|
||||
|
||||
@@ -449,34 +437,8 @@ public final class AccountingConstants {
|
||||
OPENING_BALANCES_TRANSFER_CONTRA(300, "openingBalancesTransferContra", GLAccountType.EQUITY), //
|
||||
ASSET_FUND_SOURCE(103, "fundSource", GLAccountType.ASSET), //
|
||||
PAYABLE_DIVIDENDS(201, "payableDividends", GLAccountType.LIABILITY), //
|
||||
DIVIDEND_PAID(202, "dividendPaid", GLAccountType.LIABILITY), //
|
||||
RESERVE_FOR_DIVIDEND(301, "reserveForDividend", GLAccountType.EQUITY), //
|
||||
DIVIDEND_FORFEITED_INCOME(400, "dividendForfeitedIncome", GLAccountType.INCOME), //
|
||||
/**
|
||||
* The year's closed-out profit a dividend is declared against.
|
||||
*
|
||||
* Kept apart from {@link #RETAINED_PROFIT} on purpose: a declaration is sized on this balance, so anything that
|
||||
* has already been through a distribution decision must not sit here, or the same money would be offered for
|
||||
* distribution a second time.
|
||||
*/
|
||||
DISTRIBUTABLE_PROFIT(302, "distributableProfit", GLAccountType.EQUITY), //
|
||||
/**
|
||||
* Where profit settles once it is no longer distributable - the remainder left after an approved declaration
|
||||
* and dividends forfeited after the three-year claim window. Nothing here ever enters a later dividend
|
||||
* calculation.
|
||||
*/
|
||||
RETAINED_PROFIT(303, "retainedProfit", GLAccountType.EQUITY), //
|
||||
/**
|
||||
* Where the paise a dividend cannot divide evenly are collected.
|
||||
*
|
||||
* A declaration of 1,538.91 that allocates 1,538 to members leaves 0.91 that belongs to nobody. It used to be
|
||||
* swept into retained profit along with the undistributed remainder, which buried an arithmetic artefact inside
|
||||
* a figure the society reads as a real business result. Given its own account it stays separately readable -
|
||||
* and an auditor asking why members received less than was declared can be answered from the ledger.
|
||||
*
|
||||
* Optional: a society that has not mapped it has the residue swept to retained profit exactly as before.
|
||||
*/
|
||||
DIVIDEND_ROUND_OFF(304, "dividendRoundOff", GLAccountType.EQUITY); //
|
||||
DIVIDEND_FORFEITED_INCOME(400, "dividendForfeitedIncome", GLAccountType.INCOME); //
|
||||
|
||||
private final Integer value;
|
||||
private final String code;
|
||||
|
||||
+1
-20
@@ -137,7 +137,7 @@ public class CommandSourceService {
|
||||
String permission = commandSource.getPermissionCode();
|
||||
boolean isMakerChecker = configurationDomainService.isMakerCheckerEnabledForTask(permission);
|
||||
if (isMakerChecker || result.isRollbackTransaction()) {
|
||||
if (isApprovedByChecker || isSuperUserBypassAllowed(commandSource, user)) {
|
||||
if (isApprovedByChecker || user.isCheckerSuperUser()) {
|
||||
commandSource.markAsChecked(user);
|
||||
} else {
|
||||
if (commandSource.isSanitized()) {
|
||||
@@ -151,25 +151,6 @@ public class CommandSourceService {
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean isSuperUserBypassAllowed(CommandSource commandSource, AppUser user) {
|
||||
if (!user.isCheckerSuperUser()) {
|
||||
return false;
|
||||
}
|
||||
if ("GLACCOUNT".equalsIgnoreCase(commandSource.getEntityName())
|
||||
|| "CBSBASEINTERESTRATE".equalsIgnoreCase(commandSource.getEntityName())
|
||||
|| "CHARGE".equalsIgnoreCase(commandSource.getEntityName())
|
||||
|| "LOANPRODUCT".equalsIgnoreCase(commandSource.getEntityName())
|
||||
|| "SAVINGSPRODUCT".equalsIgnoreCase(commandSource.getEntityName())
|
||||
|| "CURRENTPRODUCT".equalsIgnoreCase(commandSource.getEntityName())
|
||||
|| "SHAREPRODUCT".equalsIgnoreCase(commandSource.getEntityName())
|
||||
|| "FIXEDDEPOSITPRODUCT".equalsIgnoreCase(commandSource.getEntityName())
|
||||
|| "USER".equalsIgnoreCase(commandSource.getEntityName())
|
||||
|| "ROLE".equalsIgnoreCase(commandSource.getEntityName())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void sanitizeJson(@NonNull CommandSource commandSource, Set<String> sanitizeKeys) {
|
||||
if (sanitizeKeys == null || sanitizeKeys.isEmpty()) {
|
||||
return;
|
||||
|
||||
+69
-30
@@ -664,11 +664,75 @@ public class CommandWrapperBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder deleteOffice(final Long officeId) {
|
||||
this.actionName = "DELETE";
|
||||
this.entityName = "OFFICE";
|
||||
this.entityId = officeId;
|
||||
this.href = "/offices/" + officeId;
|
||||
public CommandWrapperBuilder createAgent() {
|
||||
this.actionName = "CREATE";
|
||||
this.entityName = "AGENT";
|
||||
this.entityId = null;
|
||||
this.href = "/dds/agents/template";
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder updateAgent(final Long agentId) {
|
||||
this.actionName = "UPDATE";
|
||||
this.entityName = "AGENT";
|
||||
this.entityId = agentId;
|
||||
this.href = "/dds/agents/" + agentId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder createParty() {
|
||||
this.actionName = "CREATE";
|
||||
this.entityName = "PARTY";
|
||||
this.entityId = null;
|
||||
this.href = "/dds/parties/template";
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder updateParty(final Long partyId) {
|
||||
this.actionName = "UPDATE";
|
||||
this.entityName = "PARTY";
|
||||
this.entityId = partyId;
|
||||
this.href = "/dds/parties/" + partyId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder closeParty(final Long partyId) {
|
||||
this.actionName = "CLOSE";
|
||||
this.entityName = "PARTY";
|
||||
this.entityId = partyId;
|
||||
this.href = "/dds/parties/" + partyId + "?command=close";
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder createPartyTransaction() {
|
||||
this.actionName = "CREATE";
|
||||
this.entityName = "PARTYTRANSACTION";
|
||||
this.entityId = null;
|
||||
this.href = "/dds/partytransactions/template";
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder createCommissionSlabs() {
|
||||
this.actionName = "CREATE";
|
||||
this.entityName = "COMMISSIONSLAB";
|
||||
this.entityId = null;
|
||||
this.href = "/dds/commissionslabs/template";
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder generateDdsBatchRun() {
|
||||
this.actionName = "GENERATE";
|
||||
this.entityName = "DDSBATCH";
|
||||
this.entityId = null;
|
||||
this.href = "/dds/batchruns/template";
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder postDdsBatchRun(final Long batchRunId) {
|
||||
this.actionName = "POST";
|
||||
this.entityName = "DDSBATCH";
|
||||
this.entityId = batchRunId;
|
||||
this.href = "/dds/batchruns/" + batchRunId;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -2219,14 +2283,6 @@ public class CommandWrapperBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder createCbsBaseInterestRate() {
|
||||
this.actionName = "CREATE";
|
||||
this.entityName = "CBSBASEINTERESTRATE";
|
||||
this.entityId = null;
|
||||
this.href = "/fixeddepositproducts/baseinterestrates";
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder updateFixedDepositProduct(final Long productId) {
|
||||
this.actionName = "UPDATE";
|
||||
this.entityName = "FIXEDDEPOSITPRODUCT";
|
||||
@@ -2913,15 +2969,6 @@ public class CommandWrapperBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder paymentFixedDepositAccount(final Long accountId) {
|
||||
this.actionName = "PAYMENT";
|
||||
this.entityName = "FIXEDDEPOSITACCOUNT";
|
||||
this.entityId = accountId;
|
||||
this.savingsId = accountId;
|
||||
this.href = "/fixeddepositaccounts/" + accountId + "?command=payment";
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder fixedDepositAccountInterestCalculation(final Long accountId) {
|
||||
this.actionName = "CALCULATEINTEREST";
|
||||
this.entityName = "FIXEDDEPOSITACCOUNT";
|
||||
@@ -3128,14 +3175,6 @@ public class CommandWrapperBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder updateFacilityChargeMapping(final Long mappingId) {
|
||||
this.actionName = "UPDATE";
|
||||
this.entityName = "FACILITYCHARGEMAPPING";
|
||||
this.entityId = mappingId;
|
||||
this.href = "/facilitychargemappings/" + mappingId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder deleteOfficeToGLAccountMapping(final Long mappingId) {
|
||||
this.actionName = "DELETE";
|
||||
this.entityName = "FINANCIALACTIVITYACCOUNT";
|
||||
|
||||
-2
@@ -26,8 +26,6 @@ public interface ConfigurationDomainService {
|
||||
|
||||
boolean isMakerCheckerEnabledForTask(String taskPermissionCode);
|
||||
|
||||
boolean isMakerCheckerEnabled();
|
||||
|
||||
/**
|
||||
* Global kill-switch for MFA-factor-backed login enforcement. When true, users with at least
|
||||
* one verified, non-disabled row in {@code m_user_mfa_factor} must complete a 2FA challenge
|
||||
|
||||
-13
@@ -130,19 +130,6 @@ public class DataValidatorBuilder {
|
||||
this.dataValidationErrors.add(error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Like {@link #failWithCode(String, Object...)}, but the caller's own message is what's actually shown to the
|
||||
* user (that method always renders the generic "Failed data validation due to: {errorCode}." regardless of the
|
||||
* args passed to it).
|
||||
*/
|
||||
public void failWithCodeAndMessage(final String errorCode, final String defaultUserMessage,
|
||||
final Object... defaultUserMessageArgs) {
|
||||
String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + "." + errorCode;
|
||||
final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultUserMessage, this.parameter,
|
||||
this.value, defaultUserMessageArgs);
|
||||
this.dataValidationErrors.add(error);
|
||||
}
|
||||
|
||||
public void failWithCodeNoParameterAddedToErrorCode(final String errorCode, final Object... defaultUserMessageArgs) {
|
||||
String validationErrorCode = "validation.msg." + this.resource + "." + errorCode;
|
||||
String defaultEnglishMessage = "Failed data validation due to: " + errorCode + ".";
|
||||
|
||||
-5
@@ -39,10 +39,7 @@ public enum JobName {
|
||||
GENERATE_LOANLOSS_PROVISIONING("Generate Loan Loss Provisioning"), //
|
||||
POST_DIVIDENTS_FOR_SHARES("Post Dividends For Shares"), //
|
||||
FORFEIT_UNCLAIMED_DIVIDENDS("Forfeit Unclaimed Dividends"), //
|
||||
POST_SHARE_ENTRY_FEE_TO_PROFIT("Post Share Entry Fee To Profit"), //
|
||||
UPDATE_SAVINGS_DORMANT_ACCOUNTS("Update Savings Dormant Accounts"), //
|
||||
APPLY_KYC_EXPIRY_RESTRICTIONS("Apply KYC Expiry Restrictions"), //
|
||||
SAVINGS_DAILY_INTEREST("Savings Daily Interest Accrual And Posting"), //
|
||||
ADD_PERIODIC_ACCRUAL_ENTRIES_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"), //
|
||||
@@ -56,7 +53,6 @@ public enum JobName {
|
||||
EXECUTE_DIRTY_JOBS("Execute All Dirty Jobs"), //
|
||||
INCREASE_BUSINESS_DATE_BY_1_DAY("Increase Business Date by 1 day"), //
|
||||
INCREASE_COB_DATE_BY_1_DAY("Increase COB Date by 1 day"), //
|
||||
SYNC_BUSINESS_DATE_TO_SYSTEM_DATE("Sync Business Date To System Date"), //
|
||||
LOAN_COB("Loan COB"), //
|
||||
LOAN_DELINQUENCY_CLASSIFICATION("Loan Delinquency Classification"), //
|
||||
SEND_ASYNCHRONOUS_EVENTS("Send Asynchronous Events"), //
|
||||
@@ -72,7 +68,6 @@ public enum JobName {
|
||||
OUTWARD_CLEARING_BATCH_SEND("CTS Outward Clearing Batch Send"), //
|
||||
CTR_REPORT_GENERATION("AML Monthly CTR Report Generation"), //
|
||||
AML_STR_WEEKLY_DIGEST("AML STR Weekly Digest"), //
|
||||
CLIENT_BEHAVIOUR_WINDOW("Client Behaviour Window Computation"), //
|
||||
; //
|
||||
|
||||
private final String name;
|
||||
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
* 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.agent.data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Collection;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Immutable data object representing a DDS agent, including its collection-limit history and
|
||||
* guarantors. Carries the collection/commission/security-account fields merged in from SubAgent
|
||||
* (2026-08-24) - Agent now does the daily collection work directly.
|
||||
*/
|
||||
@Getter
|
||||
public final class AgentData implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Long id;
|
||||
private final Long clientId;
|
||||
private final String clientName;
|
||||
private final String agentCode;
|
||||
private final String agentNameId;
|
||||
private final String agentAddress1;
|
||||
private final String agentAddress2;
|
||||
private final String agentCity;
|
||||
private final String agentPinCode;
|
||||
private final String agentTelephone;
|
||||
private final String agentSavingAccountType;
|
||||
private final String agentSavingAccountNo;
|
||||
private final LocalDate agentOpeningDate;
|
||||
private final LocalDate agentBirthDate;
|
||||
private final BigDecimal agentCurrentBalance;
|
||||
private final BigDecimal agentOpeningBalance;
|
||||
private final String homeBranch;
|
||||
private final String savingBranch;
|
||||
private final Boolean tdsApplicable;
|
||||
private final BigDecimal tdsPercent;
|
||||
private final BigDecimal currentTds;
|
||||
private final BigDecimal tdsAmount;
|
||||
private final String transferBranch;
|
||||
private final String transferAmountAccountType;
|
||||
private final String transferAccountNo;
|
||||
private final Boolean commissionCalculation;
|
||||
private final BigDecimal limit;
|
||||
private final BigDecimal machineRent;
|
||||
private final String agentSecurityBranch;
|
||||
private final String agentSecurityAccountType;
|
||||
private final String agentSecurityAccountNo;
|
||||
private final BigDecimal commission;
|
||||
private final BigDecimal otherCommission;
|
||||
private final BigDecimal agentDeposit;
|
||||
private final BigDecimal festivalAdvance;
|
||||
private final BigDecimal otherDeduction;
|
||||
private final Collection<AgentLimitData> limits;
|
||||
private final Collection<AgentGuarantorData> guarantors;
|
||||
|
||||
public static AgentData instance(final Long id, final Long clientId, final String clientName, final String agentCode,
|
||||
final String agentNameId, final String agentAddress1, final String agentAddress2, final String agentCity,
|
||||
final String agentPinCode, final String agentTelephone, final String agentSavingAccountType,
|
||||
final String agentSavingAccountNo, final LocalDate agentOpeningDate, final LocalDate agentBirthDate,
|
||||
final BigDecimal agentCurrentBalance, final BigDecimal agentOpeningBalance, final String homeBranch,
|
||||
final String savingBranch, final Boolean tdsApplicable, final BigDecimal tdsPercent, final BigDecimal currentTds,
|
||||
final BigDecimal tdsAmount, final String transferBranch, final String transferAmountAccountType,
|
||||
final String transferAccountNo, final Boolean commissionCalculation, final BigDecimal limit, final BigDecimal machineRent,
|
||||
final String agentSecurityBranch, final String agentSecurityAccountType, final String agentSecurityAccountNo,
|
||||
final BigDecimal commission, final BigDecimal otherCommission, final BigDecimal agentDeposit,
|
||||
final BigDecimal festivalAdvance, final BigDecimal otherDeduction, final Collection<AgentLimitData> limits,
|
||||
final Collection<AgentGuarantorData> guarantors) {
|
||||
return new AgentData(id, clientId, clientName, agentCode, agentNameId, agentAddress1, agentAddress2, agentCity, agentPinCode,
|
||||
agentTelephone, agentSavingAccountType, agentSavingAccountNo, agentOpeningDate, agentBirthDate, agentCurrentBalance,
|
||||
agentOpeningBalance, homeBranch, savingBranch, tdsApplicable, tdsPercent, currentTds, tdsAmount, transferBranch,
|
||||
transferAmountAccountType, transferAccountNo, commissionCalculation, limit, machineRent, agentSecurityBranch,
|
||||
agentSecurityAccountType, agentSecurityAccountNo, commission, otherCommission, agentDeposit, festivalAdvance,
|
||||
otherDeduction, limits, guarantors);
|
||||
}
|
||||
|
||||
private AgentData(final Long id, final Long clientId, final String clientName, final String agentCode, final String agentNameId,
|
||||
final String agentAddress1, final String agentAddress2, final String agentCity, final String agentPinCode,
|
||||
final String agentTelephone, final String agentSavingAccountType, final String agentSavingAccountNo,
|
||||
final LocalDate agentOpeningDate, final LocalDate agentBirthDate, final BigDecimal agentCurrentBalance,
|
||||
final BigDecimal agentOpeningBalance, final String homeBranch, final String savingBranch, final Boolean tdsApplicable,
|
||||
final BigDecimal tdsPercent, final BigDecimal currentTds, final BigDecimal tdsAmount, final String transferBranch,
|
||||
final String transferAmountAccountType, final String transferAccountNo, final Boolean commissionCalculation,
|
||||
final BigDecimal limit, final BigDecimal machineRent, final String agentSecurityBranch,
|
||||
final String agentSecurityAccountType, final String agentSecurityAccountNo, final BigDecimal commission,
|
||||
final BigDecimal otherCommission, final BigDecimal agentDeposit, final BigDecimal festivalAdvance,
|
||||
final BigDecimal otherDeduction, final Collection<AgentLimitData> limits, final Collection<AgentGuarantorData> guarantors) {
|
||||
this.id = id;
|
||||
this.clientId = clientId;
|
||||
this.clientName = clientName;
|
||||
this.agentCode = agentCode;
|
||||
this.agentNameId = agentNameId;
|
||||
this.agentAddress1 = agentAddress1;
|
||||
this.agentAddress2 = agentAddress2;
|
||||
this.agentCity = agentCity;
|
||||
this.agentPinCode = agentPinCode;
|
||||
this.agentTelephone = agentTelephone;
|
||||
this.agentSavingAccountType = agentSavingAccountType;
|
||||
this.agentSavingAccountNo = agentSavingAccountNo;
|
||||
this.agentOpeningDate = agentOpeningDate;
|
||||
this.agentBirthDate = agentBirthDate;
|
||||
this.agentCurrentBalance = agentCurrentBalance;
|
||||
this.agentOpeningBalance = agentOpeningBalance;
|
||||
this.homeBranch = homeBranch;
|
||||
this.savingBranch = savingBranch;
|
||||
this.tdsApplicable = tdsApplicable;
|
||||
this.tdsPercent = tdsPercent;
|
||||
this.currentTds = currentTds;
|
||||
this.tdsAmount = tdsAmount;
|
||||
this.transferBranch = transferBranch;
|
||||
this.transferAmountAccountType = transferAmountAccountType;
|
||||
this.transferAccountNo = transferAccountNo;
|
||||
this.commissionCalculation = commissionCalculation;
|
||||
this.limit = limit;
|
||||
this.machineRent = machineRent;
|
||||
this.agentSecurityBranch = agentSecurityBranch;
|
||||
this.agentSecurityAccountType = agentSecurityAccountType;
|
||||
this.agentSecurityAccountNo = agentSecurityAccountNo;
|
||||
this.commission = commission;
|
||||
this.otherCommission = otherCommission;
|
||||
this.agentDeposit = agentDeposit;
|
||||
this.festivalAdvance = festivalAdvance;
|
||||
this.otherDeduction = otherDeduction;
|
||||
this.limits = limits;
|
||||
this.guarantors = guarantors;
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* 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.agent.data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Immutable data object representing a single agent guarantor.
|
||||
*/
|
||||
@Getter
|
||||
public final class AgentGuarantorData implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Long id;
|
||||
private final Long clientId;
|
||||
private final String guarantorName;
|
||||
private final String address1;
|
||||
private final String address2;
|
||||
private final String city;
|
||||
private final String pinCode;
|
||||
private final String telephone;
|
||||
|
||||
public static AgentGuarantorData instance(final Long id, final Long clientId, final String guarantorName, final String address1,
|
||||
final String address2, final String city, final String pinCode, final String telephone) {
|
||||
return new AgentGuarantorData(id, clientId, guarantorName, address1, address2, city, pinCode, telephone);
|
||||
}
|
||||
|
||||
private AgentGuarantorData(final Long id, final Long clientId, final String guarantorName, final String address1,
|
||||
final String address2, final String city, final String pinCode, final String telephone) {
|
||||
this.id = id;
|
||||
this.clientId = clientId;
|
||||
this.guarantorName = guarantorName;
|
||||
this.address1 = address1;
|
||||
this.address2 = address2;
|
||||
this.city = city;
|
||||
this.pinCode = pinCode;
|
||||
this.telephone = telephone;
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* 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.agent.data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public final class AgentLimitData implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Long id;
|
||||
private final LocalDate fromDate;
|
||||
private final LocalDate toDate;
|
||||
private final BigDecimal limit;
|
||||
|
||||
public static AgentLimitData instance(final Long id, final LocalDate fromDate, final LocalDate toDate, final BigDecimal limit) {
|
||||
return new AgentLimitData(id, fromDate, toDate, limit);
|
||||
}
|
||||
|
||||
private AgentLimitData(final Long id, final LocalDate fromDate, final LocalDate toDate, final BigDecimal limit) {
|
||||
this.id = id;
|
||||
this.fromDate = fromDate;
|
||||
this.toDate = toDate;
|
||||
this.limit = limit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,440 @@
|
||||
/**
|
||||
* 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.agent.domain;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.OrderBy;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.UniqueConstraint;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
||||
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
|
||||
import org.apache.fineract.portfolio.client.domain.Client;
|
||||
|
||||
/**
|
||||
* A DDS (Daily Deposit Scheme) collection agent. Can represent either a person or, at the top of the
|
||||
* hierarchy, the bank itself acting as its own agent. Holds its own settlement savings account and one
|
||||
* or more guarantors.
|
||||
*/
|
||||
@Getter
|
||||
@Entity
|
||||
@Table(name = "m_dds_agent", uniqueConstraints = { @UniqueConstraint(columnNames = { "agent_code" }, name = "agent_code_UNIQUE") })
|
||||
public class Agent extends AbstractPersistableCustom<Long> {
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "client_id", nullable = false)
|
||||
private Client client;
|
||||
|
||||
@Column(name = "agent_code", length = 20, nullable = false)
|
||||
private String agentCode;
|
||||
|
||||
@Column(name = "agent_name", length = 100, nullable = false)
|
||||
private String agentName;
|
||||
|
||||
@Column(name = "agent_address1", length = 200, nullable = false)
|
||||
private String agentAddress1;
|
||||
|
||||
@Column(name = "agent_address2", length = 200)
|
||||
private String agentAddress2;
|
||||
|
||||
@Column(name = "agent_city", length = 100, nullable = false)
|
||||
private String agentCity;
|
||||
|
||||
@Column(name = "agent_pincode", length = 20, nullable = false)
|
||||
private String agentPinCode;
|
||||
|
||||
@Column(name = "agent_telephone", length = 20)
|
||||
private String agentTelephone;
|
||||
|
||||
@Column(name = "agent_saving_account_type", length = 100, nullable = false)
|
||||
private String agentSavingAccountType;
|
||||
|
||||
@Column(name = "agent_saving_account_no", length = 50, nullable = false)
|
||||
private String agentSavingAccountNo;
|
||||
|
||||
@Column(name = "agent_opening_date", nullable = false)
|
||||
private LocalDate agentOpeningDate;
|
||||
|
||||
@Column(name = "agent_birth_date", nullable = false)
|
||||
private LocalDate agentBirthDate;
|
||||
|
||||
@Column(name = "agent_current_balance", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal agentCurrentBalance;
|
||||
|
||||
@Column(name = "agent_opening_balance", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal agentOpeningBalance;
|
||||
|
||||
// Fields below were merged in from SubAgent (2026-08-24) - the Agent itself now does the daily
|
||||
// collection work directly; SubAgent no longer exists as a separate tier. Ag.Level / Upper Ag.Level
|
||||
// / Collector (MLM) / CRPB Points / Level Update Date were dropped - they only ever meant anything
|
||||
// for a multi-level hierarchy, which no longer exists here.
|
||||
@Column(name = "home_branch", length = 100, nullable = false)
|
||||
private String homeBranch;
|
||||
|
||||
@Column(name = "saving_branch", length = 100, nullable = false)
|
||||
private String savingBranch;
|
||||
|
||||
@Column(name = "tds_applicable", nullable = false)
|
||||
private boolean tdsApplicable;
|
||||
|
||||
@Column(name = "tds_percent", scale = 6, precision = 19)
|
||||
private BigDecimal tdsPercent;
|
||||
|
||||
@Column(name = "current_tds", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal currentTds;
|
||||
|
||||
@Column(name = "tds_amount", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal tdsAmount;
|
||||
|
||||
@Column(name = "transfer_branch", length = 100)
|
||||
private String transferBranch;
|
||||
|
||||
@Column(name = "transfer_amount_account_type", length = 100)
|
||||
private String transferAmountAccountType;
|
||||
|
||||
@Column(name = "transfer_account_no", length = 50)
|
||||
private String transferAccountNo;
|
||||
|
||||
@Column(name = "collector_commission_calculation", nullable = false)
|
||||
private boolean commissionCalculation;
|
||||
|
||||
@Column(name = "collector_limit_amount", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal limitAmount;
|
||||
|
||||
@Column(name = "machine_rent", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal machineRent;
|
||||
|
||||
@Column(name = "agent_security_branch", length = 100)
|
||||
private String agentSecurityBranch;
|
||||
|
||||
@Column(name = "agent_security_account_type", length = 100)
|
||||
private String agentSecurityAccountType;
|
||||
|
||||
@Column(name = "agent_security_account_no", length = 50)
|
||||
private String agentSecurityAccountNo;
|
||||
|
||||
@Column(name = "commission", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal commission;
|
||||
|
||||
@Column(name = "other_commission", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal otherCommission;
|
||||
|
||||
@Column(name = "agent_deposit", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal agentDeposit;
|
||||
|
||||
@Column(name = "festival_advance", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal festivalAdvance;
|
||||
|
||||
@Column(name = "other_deduction", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal otherDeduction;
|
||||
|
||||
@Column(name = "last_commission_date")
|
||||
private LocalDate lastCommissionDate;
|
||||
|
||||
@OneToMany(mappedBy = "agent", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
||||
@OrderBy("id")
|
||||
private List<AgentGuarantor> guarantors = new ArrayList<>();
|
||||
|
||||
@OneToMany(mappedBy = "agent", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
||||
@OrderBy("id")
|
||||
private List<AgentLimit> limits = new ArrayList<>();
|
||||
|
||||
protected Agent() {
|
||||
//
|
||||
}
|
||||
|
||||
private Agent(final Client client, final String agentCode, final String agentName, final String agentAddress1,
|
||||
final String agentAddress2, final String agentCity, final String agentPinCode, final String agentTelephone,
|
||||
final String agentSavingAccountType, final String agentSavingAccountNo, final LocalDate agentOpeningDate,
|
||||
final LocalDate agentBirthDate, final BigDecimal agentOpeningBalance, final JsonCommand command) {
|
||||
this.client = client;
|
||||
this.agentCode = agentCode;
|
||||
this.agentName = agentName;
|
||||
this.agentAddress1 = agentAddress1;
|
||||
this.agentAddress2 = StringUtils.defaultIfEmpty(agentAddress2, null);
|
||||
this.agentCity = agentCity;
|
||||
this.agentPinCode = agentPinCode;
|
||||
this.agentTelephone = StringUtils.defaultIfEmpty(agentTelephone, null);
|
||||
this.agentSavingAccountType = agentSavingAccountType;
|
||||
this.agentSavingAccountNo = agentSavingAccountNo;
|
||||
this.agentOpeningDate = agentOpeningDate;
|
||||
this.agentBirthDate = agentBirthDate;
|
||||
this.agentOpeningBalance = agentOpeningBalance == null ? BigDecimal.ZERO : agentOpeningBalance;
|
||||
this.agentCurrentBalance = this.agentOpeningBalance;
|
||||
|
||||
this.homeBranch = command.stringValueOfParameterNamed("homeBranch");
|
||||
this.savingBranch = command.stringValueOfParameterNamed("savingBranch");
|
||||
this.tdsApplicable = command.booleanPrimitiveValueOfParameterNamed("tdsApplicable");
|
||||
this.tdsPercent = command.bigDecimalValueOfParameterNamedDefaultToNullIfZero("tdsPercent");
|
||||
this.currentTds = BigDecimal.ZERO;
|
||||
this.tdsAmount = BigDecimal.ZERO;
|
||||
this.transferBranch = StringUtils.defaultIfEmpty(command.stringValueOfParameterNamedAllowingNull("transferBranch"), null);
|
||||
this.transferAmountAccountType = StringUtils
|
||||
.defaultIfEmpty(command.stringValueOfParameterNamedAllowingNull("transferAmountAccountType"), null);
|
||||
this.transferAccountNo = StringUtils.defaultIfEmpty(command.stringValueOfParameterNamedAllowingNull("transferAccountNo"), null);
|
||||
this.commissionCalculation = command.booleanPrimitiveValueOfParameterNamed("commissionCalculation");
|
||||
this.limitAmount = orZero(command.bigDecimalValueOfParameterNamedDefaultToNullIfZero("limit"));
|
||||
this.machineRent = orZero(command.bigDecimalValueOfParameterNamedDefaultToNullIfZero("machineRent"));
|
||||
this.agentSecurityBranch = StringUtils.defaultIfEmpty(command.stringValueOfParameterNamedAllowingNull("agentSecurityBranch"),
|
||||
null);
|
||||
this.agentSecurityAccountType = StringUtils
|
||||
.defaultIfEmpty(command.stringValueOfParameterNamedAllowingNull("agentSecurityAccountType"), null);
|
||||
this.agentSecurityAccountNo = StringUtils.defaultIfEmpty(command.stringValueOfParameterNamedAllowingNull("agentSecurityAccountNo"),
|
||||
null);
|
||||
this.commission = BigDecimal.ZERO;
|
||||
this.otherCommission = orZero(command.bigDecimalValueOfParameterNamedDefaultToNullIfZero("otherCommission"));
|
||||
this.agentDeposit = orZero(command.bigDecimalValueOfParameterNamedDefaultToNullIfZero("agentDeposit"));
|
||||
this.festivalAdvance = orZero(command.bigDecimalValueOfParameterNamedDefaultToNullIfZero("festivalAdvance"));
|
||||
this.otherDeduction = orZero(command.bigDecimalValueOfParameterNamedDefaultToNullIfZero("otherDeduction"));
|
||||
}
|
||||
|
||||
public static Agent fromJson(final Client client, final String agentCode, final JsonCommand command) {
|
||||
final String agentName = command.stringValueOfParameterNamed("agentNameId");
|
||||
final String agentAddress1 = command.stringValueOfParameterNamed("agentAddress1");
|
||||
final String agentAddress2 = command.stringValueOfParameterNamedAllowingNull("agentAddress2");
|
||||
final String agentCity = command.stringValueOfParameterNamed("agentCity");
|
||||
final String agentPinCode = command.stringValueOfParameterNamed("agentPinCode");
|
||||
final String agentTelephone = command.stringValueOfParameterNamedAllowingNull("agentTelephone");
|
||||
final String agentSavingAccountType = command.stringValueOfParameterNamed("agentSavingAccountType");
|
||||
final String agentSavingAccountNo = command.stringValueOfParameterNamed("agentSavingAccountNo");
|
||||
final LocalDate agentOpeningDate = command.localDateValueOfParameterNamed("agentOpeningDate");
|
||||
final LocalDate agentBirthDate = command.localDateValueOfParameterNamed("agentBirthDate");
|
||||
final BigDecimal agentOpeningBalance = command.bigDecimalValueOfParameterNamedDefaultToNullIfZero("agentOpeningBalance");
|
||||
|
||||
return new Agent(client, agentCode, agentName, agentAddress1, agentAddress2, agentCity, agentPinCode, agentTelephone,
|
||||
agentSavingAccountType, agentSavingAccountNo, agentOpeningDate, agentBirthDate, agentOpeningBalance, command);
|
||||
}
|
||||
|
||||
private static BigDecimal orZero(final BigDecimal value) {
|
||||
return value == null ? BigDecimal.ZERO : value;
|
||||
}
|
||||
|
||||
public void addGuarantor(final AgentGuarantor guarantor) {
|
||||
guarantor.setAgent(this);
|
||||
this.guarantors.add(guarantor);
|
||||
}
|
||||
|
||||
public void resetGuarantors() {
|
||||
this.guarantors.clear();
|
||||
}
|
||||
|
||||
public void addLimit(final AgentLimit limit) {
|
||||
limit.setAgent(this);
|
||||
this.limits.add(limit);
|
||||
}
|
||||
|
||||
public void resetLimits() {
|
||||
this.limits.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a Commission Posting's amount to this agent's running commission total and stamps the date
|
||||
* commission was last calculated through, so the next Commission Calculation batch only covers
|
||||
* collections since then.
|
||||
*/
|
||||
public void postCommission(final BigDecimal amount, final LocalDate throughDate) {
|
||||
this.commission = this.commission.add(amount);
|
||||
this.lastCommissionDate = throughDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cash this agent has collected from parties but not yet handed over to a branch (an Agent Tran
|
||||
* settlement). Raised by a Party Tran collection, lowered by an Agent Tran settlement - this is the
|
||||
* figure an Agent's collection limit is enforced against.
|
||||
*/
|
||||
public BigDecimal credit(final BigDecimal amount) {
|
||||
this.agentCurrentBalance = this.agentCurrentBalance.add(amount);
|
||||
return this.agentCurrentBalance;
|
||||
}
|
||||
|
||||
public BigDecimal settle(final BigDecimal amount) {
|
||||
this.agentCurrentBalance = this.agentCurrentBalance.subtract(amount);
|
||||
return this.agentCurrentBalance;
|
||||
}
|
||||
|
||||
public void changeClient(final Client newClient) {
|
||||
this.client = newClient;
|
||||
}
|
||||
|
||||
public Long clientId() {
|
||||
return this.client.getId();
|
||||
}
|
||||
|
||||
public Map<String, Object> update(final JsonCommand command) {
|
||||
|
||||
final Map<String, Object> actualChanges = new LinkedHashMap<>(10);
|
||||
|
||||
if (command.isChangeInLongParameterNamed("clientId", this.client.getId())) {
|
||||
actualChanges.put("clientId", command.longValueOfParameterNamed("clientId"));
|
||||
}
|
||||
|
||||
if (command.isChangeInStringParameterNamed("agentNameId", this.agentName)) {
|
||||
final String newValue = command.stringValueOfParameterNamed("agentNameId");
|
||||
actualChanges.put("agentNameId", newValue);
|
||||
this.agentName = newValue;
|
||||
}
|
||||
|
||||
if (command.isChangeInStringParameterNamed("agentAddress1", this.agentAddress1)) {
|
||||
final String newValue = command.stringValueOfParameterNamed("agentAddress1");
|
||||
actualChanges.put("agentAddress1", newValue);
|
||||
this.agentAddress1 = newValue;
|
||||
}
|
||||
|
||||
if (command.isChangeInStringParameterNamed("agentAddress2", this.agentAddress2)) {
|
||||
final String newValue = command.stringValueOfParameterNamed("agentAddress2");
|
||||
actualChanges.put("agentAddress2", newValue);
|
||||
this.agentAddress2 = StringUtils.defaultIfEmpty(newValue, null);
|
||||
}
|
||||
|
||||
if (command.isChangeInStringParameterNamed("agentCity", this.agentCity)) {
|
||||
final String newValue = command.stringValueOfParameterNamed("agentCity");
|
||||
actualChanges.put("agentCity", newValue);
|
||||
this.agentCity = newValue;
|
||||
}
|
||||
|
||||
if (command.isChangeInStringParameterNamed("agentPinCode", this.agentPinCode)) {
|
||||
final String newValue = command.stringValueOfParameterNamed("agentPinCode");
|
||||
actualChanges.put("agentPinCode", newValue);
|
||||
this.agentPinCode = newValue;
|
||||
}
|
||||
|
||||
if (command.isChangeInStringParameterNamed("agentTelephone", this.agentTelephone)) {
|
||||
final String newValue = command.stringValueOfParameterNamed("agentTelephone");
|
||||
actualChanges.put("agentTelephone", newValue);
|
||||
this.agentTelephone = StringUtils.defaultIfEmpty(newValue, null);
|
||||
}
|
||||
|
||||
if (command.isChangeInStringParameterNamed("agentSavingAccountType", this.agentSavingAccountType)) {
|
||||
final String newValue = command.stringValueOfParameterNamed("agentSavingAccountType");
|
||||
actualChanges.put("agentSavingAccountType", newValue);
|
||||
this.agentSavingAccountType = newValue;
|
||||
}
|
||||
|
||||
if (command.isChangeInStringParameterNamed("agentSavingAccountNo", this.agentSavingAccountNo)) {
|
||||
final String newValue = command.stringValueOfParameterNamed("agentSavingAccountNo");
|
||||
actualChanges.put("agentSavingAccountNo", newValue);
|
||||
this.agentSavingAccountNo = newValue;
|
||||
}
|
||||
|
||||
if (command.isChangeInDateParameterNamed("agentOpeningDate", this.agentOpeningDate)) {
|
||||
actualChanges.put("agentOpeningDate", command.stringValueOfParameterNamed("agentOpeningDate"));
|
||||
this.agentOpeningDate = command.localDateValueOfParameterNamed("agentOpeningDate");
|
||||
}
|
||||
|
||||
if (command.isChangeInDateParameterNamed("agentBirthDate", this.agentBirthDate)) {
|
||||
actualChanges.put("agentBirthDate", command.stringValueOfParameterNamed("agentBirthDate"));
|
||||
this.agentBirthDate = command.localDateValueOfParameterNamed("agentBirthDate");
|
||||
}
|
||||
|
||||
stringChange(command, actualChanges, "homeBranch", this.homeBranch, v -> this.homeBranch = v);
|
||||
stringChange(command, actualChanges, "savingBranch", this.savingBranch, v -> this.savingBranch = v);
|
||||
|
||||
if (command.isChangeInBooleanParameterNamed("tdsApplicable", this.tdsApplicable)) {
|
||||
final boolean newValue = command.booleanPrimitiveValueOfParameterNamed("tdsApplicable");
|
||||
actualChanges.put("tdsApplicable", newValue);
|
||||
this.tdsApplicable = newValue;
|
||||
}
|
||||
|
||||
if (command.isChangeInBigDecimalParameterNamed("tdsPercent", this.tdsPercent)) {
|
||||
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed("tdsPercent");
|
||||
actualChanges.put("tdsPercent", newValue);
|
||||
this.tdsPercent = newValue;
|
||||
}
|
||||
|
||||
stringChange(command, actualChanges, "transferBranch", this.transferBranch,
|
||||
v -> this.transferBranch = StringUtils.defaultIfEmpty(v, null));
|
||||
stringChange(command, actualChanges, "transferAmountAccountType", this.transferAmountAccountType,
|
||||
v -> this.transferAmountAccountType = StringUtils.defaultIfEmpty(v, null));
|
||||
stringChange(command, actualChanges, "transferAccountNo", this.transferAccountNo,
|
||||
v -> this.transferAccountNo = StringUtils.defaultIfEmpty(v, null));
|
||||
|
||||
if (command.isChangeInBooleanParameterNamed("commissionCalculation", this.commissionCalculation)) {
|
||||
final boolean newValue = command.booleanPrimitiveValueOfParameterNamed("commissionCalculation");
|
||||
actualChanges.put("commissionCalculation", newValue);
|
||||
this.commissionCalculation = newValue;
|
||||
}
|
||||
|
||||
if (command.isChangeInBigDecimalParameterNamed("limit", this.limitAmount)) {
|
||||
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed("limit");
|
||||
actualChanges.put("limit", newValue);
|
||||
this.limitAmount = newValue;
|
||||
}
|
||||
|
||||
if (command.isChangeInBigDecimalParameterNamed("machineRent", this.machineRent)) {
|
||||
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed("machineRent");
|
||||
actualChanges.put("machineRent", newValue);
|
||||
this.machineRent = newValue;
|
||||
}
|
||||
|
||||
stringChange(command, actualChanges, "agentSecurityBranch", this.agentSecurityBranch,
|
||||
v -> this.agentSecurityBranch = StringUtils.defaultIfEmpty(v, null));
|
||||
stringChange(command, actualChanges, "agentSecurityAccountType", this.agentSecurityAccountType,
|
||||
v -> this.agentSecurityAccountType = StringUtils.defaultIfEmpty(v, null));
|
||||
stringChange(command, actualChanges, "agentSecurityAccountNo", this.agentSecurityAccountNo,
|
||||
v -> this.agentSecurityAccountNo = StringUtils.defaultIfEmpty(v, null));
|
||||
|
||||
if (command.isChangeInBigDecimalParameterNamed("otherCommission", this.otherCommission)) {
|
||||
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed("otherCommission");
|
||||
actualChanges.put("otherCommission", newValue);
|
||||
this.otherCommission = newValue;
|
||||
}
|
||||
|
||||
if (command.isChangeInBigDecimalParameterNamed("agentDeposit", this.agentDeposit)) {
|
||||
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed("agentDeposit");
|
||||
actualChanges.put("agentDeposit", newValue);
|
||||
this.agentDeposit = newValue;
|
||||
}
|
||||
|
||||
if (command.isChangeInBigDecimalParameterNamed("festivalAdvance", this.festivalAdvance)) {
|
||||
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed("festivalAdvance");
|
||||
actualChanges.put("festivalAdvance", newValue);
|
||||
this.festivalAdvance = newValue;
|
||||
}
|
||||
|
||||
if (command.isChangeInBigDecimalParameterNamed("otherDeduction", this.otherDeduction)) {
|
||||
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed("otherDeduction");
|
||||
actualChanges.put("otherDeduction", newValue);
|
||||
this.otherDeduction = newValue;
|
||||
}
|
||||
|
||||
return actualChanges;
|
||||
}
|
||||
|
||||
private void stringChange(final JsonCommand command, final Map<String, Object> actualChanges, final String paramName,
|
||||
final String existingValue, final java.util.function.Consumer<String> setter) {
|
||||
if (command.isChangeInStringParameterNamed(paramName, existingValue)) {
|
||||
final String newValue = command.stringValueOfParameterNamed(paramName);
|
||||
actualChanges.put(paramName, newValue);
|
||||
setter.accept(newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
+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.organisation.agent.domain;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
|
||||
|
||||
/**
|
||||
* A single guarantor recorded against an {@link Agent} (or, reused with the same shape, against a
|
||||
* SubAgent). Always created/replaced as part of its parent agent's own create/update command - it has
|
||||
* no independent API of its own.
|
||||
*/
|
||||
@Getter
|
||||
@Entity
|
||||
@Table(name = "m_dds_agent_guarantor")
|
||||
public class AgentGuarantor extends AbstractPersistableCustom<Long> {
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "agent_id", nullable = false)
|
||||
private Agent agent;
|
||||
|
||||
@Column(name = "client_id", nullable = false)
|
||||
private Long clientId;
|
||||
|
||||
@Column(name = "guarantor_name", length = 100, nullable = false)
|
||||
private String guarantorName;
|
||||
|
||||
@Column(name = "address1", length = 200, nullable = false)
|
||||
private String address1;
|
||||
|
||||
@Column(name = "address2", length = 200)
|
||||
private String address2;
|
||||
|
||||
@Column(name = "city", length = 100, nullable = false)
|
||||
private String city;
|
||||
|
||||
@Column(name = "pin_code", length = 20, nullable = false)
|
||||
private String pinCode;
|
||||
|
||||
@Column(name = "telephone", length = 20)
|
||||
private String telephone;
|
||||
|
||||
protected AgentGuarantor() {
|
||||
//
|
||||
}
|
||||
|
||||
public AgentGuarantor(final Long clientId, final String guarantorName, final String address1, final String address2,
|
||||
final String city, final String pinCode, final String telephone) {
|
||||
this.clientId = clientId;
|
||||
this.guarantorName = guarantorName;
|
||||
this.address1 = address1;
|
||||
this.address2 = StringUtils.defaultIfEmpty(address2, null);
|
||||
this.city = city;
|
||||
this.pinCode = pinCode;
|
||||
this.telephone = StringUtils.defaultIfEmpty(telephone, null);
|
||||
}
|
||||
|
||||
void setAgent(final Agent agent) {
|
||||
this.agent = agent;
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* 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.agent.domain;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import lombok.Getter;
|
||||
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
|
||||
|
||||
/**
|
||||
* One row of an Agent's time-bound collection-limit history (From Date / To Date / Limit) - an
|
||||
* Agent's authorized collection limit can change over time and every change is kept, not overwritten.
|
||||
*/
|
||||
@Getter
|
||||
@Entity
|
||||
@Table(name = "m_dds_agent_limit")
|
||||
public class AgentLimit extends AbstractPersistableCustom<Long> {
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "agent_id", nullable = false)
|
||||
private Agent agent;
|
||||
|
||||
@Column(name = "from_date", nullable = false)
|
||||
private LocalDate fromDate;
|
||||
|
||||
@Column(name = "to_date", nullable = false)
|
||||
private LocalDate toDate;
|
||||
|
||||
@Column(name = "limit_amount", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal limitAmount;
|
||||
|
||||
protected AgentLimit() {
|
||||
//
|
||||
}
|
||||
|
||||
public AgentLimit(final LocalDate fromDate, final LocalDate toDate, final BigDecimal limitAmount) {
|
||||
this.fromDate = fromDate;
|
||||
this.toDate = toDate;
|
||||
this.limitAmount = limitAmount;
|
||||
}
|
||||
|
||||
void setAgent(final Agent agent) {
|
||||
this.agent = agent;
|
||||
}
|
||||
}
|
||||
+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.organisation.agent.exception;
|
||||
|
||||
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
|
||||
/**
|
||||
* A {@link RuntimeException} thrown when a DDS agent resource is not found.
|
||||
*/
|
||||
public class AgentNotFoundException extends AbstractPlatformResourceNotFoundException {
|
||||
|
||||
public AgentNotFoundException(final Long id) {
|
||||
super("error.msg.agent.id.invalid", "Agent with identifier " + id + " does not exist", id);
|
||||
}
|
||||
|
||||
public AgentNotFoundException(final Long id, final EmptyResultDataAccessException e) {
|
||||
super("error.msg.agent.id.invalid", "Agent with identifier " + id + " does not exist", id, e);
|
||||
}
|
||||
|
||||
public AgentNotFoundException(final String agentCode) {
|
||||
super("error.msg.agent.code.invalid", "Agent with code " + agentCode + " does not exist", agentCode);
|
||||
}
|
||||
}
|
||||
+16
-7
@@ -16,15 +16,24 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.useradministration.domain;
|
||||
package org.apache.fineract.organisation.commissionslab.data;
|
||||
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
public interface UserPendingRequestRepository extends JpaRepository<UserPendingRequest, Long>, JpaSpecificationExecutor<UserPendingRequest> {
|
||||
@Getter
|
||||
@Builder
|
||||
public final class CommissionSlabData implements Serializable {
|
||||
|
||||
Optional<UserPendingRequest> findByPendingLockKey(String pendingLockKey);
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
boolean existsByPendingLockKey(String pendingLockKey);
|
||||
private final Long id;
|
||||
private final String slabType;
|
||||
private final BigDecimal slabFrom;
|
||||
private final BigDecimal slabTo;
|
||||
private final BigDecimal commissionPercent;
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* 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.commissionslab.domain;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
import java.math.BigDecimal;
|
||||
import lombok.Getter;
|
||||
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
|
||||
|
||||
/**
|
||||
* One row of the agent commission chart: an ACCOUNT slab (commission percentage on collection
|
||||
* volume) or a COMMISSION slab (the override a senior agent earns on a sub-agent's commission).
|
||||
* Append-only reference data, like the legacy screen it replaces - there is deliberately no update or
|
||||
* delete API; a superseded slab range is retired by adding a new row, not editing history.
|
||||
*/
|
||||
@Getter
|
||||
@Entity
|
||||
@Table(name = "m_dds_commission_slab")
|
||||
public class CommissionSlab extends AbstractPersistableCustom<Long> {
|
||||
|
||||
@Column(name = "slab_type", length = 20, nullable = false)
|
||||
private String slabType;
|
||||
|
||||
@Column(name = "slab_from", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal slabFrom;
|
||||
|
||||
@Column(name = "slab_to", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal slabTo;
|
||||
|
||||
@Column(name = "commission_percent", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal commissionPercent;
|
||||
|
||||
protected CommissionSlab() {
|
||||
//
|
||||
}
|
||||
|
||||
public CommissionSlab(final String slabType, final BigDecimal slabFrom, final BigDecimal slabTo, final BigDecimal commissionPercent) {
|
||||
this.slabType = slabType;
|
||||
this.slabFrom = slabFrom;
|
||||
this.slabTo = slabTo;
|
||||
this.commissionPercent = commissionPercent;
|
||||
}
|
||||
}
|
||||
-11
@@ -61,15 +61,4 @@ public class OfficeRepositoryWrapper {
|
||||
public void delete(final Office entity) {
|
||||
this.repository.delete(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes and flushes in the same call, so a foreign-key violation the caller did not already check
|
||||
* for (a savings transaction, a GL journal entry, a teller position -- anything on m_office's long
|
||||
* tail of referencing tables) surfaces synchronously here, inside the caller's own try/catch, rather
|
||||
* than at transaction-commit time where it can no longer be turned into a clean error message.
|
||||
*/
|
||||
public void deleteAndFlush(final Office entity) {
|
||||
this.repository.delete(entity);
|
||||
this.repository.flush();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-16
@@ -72,26 +72,11 @@ public class SavingsAccountSummaryData {
|
||||
// differentiate deposit accounts Savings, FD and RD accounts
|
||||
private final EnumOptionData depositType;
|
||||
|
||||
/**
|
||||
* For a Fixed Deposit, the stable customer-facing FD number: the account number of the first account in the renewal
|
||||
* chain, which stays the same across every renewal even though each term is its own account row. Equals accountNo
|
||||
* for an FD that has never been renewed, and is null for non-deposit accounts.
|
||||
*/
|
||||
private final String fdAccountNumber;
|
||||
/**
|
||||
* Which renewal cycle of that FD this row is: 0 for the originally opened account, 1 for the first renewal, and so
|
||||
* on. Lets a client's account list collapse a renewal chain into one FD instead of listing each term separately.
|
||||
*/
|
||||
private final Integer renewalCycleNo;
|
||||
|
||||
public SavingsAccountSummaryData(final Long id, final String accountNo, final String externalId, final Long productId,
|
||||
final String productName, final String shortProductName, final SavingsAccountStatusEnumData status, final CurrencyData currency,
|
||||
final BigDecimal accountBalance, final BigDecimal onHoldFunds, final BigDecimal savingsAmountOnHold,
|
||||
final BigDecimal availableBalance, final EnumOptionData accountType, final SavingsAccountApplicationTimelineData timeline,
|
||||
final EnumOptionData depositType, final SavingsAccountSubStatusEnumData subStatus, final LocalDate lastActiveTransactionDate,
|
||||
final String fdAccountNumber, final Integer renewalCycleNo) {
|
||||
this.fdAccountNumber = fdAccountNumber;
|
||||
this.renewalCycleNo = renewalCycleNo;
|
||||
final EnumOptionData depositType, final SavingsAccountSubStatusEnumData subStatus, final LocalDate lastActiveTransactionDate) {
|
||||
this.id = id;
|
||||
this.accountNo = accountNo;
|
||||
this.externalId = externalId;
|
||||
|
||||
@@ -78,30 +78,6 @@ public class AmlAlert extends AbstractAuditableWithUTCDateTimeCustom<Long> {
|
||||
@Column(name = "disposition", length = 20)
|
||||
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() {}
|
||||
|
||||
public static AmlAlert raise(AmlTransactionType transactionType, Long transactionId, Client client, AmlTransactionRule rule,
|
||||
@@ -118,58 +94,6 @@ public class AmlAlert extends AbstractAuditableWithUTCDateTimeCustom<Long> {
|
||||
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) {
|
||||
this.reviewedBy = reviewer;
|
||||
this.reviewedOn = LocalDateTime.now();
|
||||
|
||||
-14
@@ -44,18 +44,4 @@ public interface AmlAlertRepository extends JpaRepository<AmlAlert, Long> {
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* 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
@@ -1,163 +0,0 @@
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
-106
@@ -1,106 +0,0 @@
|
||||
/**
|
||||
* 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,7 +26,6 @@ import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import org.apache.fineract.portfolio.client.domain.Client;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
@@ -66,20 +65,6 @@ public class AmlRecurringReview {
|
||||
@Column(name = "reviewed_on", nullable = false)
|
||||
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() {}
|
||||
|
||||
public static AmlRecurringReview record(final Client client, final int alertCountAtReview,
|
||||
@@ -91,22 +76,9 @@ public class AmlRecurringReview {
|
||||
review.notes = notes;
|
||||
review.reviewedBy = reviewedBy;
|
||||
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;
|
||||
}
|
||||
|
||||
/** 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() {
|
||||
return id;
|
||||
}
|
||||
@@ -134,35 +106,4 @@ public class AmlRecurringReview {
|
||||
public LocalDateTime getReviewedOn() {
|
||||
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
@@ -1,83 +0,0 @@
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
-4
@@ -20,7 +20,6 @@ package org.apache.fineract.portfolio.aml.domain;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
@@ -29,9 +28,6 @@ public interface AmlStrCaseRepository extends JpaRepository<AmlStrCase, Long> {
|
||||
|
||||
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);
|
||||
|
||||
@Query("SELECT c FROM AmlStrCase c WHERE c.status = 'CONCLUDED_SUSPICIOUS' AND c.concludedOn BETWEEN :from AND :to")
|
||||
|
||||
-43
@@ -84,49 +84,6 @@ public class AmlTransactionRule {
|
||||
@Column(name = "is_active", nullable = false)
|
||||
private boolean active;
|
||||
|
||||
/**
|
||||
* CREDIT or DEBIT for a rule written about one direction only; null where either way qualifies.
|
||||
* A rule named for withdrawals must not fire on a deposit.
|
||||
*/
|
||||
@Column(name = "direction", length = 10)
|
||||
private String direction;
|
||||
|
||||
/** True where only physical cash qualifies — a cash-reporting rule is not about transfers. */
|
||||
@Column(name = "cash_only", nullable = false)
|
||||
private boolean cashOnly;
|
||||
|
||||
/**
|
||||
* How many transactions must make up the window before a pattern rule fires. Structuring is
|
||||
* many small transactions; without this floor a single large one satisfies the window total and
|
||||
* reads as a pattern it is not.
|
||||
*/
|
||||
@Column(name = "min_transaction_count")
|
||||
private Integer minTransactionCount;
|
||||
|
||||
/**
|
||||
* Which customers a rule is about, where the rule is about the customer rather than the
|
||||
* transaction: PEP, CHARITABLE_ORG, HIGH_RISK_BUSINESS, NEW_ACCOUNT. Null means the rule is
|
||||
* about the transaction alone and so applies to everyone.
|
||||
*/
|
||||
@Column(name = "subject_scope", length = 30)
|
||||
private String subjectScope;
|
||||
|
||||
public String getSubjectScope() {
|
||||
return subjectScope;
|
||||
}
|
||||
|
||||
public String getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public boolean isCashOnly() {
|
||||
return cashOnly;
|
||||
}
|
||||
|
||||
public Integer getMinTransactionCount() {
|
||||
return minTransactionCount;
|
||||
}
|
||||
|
||||
protected AmlTransactionRule() {}
|
||||
|
||||
/**
|
||||
|
||||
-7
@@ -18,7 +18,6 @@
|
||||
*/
|
||||
package org.apache.fineract.portfolio.aml.domain;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
@@ -33,10 +32,4 @@ public interface AmlTransactionRuleRepository extends JpaRepository<AmlTransacti
|
||||
* by hand from the ledger.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
-9
@@ -162,15 +162,6 @@ public class ClientApiConstants {
|
||||
public static final String ageDaysParamName = "ageDays";
|
||||
public static final String nationalityIdParamName = "nationalityId";
|
||||
public static final String isMinorParamName = "isMinor";
|
||||
/**
|
||||
* Below this age a client is treated as a minor: guardian mapping required and a restricted KYC/OVD
|
||||
* document set. Must stay in step with MINOR_AGE_THRESHOLD in the web app's client-age util -- the
|
||||
* KYC template endpoint is authoritative for the document list, so a mismatch would serve an adult
|
||||
* list (with mandatory PAN) for a client the UI classifies as a minor.
|
||||
*/
|
||||
public static final int MINOR_AGE_THRESHOLD = 10;
|
||||
/** At or above this age a client qualifies for senior-citizen deposit rates. */
|
||||
public static final int SENIOR_CITIZEN_AGE_THRESHOLD = 60;
|
||||
public static final String guardianClientIdParamName = "guardianClientId";
|
||||
public static final String guardianClientDisplayNameParamName = "guardianClientDisplayName";
|
||||
public static final String guardianRelationParamName = "guardianRelation";
|
||||
|
||||
-219
@@ -1,219 +0,0 @@
|
||||
/**
|
||||
* 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
@@ -1,43 +0,0 @@
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
+15
-171
@@ -291,31 +291,6 @@ public class ClientKyc extends AbstractAuditableWithUTCDateTimeCustom<Long> {
|
||||
@Column(name = "form15_fy", length = 10)
|
||||
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 ───────────────────────────────────────────────────────────────
|
||||
/** Central KYC Records Registry number issued by CERSAI */
|
||||
@Column(name = "ckyc_number", length = 14)
|
||||
@@ -380,7 +355,7 @@ public class ClientKyc extends AbstractAuditableWithUTCDateTimeCustom<Long> {
|
||||
this.dinVerified = false;
|
||||
this.isException = false;
|
||||
this.exceptionResolved = false;
|
||||
this.initiatedOn = DateUtils.getBusinessLocalDate();
|
||||
this.initiatedOn = DateUtils.getLocalDateOfTenant();
|
||||
}
|
||||
|
||||
public static ClientKyc initiateKyc(final Client client, final JsonCommand command) {
|
||||
@@ -509,14 +484,6 @@ public class ClientKyc extends AbstractAuditableWithUTCDateTimeCustom<Long> {
|
||||
actualChanges.put(riskParam, newValue);
|
||||
recordOverwrite(riskParam, this.riskCategory);
|
||||
this.riskCategory = newValue;
|
||||
|
||||
// The re-KYC cycle is a property of the risk category, so moving the category moves the
|
||||
// due date with it — otherwise a customer raised to High keeps a Low customer's ten-year
|
||||
// renewal and is never called back in for the two-yearly review the rating requires.
|
||||
final LocalDate newExpiry = recalculateExpiryForRiskCategory();
|
||||
if (newExpiry != null) {
|
||||
actualChanges.put("expiryDate", newExpiry);
|
||||
}
|
||||
}
|
||||
|
||||
// remarks is the audit justification itself, so a change to it is deliberately not recorded
|
||||
@@ -552,19 +519,6 @@ public class ClientKyc extends AbstractAuditableWithUTCDateTimeCustom<Long> {
|
||||
v -> this.aadhaarReceiptRemarks = v);
|
||||
updateDateField(command, "aadhaarReceiptTakenOn", this.aadhaarReceiptTakenOn, actualChanges,
|
||||
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, "cinNumber", this.cinNumber, actualChanges, v -> this.cinNumber = v);
|
||||
updateStringField(command, "dinNumber", this.dinNumber, actualChanges, v -> this.dinNumber = v);
|
||||
@@ -600,21 +554,10 @@ public class ClientKyc extends AbstractAuditableWithUTCDateTimeCustom<Long> {
|
||||
v -> this.form15Applicable = v);
|
||||
updateStringField(command, "form15Type", this.form15Type, actualChanges, v -> this.form15Type = v);
|
||||
updateStringField(command, "form15FY", this.form15Fy, actualChanges, v -> this.form15Fy = v);
|
||||
// The four exception columns are derived from whether the identity checks have passed, not
|
||||
// data an officer types, so they are updated without recording an overwrite. A verified
|
||||
// record demands remarks for any field it already held (see
|
||||
// getFieldsOverwrittenByLastUpdate), and is_exception is never null once written — so
|
||||
// counting these would make closing a settled exception impossible without a justification
|
||||
// for something nobody chose. That is what left clients verified on the KYC tab while the
|
||||
// exceptions register still listed them as Pending.
|
||||
updateDerivedBooleanField(command, "isException", this.isException, actualChanges,
|
||||
v -> this.isException = v != null ? v : false);
|
||||
updateDerivedStringField(command, "exceptionReason", this.exceptionReason, actualChanges,
|
||||
v -> this.exceptionReason = v);
|
||||
updateDerivedBooleanField(command, "exceptionResolved", this.exceptionResolved, actualChanges,
|
||||
v -> this.exceptionResolved = v != null ? v : false);
|
||||
updateDerivedDateField(command, "exceptionResolvedOn", this.exceptionResolvedOn, actualChanges,
|
||||
v -> this.exceptionResolvedOn = v);
|
||||
updateBooleanField(command, "isException", this.isException, actualChanges, v -> this.isException = v != null ? v : false);
|
||||
updateStringField(command, "exceptionReason", this.exceptionReason, actualChanges, v -> this.exceptionReason = v);
|
||||
updateBooleanField(command, "exceptionResolved", this.exceptionResolved, actualChanges, v -> this.exceptionResolved = v != null ? v : false);
|
||||
updateDateField(command, "exceptionResolvedOn", this.exceptionResolvedOn, actualChanges, v -> this.exceptionResolvedOn = v);
|
||||
updateBooleanField(command, "panVerified", this.panVerified, actualChanges, v -> this.panVerified = v != null ? v : false);
|
||||
updateBooleanField(command, "aadhaarVerified", this.aadhaarVerified, actualChanges, v -> this.aadhaarVerified = v != null ? v : false);
|
||||
updateBooleanField(command, "gstinVerified", this.gstinVerified, actualChanges, v -> this.gstinVerified = v != null ? v : false);
|
||||
@@ -669,44 +612,6 @@ public class ClientKyc extends AbstractAuditableWithUTCDateTimeCustom<Long> {
|
||||
* populated is the record being completed rather than altered, so it is deliberately not
|
||||
* recorded — see {@link #getFieldsOverwrittenByLastUpdate()}.
|
||||
*/
|
||||
/*
|
||||
* Derived-field variants of the update helpers above.
|
||||
*
|
||||
* Identical, minus the recordOverwrite call: these columns are computed from whether the
|
||||
* identity checks have passed rather than entered by an officer, so replacing one is not the
|
||||
* kind of change a verified record demands a justification for. They still report into
|
||||
* `changes`, so the update is persisted and audited like any other.
|
||||
*/
|
||||
|
||||
private void updateDerivedBooleanField(final JsonCommand command, final String param, final Boolean current,
|
||||
final Map<String, Object> changes, final java.util.function.Consumer<Boolean> setter) {
|
||||
if (command.parameterExists(param)) {
|
||||
final Boolean newValue = command.booleanObjectValueOfParameterNamed(param);
|
||||
if ((newValue == null && current != null) || (newValue != null && !newValue.equals(current))) {
|
||||
changes.put(param, newValue);
|
||||
setter.accept(newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDerivedStringField(final JsonCommand command, final String param, final String current,
|
||||
final Map<String, Object> changes, final java.util.function.Consumer<String> setter) {
|
||||
if (command.isChangeInStringParameterNamed(param, current)) {
|
||||
final String newValue = command.stringValueOfParameterNamed(param);
|
||||
changes.put(param, newValue);
|
||||
setter.accept(StringUtils.defaultIfEmpty(newValue, null));
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDerivedDateField(final JsonCommand command, final String param, final LocalDate current,
|
||||
final Map<String, Object> changes, final java.util.function.Consumer<LocalDate> setter) {
|
||||
if (command.isChangeInLocalDateParameterNamed(param, current)) {
|
||||
final LocalDate newValue = command.localDateValueOfParameterNamed(param);
|
||||
changes.put(param, newValue);
|
||||
setter.accept(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
private void recordOverwrite(final String param, final Object currentValue) {
|
||||
final boolean wasPopulated = currentValue instanceof String text
|
||||
? StringUtils.isNotBlank(text)
|
||||
@@ -757,13 +662,13 @@ public class ClientKyc extends AbstractAuditableWithUTCDateTimeCustom<Long> {
|
||||
public void markCkycUploaded(final String ckycNumber, final String batchId) {
|
||||
this.ckycNumber = StringUtils.defaultIfEmpty(ckycNumber, null);
|
||||
this.ckycBatchId = StringUtils.defaultIfEmpty(batchId, null);
|
||||
this.ckycUploadedOn = DateUtils.getBusinessLocalDate();
|
||||
this.ckycUploadedOn = DateUtils.getLocalDateOfTenant();
|
||||
}
|
||||
|
||||
/** Called after successful 3rd-party verification of all required documents. */
|
||||
public void markVerified(final String ckycNumber) {
|
||||
this.kycStatus = ClientKycStatus.VERIFIED.getValue();
|
||||
this.verifiedOn = DateUtils.getBusinessLocalDate();
|
||||
this.verifiedOn = DateUtils.getLocalDateOfTenant();
|
||||
this.ckycNumber = StringUtils.defaultIfEmpty(ckycNumber, null);
|
||||
|
||||
final KycRiskCategory risk = KycRiskCategory.fromInt(this.riskCategory);
|
||||
@@ -772,45 +677,17 @@ public class ClientKyc extends AbstractAuditableWithUTCDateTimeCustom<Long> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-dates the re-KYC due date after the risk category moves.
|
||||
*
|
||||
* The cycle length belongs to the category the customer is in <em>now</em> (Low 10, Medium 8,
|
||||
* High 2), and it is counted from the day of the change rather than from the original
|
||||
* verification. A customer moved to High in year two of a Low rating is then due in two years'
|
||||
* time, not immediately — dating it from {@code verifiedOn} would push most of the book into
|
||||
* an overdue queue the moment a re-rating ran.
|
||||
*
|
||||
* <p>Only a verified KYC carries an expiry: an unverified record has nothing to renew, and
|
||||
* {@link #markVerified} sets the date when it is first verified.
|
||||
*
|
||||
* @return the new expiry date, or {@code null} if the record carries no expiry
|
||||
*/
|
||||
private LocalDate recalculateExpiryForRiskCategory() {
|
||||
if (this.verifiedOn == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final KycRiskCategory risk = KycRiskCategory.fromInt(this.riskCategory);
|
||||
if (risk.getReKycYears() <= 0) {
|
||||
return this.expiryDate;
|
||||
}
|
||||
|
||||
this.expiryDate = DateUtils.getBusinessLocalDate().plusYears(risk.getReKycYears());
|
||||
return this.expiryDate;
|
||||
}
|
||||
|
||||
/** Called when verification fails. */
|
||||
public void markRejected(final String remarks) {
|
||||
this.kycStatus = ClientKycStatus.REJECTED.getValue();
|
||||
this.rejectedOn = DateUtils.getBusinessLocalDate();
|
||||
this.rejectedOn = DateUtils.getLocalDateOfTenant();
|
||||
this.remarks = StringUtils.defaultIfEmpty(remarks, this.remarks);
|
||||
}
|
||||
|
||||
public void markPanVerified(final String fullName, final String firstName, final String lastName,
|
||||
final String aadhaarSeedingStatus, final String category, final String status) {
|
||||
this.panVerified = true;
|
||||
this.panVerifiedOn = DateUtils.getBusinessLocalDate();
|
||||
this.panVerifiedOn = DateUtils.getLocalDateOfTenant();
|
||||
this.panFullName = StringUtils.defaultIfEmpty(fullName, null);
|
||||
this.panFirstName = StringUtils.defaultIfEmpty(firstName, null);
|
||||
this.panLastName = StringUtils.defaultIfEmpty(lastName, null);
|
||||
@@ -836,28 +713,28 @@ public class ClientKyc extends AbstractAuditableWithUTCDateTimeCustom<Long> {
|
||||
|
||||
public void markAadhaarVerified() {
|
||||
this.aadhaarVerified = true;
|
||||
this.aadhaarVerifiedOn = DateUtils.getBusinessLocalDate();
|
||||
this.aadhaarVerifiedOn = DateUtils.getLocalDateOfTenant();
|
||||
}
|
||||
|
||||
public void markGstinVerified() {
|
||||
this.gstinVerified = true;
|
||||
this.gstinVerifiedOn = DateUtils.getBusinessLocalDate();
|
||||
this.gstinVerifiedOn = DateUtils.getLocalDateOfTenant();
|
||||
}
|
||||
|
||||
public void markCinVerified() {
|
||||
this.cinVerified = true;
|
||||
this.cinVerifiedOn = DateUtils.getBusinessLocalDate();
|
||||
this.cinVerifiedOn = DateUtils.getLocalDateOfTenant();
|
||||
}
|
||||
|
||||
public void markDinVerified() {
|
||||
this.dinVerified = true;
|
||||
this.dinVerifiedOn = DateUtils.getBusinessLocalDate();
|
||||
this.dinVerifiedOn = DateUtils.getLocalDateOfTenant();
|
||||
}
|
||||
|
||||
public void markDinVerified(final String dinNumber, final String mcaResponseJson) {
|
||||
this.dinNumber = dinNumber;
|
||||
this.dinVerified = true;
|
||||
this.dinVerifiedOn = DateUtils.getBusinessLocalDate();
|
||||
this.dinVerifiedOn = DateUtils.getLocalDateOfTenant();
|
||||
this.isDirector = true;
|
||||
this.dinMcaResponse = mcaResponseJson;
|
||||
}
|
||||
@@ -878,17 +755,7 @@ public class ClientKyc extends AbstractAuditableWithUTCDateTimeCustom<Long> {
|
||||
} else if (type != null && type.isNonIndividual()) {
|
||||
allDone = this.panVerified && this.gstinVerified;
|
||||
}
|
||||
// Re-stamped even when the record already reads VERIFIED, because that is exactly what a
|
||||
// periodic re-KYC is: an already-verified customer verified afresh.
|
||||
//
|
||||
// Skipping it there left verifiedOn — and with it the expiry date, and the dormancy clock
|
||||
// that now measures from it — frozen at the original onboarding. An officer who re-verified
|
||||
// both PAN and Aadhaar at the counter saw both rows stamped with today's date and the
|
||||
// account still sitting on the inactive report, with nothing to say what was missing.
|
||||
//
|
||||
// Guarded on the verifications rather than the status, so this only fires when the checks
|
||||
// that constitute a verification have actually been done again.
|
||||
if (allDone) {
|
||||
if (allDone && !getKycStatus().isVerified()) {
|
||||
markVerified(this.ckycNumber);
|
||||
}
|
||||
return allDone;
|
||||
@@ -931,29 +798,6 @@ public class ClientKyc extends AbstractAuditableWithUTCDateTimeCustom<Long> {
|
||||
*/
|
||||
public void escalateRiskCategory(Integer newCategory) {
|
||||
this.riskCategory = newCategory;
|
||||
// An auto-escalation moves the rating for the same reason an officer would, so it moves the
|
||||
// re-KYC due date on the same terms — see 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() {
|
||||
|
||||
-13
@@ -18,7 +18,6 @@
|
||||
*/
|
||||
package org.apache.fineract.portfolio.client.domain;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
@@ -49,18 +48,6 @@ public interface ClientKycRepository extends JpaRepository<ClientKyc, Long> {
|
||||
@Query("SELECT k FROM ClientKyc k WHERE k.kycStatus = :status")
|
||||
List<ClientKyc> findAllByStatus(@Param("status") Integer status);
|
||||
|
||||
/**
|
||||
* KYC records whose periodic re-KYC due date has passed, oldest first.
|
||||
*
|
||||
* <p>Only records that carry an expiry are considered: an expiry is set when the KYC is first
|
||||
* verified, so one without a date has never been verified and has no renewal cycle to lapse.
|
||||
* A rejected record is excluded for the same reason — it is not a lapsed KYC, it is one that
|
||||
* never took effect, and restricting an account over it would punish the wrong thing.
|
||||
*/
|
||||
@Query("SELECT k FROM ClientKyc k WHERE k.expiryDate IS NOT NULL AND k.expiryDate <= :asOn "
|
||||
+ "AND k.kycStatus <> :rejectedStatus ORDER BY k.expiryDate ASC")
|
||||
List<ClientKyc> findLapsedAsOn(@Param("asOn") LocalDate asOn, @Param("rejectedStatus") Integer rejectedStatus);
|
||||
|
||||
// ── Pre-KYC uniqueness probes ───────────────────────────────────────────
|
||||
// Why: stop a second client from being created with the same PAN / Aadhaar / GSTIN BEFORE the
|
||||
// external KYC API is called, so we don't burn vendor calls on duplicate-identity records. PAN
|
||||
|
||||
+1
-35
@@ -93,26 +93,6 @@ public class ClientRiskRule {
|
||||
@Column(name = "order_position", nullable = false)
|
||||
private Integer orderPosition;
|
||||
|
||||
/**
|
||||
* Which of the two rule families this row belongs to - {@link #KIND_KYC} or {@link #KIND_AML}.
|
||||
*
|
||||
* This table carries both, and they are not interchangeable. A KYC rule is profile-driven: it
|
||||
* reads occupation / income / turnover to categorise a customer at onboarding (RBI Master
|
||||
* Direction on KYC, Section 12). An AML rule is behaviour-driven: it describes a transaction
|
||||
* pattern and may only fire against posted transactions, surfacing in {@code m_aml_alert}
|
||||
* (Section 13).
|
||||
*
|
||||
* The distinction used to be inferred from "has no criteria set", which migration 0448 erased
|
||||
* by writing 0.0 over the NULLs - after which transaction-monitoring rules began matching
|
||||
* ordinary customers at onboarding and pre-flagging them for AML. Recording the kind means a
|
||||
* rule states what it is; nothing has to guess from the shape of its other columns.
|
||||
*/
|
||||
@Column(name = "rule_kind", length = 10)
|
||||
private String ruleKind;
|
||||
|
||||
public static final String KIND_KYC = "KYC";
|
||||
public static final String KIND_AML = "AML";
|
||||
|
||||
protected ClientRiskRule() {}
|
||||
|
||||
/**
|
||||
@@ -124,9 +104,8 @@ public class ClientRiskRule {
|
||||
final BigDecimal maxMonthlyIncome, final BigDecimal minAnnualIncome, final BigDecimal maxAnnualIncome,
|
||||
final BigDecimal minAnnualTurnover, final BigDecimal maxAnnualTurnover, final String amlCheckStatus,
|
||||
final String bannedEntityMatch, final String willfulDefaulter, final String ecgcSalFlag,
|
||||
final String dormantFlag, final String ruleKind) {
|
||||
final String dormantFlag) {
|
||||
final ClientRiskRule rule = new ClientRiskRule();
|
||||
rule.ruleKind = ruleKind;
|
||||
rule.ruleName = ruleName;
|
||||
rule.reason = reason;
|
||||
rule.riskCategory = riskCategory;
|
||||
@@ -158,19 +137,6 @@ public class ClientRiskRule {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getRuleKind() {
|
||||
return ruleKind;
|
||||
}
|
||||
|
||||
/**
|
||||
* True when this rule may take part in onboarding risk categorisation. Rows predating the
|
||||
* rule_kind column are treated as KYC, matching how they behaved before AML rules were seeded
|
||||
* into the same table.
|
||||
*/
|
||||
public boolean isKycRule() {
|
||||
return !KIND_AML.equalsIgnoreCase(this.ruleKind);
|
||||
}
|
||||
|
||||
public String getRuleName() {
|
||||
return ruleName;
|
||||
}
|
||||
|
||||
-106
@@ -1,106 +0,0 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* How far an account has travelled down the restriction ladder after its periodic re-KYC lapsed.
|
||||
*
|
||||
* <p>
|
||||
* RBI's Master Direction on KYC does not treat an overdue re-KYC as grounds to shut a customer out.
|
||||
* The 2021 amendment (DOR.AML.REC.13/14.01.001/2021-22) is explicit that an account is not to be
|
||||
* closed merely because periodic KYC is pending, and that any restriction follows notice and a fair
|
||||
* opportunity to comply. The ladder therefore leaves the account untouched for a grace period,
|
||||
* stops debits before it stops anything else, and never reaches closure on its own — closure stays
|
||||
* a manual decision with its own notice.
|
||||
*
|
||||
* <p>
|
||||
* The day counts are bank policy rather than a regulatory figure — the Direction requires "adequate
|
||||
* notice" without fixing a number — so they are declared here once and read from here everywhere.
|
||||
*/
|
||||
public enum KycExpiryStage {
|
||||
|
||||
/**
|
||||
* Inside the grace window. Nothing is restricted; the customer is being chased.
|
||||
*/
|
||||
GRACE(0),
|
||||
|
||||
/**
|
||||
* Debits stopped, credits still accepted. The first actual restriction, and the one that brings
|
||||
* the customer into the branch without putting their incoming money at risk.
|
||||
*/
|
||||
PARTIAL_FREEZE(90),
|
||||
|
||||
/**
|
||||
* Both directions restricted, barring the credits that must always be let through.
|
||||
*/
|
||||
INOPERATIVE(180);
|
||||
|
||||
/** Days past the expiry date at which this stage begins. */
|
||||
private final int fromDaysOverdue;
|
||||
|
||||
KycExpiryStage(final int fromDaysOverdue) {
|
||||
this.fromDaysOverdue = fromDaysOverdue;
|
||||
}
|
||||
|
||||
public int getFromDaysOverdue() {
|
||||
return fromDaysOverdue;
|
||||
}
|
||||
|
||||
/**
|
||||
* The stage an account sits at, given how far past its re-KYC due date it is.
|
||||
*
|
||||
* @param daysOverdue
|
||||
* days since the expiry date; zero or negative means the KYC has not lapsed
|
||||
* @return the stage, or {@code null} where the KYC is still current and nothing applies
|
||||
*/
|
||||
public static KycExpiryStage fromDaysOverdue(final long daysOverdue) {
|
||||
if (daysOverdue < 0) {
|
||||
return null;
|
||||
}
|
||||
if (daysOverdue >= INOPERATIVE.fromDaysOverdue) {
|
||||
return INOPERATIVE;
|
||||
}
|
||||
if (daysOverdue >= PARTIAL_FREEZE.fromDaysOverdue) {
|
||||
return PARTIAL_FREEZE;
|
||||
}
|
||||
return GRACE;
|
||||
}
|
||||
|
||||
public boolean isGrace() {
|
||||
return this == GRACE;
|
||||
}
|
||||
|
||||
public boolean isPartialFreeze() {
|
||||
return this == PARTIAL_FREEZE;
|
||||
}
|
||||
|
||||
public boolean isInoperative() {
|
||||
return this == INOPERATIVE;
|
||||
}
|
||||
|
||||
/** Whether debits should be stopped at this stage. */
|
||||
public boolean blocksDebits() {
|
||||
return this == PARTIAL_FREEZE || this == INOPERATIVE;
|
||||
}
|
||||
|
||||
/** Whether ordinary credits should be stopped at this stage. */
|
||||
public boolean blocksCredits() {
|
||||
return this == INOPERATIVE;
|
||||
}
|
||||
}
|
||||
-74
@@ -1,74 +0,0 @@
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* 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.dds.batch.data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Collection;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Builder(toBuilder = true)
|
||||
public final class BatchRunData implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Long id;
|
||||
private final String jobType;
|
||||
private final String branchScope;
|
||||
private final LocalDate jobDate;
|
||||
private final Long agentFrom;
|
||||
private final Long agentTo;
|
||||
private final Long partyFrom;
|
||||
private final Long partyTo;
|
||||
private final String status;
|
||||
private final Integer totalRows;
|
||||
private final BigDecimal totalAmount;
|
||||
private final LocalDate generatedOnDate;
|
||||
private final LocalDate postedOnDate;
|
||||
private final Collection<BatchRunRowData> rows;
|
||||
}
|
||||
+18
-7
@@ -16,15 +16,26 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.useradministration.service;
|
||||
package org.apache.fineract.portfolio.dds.batch.data;
|
||||
|
||||
import org.apache.fineract.infrastructure.core.service.Page;
|
||||
import org.apache.fineract.useradministration.data.UserPendingRequestData;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
public interface UserPendingReadPlatformService {
|
||||
@Getter
|
||||
@Builder
|
||||
public final class BatchRunRowData implements Serializable {
|
||||
|
||||
Page<UserPendingRequestData> retrieveAllPendingRequests(String status, String username, String fromDate, String toDate,
|
||||
Integer offset, Integer limit);
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
UserPendingRequestData retrievePendingRequest(Long id);
|
||||
private final Long id;
|
||||
private final Long partyId;
|
||||
private final String partyCode;
|
||||
private final String partyName;
|
||||
private final Long agentId;
|
||||
private final String agentCode;
|
||||
private final BigDecimal amount;
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
* 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.dds.batch.domain;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.OrderBy;
|
||||
import jakarta.persistence.Table;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
|
||||
|
||||
/**
|
||||
* One Calculate-then-Post batch run - the deliberate two-step control from the legacy Interest Part
|
||||
* menu (Interest Calculation -> Interest Posting, OD Interest Calculation -> OD Interest Posting,
|
||||
* Commission Calculation -> Commission Posting): a run is generated (rows computed and saved as a
|
||||
* preview, nothing else changes), then posted (a separate, explicit step that applies exactly the
|
||||
* rows that were previewed - never a fresh recalculation, so what gets applied is always what was
|
||||
* seen).
|
||||
*/
|
||||
@Getter
|
||||
@Entity
|
||||
@Table(name = "m_dds_batch_run")
|
||||
public class BatchRun extends AbstractPersistableCustom<Long> {
|
||||
|
||||
@Column(name = "job_type", length = 40, nullable = false)
|
||||
private String jobType;
|
||||
|
||||
@Column(name = "branch_scope", length = 20, nullable = false)
|
||||
private String branchScope;
|
||||
|
||||
@Column(name = "job_date", nullable = false)
|
||||
private LocalDate jobDate;
|
||||
|
||||
@Column(name = "agent_from", nullable = false)
|
||||
private Long agentFrom;
|
||||
|
||||
@Column(name = "agent_to", nullable = false)
|
||||
private Long agentTo;
|
||||
|
||||
@Column(name = "party_from")
|
||||
private Long partyFrom;
|
||||
|
||||
@Column(name = "party_to")
|
||||
private Long partyTo;
|
||||
|
||||
@Column(name = "status", length = 20, nullable = false)
|
||||
private String status;
|
||||
|
||||
@Column(name = "total_rows", nullable = false)
|
||||
private Integer totalRows;
|
||||
|
||||
@Column(name = "total_amount", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal totalAmount;
|
||||
|
||||
@Column(name = "generated_on_date", nullable = false)
|
||||
private LocalDate generatedOnDate;
|
||||
|
||||
@Column(name = "posted_on_date")
|
||||
private LocalDate postedOnDate;
|
||||
|
||||
@OneToMany(mappedBy = "batchRun", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
||||
@OrderBy("id")
|
||||
private List<BatchRunRow> rows = new ArrayList<>();
|
||||
|
||||
protected BatchRun() {
|
||||
//
|
||||
}
|
||||
|
||||
public BatchRun(final String jobType, final String branchScope, final LocalDate jobDate, final Long agentFrom,
|
||||
final Long agentTo, final Long partyFrom, final Long partyTo, final LocalDate generatedOnDate) {
|
||||
this.jobType = jobType;
|
||||
this.branchScope = branchScope;
|
||||
this.jobDate = jobDate;
|
||||
this.agentFrom = agentFrom;
|
||||
this.agentTo = agentTo;
|
||||
this.partyFrom = partyFrom;
|
||||
this.partyTo = partyTo;
|
||||
this.status = "CALCULATED";
|
||||
this.totalRows = 0;
|
||||
this.totalAmount = BigDecimal.ZERO;
|
||||
this.generatedOnDate = generatedOnDate;
|
||||
}
|
||||
|
||||
public void addRow(final BatchRunRow row) {
|
||||
row.setBatchRun(this);
|
||||
this.rows.add(row);
|
||||
this.totalRows = this.rows.size();
|
||||
this.totalAmount = this.totalAmount.add(row.getAmount());
|
||||
}
|
||||
|
||||
public boolean isPosted() {
|
||||
return "POSTED".equals(this.status);
|
||||
}
|
||||
|
||||
public void markPosted(final LocalDate postedOnDate) {
|
||||
this.status = "POSTED";
|
||||
this.postedOnDate = postedOnDate;
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* 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.dds.batch.domain;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import java.math.BigDecimal;
|
||||
import lombok.Getter;
|
||||
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
|
||||
|
||||
/**
|
||||
* One previewed/posted line of a {@link BatchRun}: for an interest job, one Party's accrued interest;
|
||||
* for a commission job, one Agent's commission on their collected volume (partyId is null there).
|
||||
*/
|
||||
@Getter
|
||||
@Entity
|
||||
@Table(name = "m_dds_batch_run_row")
|
||||
public class BatchRunRow extends AbstractPersistableCustom<Long> {
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "batch_run_id", nullable = false)
|
||||
private BatchRun batchRun;
|
||||
|
||||
@Column(name = "party_id")
|
||||
private Long partyId;
|
||||
|
||||
@Column(name = "agent_id", nullable = false)
|
||||
private Long agentId;
|
||||
|
||||
@Column(name = "amount", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal amount;
|
||||
|
||||
protected BatchRunRow() {
|
||||
//
|
||||
}
|
||||
|
||||
public BatchRunRow(final Long partyId, final Long agentId, final BigDecimal amount) {
|
||||
this.partyId = partyId;
|
||||
this.agentId = agentId;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
void setBatchRun(final BatchRun batchRun) {
|
||||
this.batchRun = batchRun;
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* 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.dds.batch.exception;
|
||||
|
||||
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException;
|
||||
|
||||
/**
|
||||
* Thrown when Post is attempted on a batch run that has already been posted - a run applies once,
|
||||
* matching the calculate-then-post safety control (never re-post the same preview).
|
||||
*/
|
||||
public class BatchRunAlreadyPostedException extends AbstractPlatformDomainRuleException {
|
||||
|
||||
public BatchRunAlreadyPostedException(final Long batchRunId) {
|
||||
super("error.msg.ddsbatchrun.already.posted", "DDS batch run " + batchRunId + " has already been posted", batchRunId);
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -16,13 +16,13 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.useradministration.exception;
|
||||
package org.apache.fineract.portfolio.dds.batch.exception;
|
||||
|
||||
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
|
||||
|
||||
public class UserPendingRequestNotFoundException extends AbstractPlatformResourceNotFoundException {
|
||||
public class BatchRunNotFoundException extends AbstractPlatformResourceNotFoundException {
|
||||
|
||||
public UserPendingRequestNotFoundException(final Long id) {
|
||||
super("error.msg.userpendingrequest.id.invalid", "User pending request with identifier " + id + " does not exist", id);
|
||||
public BatchRunNotFoundException(final Long id) {
|
||||
super("error.msg.ddsbatchrun.id.invalid", "DDS batch run with identifier " + id + " does not exist", id);
|
||||
}
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* 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.dds.party.data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Collection;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Immutable data object representing a DDS Party (customer scheme account), including its nominees.
|
||||
* Built via the Lombok builder rather than a long positional constructor - the field count here makes
|
||||
* positional args unreadable and error-prone to keep in sync.
|
||||
*/
|
||||
@Getter
|
||||
@Builder(toBuilder = true)
|
||||
public final class PartyData implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Long id;
|
||||
private final Long clientId;
|
||||
private final String clientName;
|
||||
private final Long agentId;
|
||||
private final String agentCode;
|
||||
private final String agentName;
|
||||
private final Long savingsAccountId;
|
||||
private final String subType;
|
||||
private final String partyCode;
|
||||
private final String lastAccount;
|
||||
private final Boolean nominal;
|
||||
private final String aadharNo;
|
||||
private final String partyName;
|
||||
private final String partyName1;
|
||||
private final String address1;
|
||||
private final String address2;
|
||||
private final String address3;
|
||||
private final String city;
|
||||
private final String pincode;
|
||||
private final String gender;
|
||||
private final String panCardNo;
|
||||
private final String telephone;
|
||||
private final String mobileNoSms;
|
||||
private final String operation;
|
||||
private final LocalDate birthDate;
|
||||
private final String occupation;
|
||||
private final String risk;
|
||||
private final String ckycId;
|
||||
private final String adultMinor;
|
||||
private final LocalDate minorDate;
|
||||
private final Long guardianClientId;
|
||||
private final String minAccountOpt;
|
||||
private final String relation;
|
||||
private final LocalDate openingDate;
|
||||
private final Integer month;
|
||||
private final LocalDate maturityDate;
|
||||
private final LocalDate reopenDate;
|
||||
private final BigDecimal depositAmount;
|
||||
private final BigDecimal dailyDepositAmount;
|
||||
private final Integer days;
|
||||
private final String ledgerNo;
|
||||
private final BigDecimal maturityAmount;
|
||||
private final BigDecimal interestRate;
|
||||
private final String withdrawType;
|
||||
private final Boolean od1Flag;
|
||||
private final Boolean od2Flag;
|
||||
private final Boolean lien;
|
||||
private final LocalDate payDate;
|
||||
private final BigDecimal paymentAmount;
|
||||
private final BigDecimal currentBalance;
|
||||
private final BigDecimal openingBalance;
|
||||
private final Boolean isSmsActive;
|
||||
private final Boolean isEmailActive;
|
||||
private final BigDecimal interestCalc;
|
||||
private final LocalDate interestDate;
|
||||
private final String spDescription;
|
||||
private final String freezeCode;
|
||||
private final String advCode;
|
||||
private final String creditToBranch;
|
||||
private final String creditToAccountType;
|
||||
private final String creditToAccount;
|
||||
private final Boolean nomineeApplicable;
|
||||
private final String nomineeSplitMode;
|
||||
private final String status;
|
||||
private final LocalDate closeDate;
|
||||
private final Collection<PartyNomineeData> nominees;
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* 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.dds.party.data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public final class PartyNomineeData implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Long id;
|
||||
private final LocalDate nominationDate;
|
||||
private final String name;
|
||||
private final String mobileNo;
|
||||
private final LocalDate birthDate;
|
||||
private final Boolean minor;
|
||||
private final String relation;
|
||||
private final String gender;
|
||||
private final String guardianName;
|
||||
|
||||
public static PartyNomineeData instance(final Long id, final LocalDate nominationDate, final String name, final String mobileNo,
|
||||
final LocalDate birthDate, final Boolean minor, final String relation, final String gender, final String guardianName) {
|
||||
return new PartyNomineeData(id, nominationDate, name, mobileNo, birthDate, minor, relation, gender, guardianName);
|
||||
}
|
||||
|
||||
private PartyNomineeData(final Long id, final LocalDate nominationDate, final String name, final String mobileNo,
|
||||
final LocalDate birthDate, final Boolean minor, final String relation, final String gender, final String guardianName) {
|
||||
this.id = id;
|
||||
this.nominationDate = nominationDate;
|
||||
this.name = name;
|
||||
this.mobileNo = mobileNo;
|
||||
this.birthDate = birthDate;
|
||||
this.minor = minor;
|
||||
this.relation = relation;
|
||||
this.gender = gender;
|
||||
this.guardianName = guardianName;
|
||||
}
|
||||
}
|
||||
+569
@@ -0,0 +1,569 @@
|
||||
/**
|
||||
* 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.dds.party.domain;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.OrderBy;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.UniqueConstraint;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
||||
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
|
||||
import org.apache.fineract.organisation.agent.domain.Agent;
|
||||
import org.apache.fineract.portfolio.client.domain.Client;
|
||||
|
||||
/**
|
||||
* A DDS Party - the customer's daily-deposit scheme account, linked to the Agent who collects for it.
|
||||
* Carries the scheme's KYC, terms and two-stage overdue flags, plus a nominee list.
|
||||
*
|
||||
* The underlying RD (recurring deposit) account this scheme conceptually reuses is not wired up yet -
|
||||
* {@code savingsAccountId} is a nullable placeholder for that future linkage (see the DDS architecture
|
||||
* decision to reuse the RD engine for the deposit half). Until then the scheme/balance fields below
|
||||
* are this record's own, not mirrored from any m_savings_account row.
|
||||
*/
|
||||
@Getter
|
||||
@Entity
|
||||
@Table(name = "m_dds_party", uniqueConstraints = { @UniqueConstraint(columnNames = { "party_code" }, name = "party_code_UNIQUE") })
|
||||
public class Party extends AbstractPersistableCustom<Long> {
|
||||
|
||||
/** DDS accounts carry a flat interest rate unless the officer explicitly overrides it at creation. */
|
||||
private static final BigDecimal DEFAULT_INTEREST_RATE = new BigDecimal("2");
|
||||
|
||||
public static final String STATUS_ACTIVE = "ACTIVE";
|
||||
public static final String STATUS_CLOSED = "CLOSED";
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "client_id", nullable = false)
|
||||
private Client client;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "agent_id", nullable = false)
|
||||
private Agent agent;
|
||||
|
||||
@Column(name = "savings_account_id")
|
||||
private Long savingsAccountId;
|
||||
|
||||
@Column(name = "sub_type", length = 60, nullable = false)
|
||||
private String subType;
|
||||
|
||||
@Column(name = "party_code", length = 20, nullable = false)
|
||||
private String partyCode;
|
||||
|
||||
@Column(name = "last_account", length = 50)
|
||||
private String lastAccount;
|
||||
|
||||
@Column(name = "nominal", nullable = false)
|
||||
private boolean nominal;
|
||||
|
||||
@Column(name = "aadhar_no", length = 20)
|
||||
private String aadharNo;
|
||||
|
||||
@Column(name = "party_name", length = 100, nullable = false)
|
||||
private String partyName;
|
||||
|
||||
@Column(name = "party_name1", length = 100)
|
||||
private String partyName1;
|
||||
|
||||
@Column(name = "address1", length = 200, nullable = false)
|
||||
private String address1;
|
||||
|
||||
@Column(name = "address2", length = 200)
|
||||
private String address2;
|
||||
|
||||
@Column(name = "address3", length = 200)
|
||||
private String address3;
|
||||
|
||||
@Column(name = "city", length = 100, nullable = false)
|
||||
private String city;
|
||||
|
||||
@Column(name = "pincode", length = 20, nullable = false)
|
||||
private String pincode;
|
||||
|
||||
@Column(name = "gender", length = 20)
|
||||
private String gender;
|
||||
|
||||
@Column(name = "pan_card_no", length = 20)
|
||||
private String panCardNo;
|
||||
|
||||
@Column(name = "telephone", length = 20)
|
||||
private String telephone;
|
||||
|
||||
@Column(name = "mobile_no_sms", length = 20, nullable = false)
|
||||
private String mobileNoSms;
|
||||
|
||||
@Column(name = "operation", length = 20, nullable = false)
|
||||
private String operation;
|
||||
|
||||
@Column(name = "birth_date")
|
||||
private LocalDate birthDate;
|
||||
|
||||
@Column(name = "occupation", length = 40)
|
||||
private String occupation;
|
||||
|
||||
@Column(name = "risk", length = 20)
|
||||
private String risk;
|
||||
|
||||
@Column(name = "ckyc_id", length = 40)
|
||||
private String ckycId;
|
||||
|
||||
@Column(name = "adult_minor", length = 20, nullable = false)
|
||||
private String adultMinor;
|
||||
|
||||
@Column(name = "minor_date")
|
||||
private LocalDate minorDate;
|
||||
|
||||
@Column(name = "guardian_client_id")
|
||||
private Long guardianClientId;
|
||||
|
||||
@Column(name = "min_account_opt", length = 40)
|
||||
private String minAccountOpt;
|
||||
|
||||
@Column(name = "relation", length = 40)
|
||||
private String relation;
|
||||
|
||||
@Column(name = "opening_date", nullable = false)
|
||||
private LocalDate openingDate;
|
||||
|
||||
@Column(name = "months")
|
||||
private Integer month;
|
||||
|
||||
@Column(name = "maturity_date")
|
||||
private LocalDate maturityDate;
|
||||
|
||||
@Column(name = "reopen_date")
|
||||
private LocalDate reopenDate;
|
||||
|
||||
@Column(name = "deposit_amount", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal depositAmount;
|
||||
|
||||
@Column(name = "daily_deposit_amount", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal dailyDepositAmount;
|
||||
|
||||
@Column(name = "days", nullable = false)
|
||||
private Integer days;
|
||||
|
||||
@Column(name = "ledger_no", length = 40)
|
||||
private String ledgerNo;
|
||||
|
||||
@Column(name = "maturity_amount", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal maturityAmount;
|
||||
|
||||
@Column(name = "interest_rate", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal interestRate;
|
||||
|
||||
@Column(name = "withdraw_type", length = 20)
|
||||
private String withdrawType;
|
||||
|
||||
@Column(name = "od1_flag", nullable = false)
|
||||
private boolean od1Flag;
|
||||
|
||||
@Column(name = "od2_flag", nullable = false)
|
||||
private boolean od2Flag;
|
||||
|
||||
@Column(name = "lien", nullable = false)
|
||||
private boolean lien;
|
||||
|
||||
@Column(name = "pay_date")
|
||||
private LocalDate payDate;
|
||||
|
||||
@Column(name = "payment_amount", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal paymentAmount;
|
||||
|
||||
@Column(name = "current_balance", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal currentBalance;
|
||||
|
||||
@Column(name = "opening_balance", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal openingBalance;
|
||||
|
||||
@Column(name = "is_sms_active", nullable = false)
|
||||
private boolean isSmsActive;
|
||||
|
||||
@Column(name = "is_email_active", nullable = false)
|
||||
private boolean isEmailActive;
|
||||
|
||||
@Column(name = "interest_calc", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal interestCalc;
|
||||
|
||||
@Column(name = "interest_date")
|
||||
private LocalDate interestDate;
|
||||
|
||||
@Column(name = "sp_description", length = 500)
|
||||
private String spDescription;
|
||||
|
||||
@Column(name = "freeze_code", length = 20, nullable = false)
|
||||
private String freezeCode;
|
||||
|
||||
@Column(name = "adv_code", length = 40, nullable = false)
|
||||
private String advCode;
|
||||
|
||||
@Column(name = "credit_to_branch", length = 100)
|
||||
private String creditToBranch;
|
||||
|
||||
@Column(name = "credit_to_account_type", length = 100)
|
||||
private String creditToAccountType;
|
||||
|
||||
@Column(name = "credit_to_account", length = 50)
|
||||
private String creditToAccount;
|
||||
|
||||
@Column(name = "nominee_applicable", nullable = false)
|
||||
private boolean nomineeApplicable;
|
||||
|
||||
@Column(name = "nominee_split_mode", length = 20)
|
||||
private String nomineeSplitMode;
|
||||
|
||||
@Column(name = "status", length = 20, nullable = false)
|
||||
private String status;
|
||||
|
||||
@Column(name = "close_date")
|
||||
private LocalDate closeDate;
|
||||
|
||||
@OneToMany(mappedBy = "party", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
||||
@OrderBy("id")
|
||||
private List<PartyNominee> nominees = new ArrayList<>();
|
||||
|
||||
protected Party() {
|
||||
//
|
||||
}
|
||||
|
||||
private Party(final Client client, final Agent agent, final String partyCode, final JsonCommand command) {
|
||||
this.client = client;
|
||||
this.agent = agent;
|
||||
this.partyCode = partyCode;
|
||||
this.subType = command.stringValueOfParameterNamed("subType");
|
||||
this.lastAccount = command.stringValueOfParameterNamedAllowingNull("lastAccount");
|
||||
this.nominal = command.booleanPrimitiveValueOfParameterNamed("nominal");
|
||||
this.aadharNo = command.stringValueOfParameterNamedAllowingNull("aadharNo");
|
||||
this.partyName = command.stringValueOfParameterNamed("partyName");
|
||||
this.partyName1 = command.stringValueOfParameterNamedAllowingNull("partyName1");
|
||||
this.address1 = command.stringValueOfParameterNamed("address1");
|
||||
this.address2 = command.stringValueOfParameterNamedAllowingNull("address2");
|
||||
this.address3 = command.stringValueOfParameterNamedAllowingNull("address3");
|
||||
this.city = command.stringValueOfParameterNamed("city");
|
||||
this.pincode = command.stringValueOfParameterNamed("pincode");
|
||||
this.gender = command.stringValueOfParameterNamedAllowingNull("gender");
|
||||
this.panCardNo = command.stringValueOfParameterNamedAllowingNull("panCardNo");
|
||||
this.telephone = command.stringValueOfParameterNamedAllowingNull("telephone");
|
||||
this.mobileNoSms = command.stringValueOfParameterNamed("mobileNoSms");
|
||||
this.operation = command.stringValueOfParameterNamed("operation");
|
||||
this.birthDate = command.localDateValueOfParameterNamed("birthDate");
|
||||
this.occupation = command.stringValueOfParameterNamedAllowingNull("occupation");
|
||||
this.risk = command.stringValueOfParameterNamedAllowingNull("risk");
|
||||
this.ckycId = command.stringValueOfParameterNamedAllowingNull("ckycId");
|
||||
this.adultMinor = command.stringValueOfParameterNamed("adultMinor");
|
||||
this.minorDate = command.localDateValueOfParameterNamed("minorDate");
|
||||
this.guardianClientId = command.longValueOfParameterNamed("guardianClientId");
|
||||
this.minAccountOpt = command.stringValueOfParameterNamedAllowingNull("minAccountOpt");
|
||||
this.relation = command.stringValueOfParameterNamedAllowingNull("relation");
|
||||
this.openingDate = command.localDateValueOfParameterNamed("openingDate");
|
||||
this.month = command.integerValueOfParameterNamedDefaultToNullIfZero("month");
|
||||
this.maturityDate = command.localDateValueOfParameterNamed("maturityDate");
|
||||
this.reopenDate = command.localDateValueOfParameterNamed("reopenDate");
|
||||
this.depositAmount = orZero(command.bigDecimalValueOfParameterNamedDefaultToNullIfZero("depositAmount"));
|
||||
this.dailyDepositAmount = command.bigDecimalValueOfParameterNamed("dailyDepositAmount");
|
||||
this.days = command.integerValueOfParameterNamed("days");
|
||||
this.ledgerNo = command.stringValueOfParameterNamedAllowingNull("ledgerNo");
|
||||
this.maturityAmount = BigDecimal.ZERO;
|
||||
this.interestRate = command.parameterExists("interestRate")
|
||||
? command.bigDecimalValueOfParameterNamed("interestRate")
|
||||
: DEFAULT_INTEREST_RATE;
|
||||
this.withdrawType = command.stringValueOfParameterNamedAllowingNull("withdrawType");
|
||||
this.od1Flag = false;
|
||||
this.od2Flag = false;
|
||||
this.lien = command.booleanPrimitiveValueOfParameterNamed("lien");
|
||||
this.payDate = command.localDateValueOfParameterNamed("payDate");
|
||||
this.paymentAmount = orZero(command.bigDecimalValueOfParameterNamedDefaultToNullIfZero("paymentAmount"));
|
||||
this.openingBalance = orZero(command.bigDecimalValueOfParameterNamedDefaultToNullIfZero("openingBalance"));
|
||||
this.currentBalance = this.openingBalance;
|
||||
this.isSmsActive = command.booleanPrimitiveValueOfParameterNamed("isSmsActive");
|
||||
this.isEmailActive = command.booleanPrimitiveValueOfParameterNamed("isEmailActive");
|
||||
this.interestCalc = BigDecimal.ZERO;
|
||||
this.interestDate = command.localDateValueOfParameterNamed("interestDate");
|
||||
this.spDescription = command.stringValueOfParameterNamedAllowingNull("spDescription");
|
||||
this.freezeCode = StringUtils.defaultIfBlank(command.stringValueOfParameterNamedAllowingNull("freezeCode"), "Normal");
|
||||
this.advCode = StringUtils.defaultIfBlank(command.stringValueOfParameterNamedAllowingNull("advCode"), "None");
|
||||
this.creditToBranch = command.stringValueOfParameterNamedAllowingNull("creditToBranch");
|
||||
this.creditToAccountType = command.stringValueOfParameterNamedAllowingNull("creditToAccountType");
|
||||
this.creditToAccount = command.stringValueOfParameterNamedAllowingNull("creditToAccount");
|
||||
this.nomineeApplicable = command.booleanPrimitiveValueOfParameterNamed("nomineeApplicable");
|
||||
this.nomineeSplitMode = StringUtils.defaultIfBlank(command.stringValueOfParameterNamedAllowingNull("nomineeSplitMode"),
|
||||
"Percentage");
|
||||
this.status = STATUS_ACTIVE;
|
||||
}
|
||||
|
||||
public static Party fromJson(final Client client, final Agent agent, final String partyCode, final JsonCommand command) {
|
||||
return new Party(client, agent, partyCode, command);
|
||||
}
|
||||
|
||||
private static BigDecimal orZero(final BigDecimal value) {
|
||||
return value == null ? BigDecimal.ZERO : value;
|
||||
}
|
||||
|
||||
public void addNominee(final PartyNominee nominee) {
|
||||
nominee.setParty(this);
|
||||
this.nominees.add(nominee);
|
||||
}
|
||||
|
||||
public void resetNominees() {
|
||||
this.nominees.clear();
|
||||
}
|
||||
|
||||
public void changeClient(final Client newClient) {
|
||||
this.client = newClient;
|
||||
}
|
||||
|
||||
public void changeAgent(final Agent newAgent) {
|
||||
this.agent = newAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Links this Party to an existing real Savings Account, resolved by account number in the write
|
||||
* service. There is no unlink - once a Party's DDS scheme is tied to a real account, it stays
|
||||
* tied.
|
||||
*/
|
||||
public void linkSavingsAccount(final Long savingsAccountId) {
|
||||
this.savingsAccountId = savingsAccountId;
|
||||
}
|
||||
|
||||
public BigDecimal credit(final BigDecimal amount) {
|
||||
this.currentBalance = this.currentBalance.add(amount);
|
||||
return this.currentBalance;
|
||||
}
|
||||
|
||||
public BigDecimal debit(final BigDecimal amount) {
|
||||
this.currentBalance = this.currentBalance.subtract(amount);
|
||||
return this.currentBalance;
|
||||
}
|
||||
|
||||
public boolean isClosed() {
|
||||
return STATUS_CLOSED.equals(this.status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes this Party's account as of the given date. The balance must already be zero - a Party
|
||||
* is settled to zero (a full Withdraw Deposite/payout) before it is closed, not closed with money
|
||||
* still owed to it.
|
||||
*/
|
||||
public void close(final LocalDate closeDate) {
|
||||
this.status = STATUS_CLOSED;
|
||||
this.closeDate = closeDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stamps the date interest (regular or OD) was last calculated up to, so the next batch run
|
||||
* accrues only the days since. Set on POST, not on calculate/preview.
|
||||
*/
|
||||
public void markInterestCalculatedThrough(final LocalDate date) {
|
||||
this.interestDate = date;
|
||||
}
|
||||
|
||||
public Long clientId() {
|
||||
return this.client.getId();
|
||||
}
|
||||
|
||||
public Long agentId() {
|
||||
return this.agent.getId();
|
||||
}
|
||||
|
||||
public Map<String, Object> update(final JsonCommand command) {
|
||||
|
||||
final Map<String, Object> actualChanges = new LinkedHashMap<>(40);
|
||||
|
||||
if (command.isChangeInLongParameterNamed("clientId", this.client.getId())) {
|
||||
actualChanges.put("clientId", command.longValueOfParameterNamed("clientId"));
|
||||
}
|
||||
if (command.isChangeInLongParameterNamed("agentId", this.agent.getId())) {
|
||||
actualChanges.put("agentId", command.longValueOfParameterNamed("agentId"));
|
||||
}
|
||||
|
||||
stringChange(command, actualChanges, "subType", this.subType, v -> this.subType = v);
|
||||
stringChange(command, actualChanges, "lastAccount", this.lastAccount, v -> this.lastAccount = v);
|
||||
|
||||
if (command.isChangeInBooleanParameterNamed("nominal", this.nominal)) {
|
||||
final boolean newValue = command.booleanPrimitiveValueOfParameterNamed("nominal");
|
||||
actualChanges.put("nominal", newValue);
|
||||
this.nominal = newValue;
|
||||
}
|
||||
|
||||
stringChange(command, actualChanges, "aadharNo", this.aadharNo, v -> this.aadharNo = v);
|
||||
stringChange(command, actualChanges, "partyName", this.partyName, v -> this.partyName = v);
|
||||
stringChange(command, actualChanges, "partyName1", this.partyName1, v -> this.partyName1 = v);
|
||||
stringChange(command, actualChanges, "address1", this.address1, v -> this.address1 = v);
|
||||
stringChange(command, actualChanges, "address2", this.address2, v -> this.address2 = v);
|
||||
stringChange(command, actualChanges, "address3", this.address3, v -> this.address3 = v);
|
||||
stringChange(command, actualChanges, "city", this.city, v -> this.city = v);
|
||||
stringChange(command, actualChanges, "pincode", this.pincode, v -> this.pincode = v);
|
||||
stringChange(command, actualChanges, "gender", this.gender, v -> this.gender = v);
|
||||
stringChange(command, actualChanges, "panCardNo", this.panCardNo, v -> this.panCardNo = v);
|
||||
stringChange(command, actualChanges, "telephone", this.telephone, v -> this.telephone = v);
|
||||
stringChange(command, actualChanges, "mobileNoSms", this.mobileNoSms, v -> this.mobileNoSms = v);
|
||||
stringChange(command, actualChanges, "operation", this.operation, v -> this.operation = v);
|
||||
|
||||
if (command.isChangeInDateParameterNamed("birthDate", this.birthDate)) {
|
||||
actualChanges.put("birthDate", command.stringValueOfParameterNamed("birthDate"));
|
||||
this.birthDate = command.localDateValueOfParameterNamed("birthDate");
|
||||
}
|
||||
|
||||
stringChange(command, actualChanges, "occupation", this.occupation, v -> this.occupation = v);
|
||||
stringChange(command, actualChanges, "risk", this.risk, v -> this.risk = v);
|
||||
stringChange(command, actualChanges, "ckycId", this.ckycId, v -> this.ckycId = v);
|
||||
stringChange(command, actualChanges, "adultMinor", this.adultMinor, v -> this.adultMinor = v);
|
||||
|
||||
if (command.isChangeInDateParameterNamed("minorDate", this.minorDate)) {
|
||||
actualChanges.put("minorDate", command.stringValueOfParameterNamed("minorDate"));
|
||||
this.minorDate = command.localDateValueOfParameterNamed("minorDate");
|
||||
}
|
||||
|
||||
if (command.isChangeInLongParameterNamed("guardianClientId", this.guardianClientId)) {
|
||||
final Long newValue = command.longValueOfParameterNamed("guardianClientId");
|
||||
actualChanges.put("guardianClientId", newValue);
|
||||
this.guardianClientId = newValue;
|
||||
}
|
||||
|
||||
stringChange(command, actualChanges, "minAccountOpt", this.minAccountOpt, v -> this.minAccountOpt = v);
|
||||
stringChange(command, actualChanges, "relation", this.relation, v -> this.relation = v);
|
||||
|
||||
if (command.isChangeInDateParameterNamed("openingDate", this.openingDate)) {
|
||||
actualChanges.put("openingDate", command.stringValueOfParameterNamed("openingDate"));
|
||||
this.openingDate = command.localDateValueOfParameterNamed("openingDate");
|
||||
}
|
||||
|
||||
if (command.isChangeInIntegerParameterNamed("month", this.month)) {
|
||||
final Integer newValue = command.integerValueOfParameterNamed("month");
|
||||
actualChanges.put("month", newValue);
|
||||
this.month = newValue;
|
||||
}
|
||||
|
||||
if (command.isChangeInDateParameterNamed("maturityDate", this.maturityDate)) {
|
||||
actualChanges.put("maturityDate", command.stringValueOfParameterNamed("maturityDate"));
|
||||
this.maturityDate = command.localDateValueOfParameterNamed("maturityDate");
|
||||
}
|
||||
|
||||
if (command.isChangeInDateParameterNamed("reopenDate", this.reopenDate)) {
|
||||
actualChanges.put("reopenDate", command.stringValueOfParameterNamed("reopenDate"));
|
||||
this.reopenDate = command.localDateValueOfParameterNamed("reopenDate");
|
||||
}
|
||||
|
||||
if (command.isChangeInBigDecimalParameterNamed("depositAmount", this.depositAmount)) {
|
||||
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed("depositAmount");
|
||||
actualChanges.put("depositAmount", newValue);
|
||||
this.depositAmount = newValue;
|
||||
}
|
||||
|
||||
if (command.isChangeInBigDecimalParameterNamed("dailyDepositAmount", this.dailyDepositAmount)) {
|
||||
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed("dailyDepositAmount");
|
||||
actualChanges.put("dailyDepositAmount", newValue);
|
||||
this.dailyDepositAmount = newValue;
|
||||
}
|
||||
|
||||
if (command.isChangeInIntegerParameterNamed("days", this.days)) {
|
||||
final Integer newValue = command.integerValueOfParameterNamed("days");
|
||||
actualChanges.put("days", newValue);
|
||||
this.days = newValue;
|
||||
}
|
||||
|
||||
if (command.isChangeInBigDecimalParameterNamed("interestRate", this.interestRate)) {
|
||||
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed("interestRate");
|
||||
actualChanges.put("interestRate", newValue);
|
||||
this.interestRate = newValue;
|
||||
}
|
||||
|
||||
stringChange(command, actualChanges, "ledgerNo", this.ledgerNo, v -> this.ledgerNo = v);
|
||||
stringChange(command, actualChanges, "withdrawType", this.withdrawType, v -> this.withdrawType = v);
|
||||
|
||||
if (command.isChangeInBooleanParameterNamed("lien", this.lien)) {
|
||||
final boolean newValue = command.booleanPrimitiveValueOfParameterNamed("lien");
|
||||
actualChanges.put("lien", newValue);
|
||||
this.lien = newValue;
|
||||
}
|
||||
|
||||
if (command.isChangeInDateParameterNamed("payDate", this.payDate)) {
|
||||
actualChanges.put("payDate", command.stringValueOfParameterNamed("payDate"));
|
||||
this.payDate = command.localDateValueOfParameterNamed("payDate");
|
||||
}
|
||||
|
||||
if (command.isChangeInBigDecimalParameterNamed("paymentAmount", this.paymentAmount)) {
|
||||
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed("paymentAmount");
|
||||
actualChanges.put("paymentAmount", newValue);
|
||||
this.paymentAmount = newValue;
|
||||
}
|
||||
|
||||
if (command.isChangeInBigDecimalParameterNamed("openingBalance", this.openingBalance)) {
|
||||
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed("openingBalance");
|
||||
actualChanges.put("openingBalance", newValue);
|
||||
this.openingBalance = newValue;
|
||||
}
|
||||
|
||||
if (command.isChangeInBooleanParameterNamed("isSmsActive", this.isSmsActive)) {
|
||||
final boolean newValue = command.booleanPrimitiveValueOfParameterNamed("isSmsActive");
|
||||
actualChanges.put("isSmsActive", newValue);
|
||||
this.isSmsActive = newValue;
|
||||
}
|
||||
|
||||
if (command.isChangeInBooleanParameterNamed("isEmailActive", this.isEmailActive)) {
|
||||
final boolean newValue = command.booleanPrimitiveValueOfParameterNamed("isEmailActive");
|
||||
actualChanges.put("isEmailActive", newValue);
|
||||
this.isEmailActive = newValue;
|
||||
}
|
||||
|
||||
if (command.isChangeInDateParameterNamed("interestDate", this.interestDate)) {
|
||||
actualChanges.put("interestDate", command.stringValueOfParameterNamed("interestDate"));
|
||||
this.interestDate = command.localDateValueOfParameterNamed("interestDate");
|
||||
}
|
||||
|
||||
stringChange(command, actualChanges, "spDescription", this.spDescription, v -> this.spDescription = v);
|
||||
stringChange(command, actualChanges, "freezeCode", this.freezeCode, v -> this.freezeCode = v);
|
||||
stringChange(command, actualChanges, "advCode", this.advCode, v -> this.advCode = v);
|
||||
stringChange(command, actualChanges, "creditToBranch", this.creditToBranch, v -> this.creditToBranch = v);
|
||||
stringChange(command, actualChanges, "creditToAccountType", this.creditToAccountType, v -> this.creditToAccountType = v);
|
||||
stringChange(command, actualChanges, "creditToAccount", this.creditToAccount, v -> this.creditToAccount = v);
|
||||
|
||||
if (command.isChangeInBooleanParameterNamed("nomineeApplicable", this.nomineeApplicable)) {
|
||||
final boolean newValue = command.booleanPrimitiveValueOfParameterNamed("nomineeApplicable");
|
||||
actualChanges.put("nomineeApplicable", newValue);
|
||||
this.nomineeApplicable = newValue;
|
||||
}
|
||||
|
||||
stringChange(command, actualChanges, "nomineeSplitMode", this.nomineeSplitMode, v -> this.nomineeSplitMode = v);
|
||||
|
||||
return actualChanges;
|
||||
}
|
||||
|
||||
private void stringChange(final JsonCommand command, final Map<String, Object> actualChanges, final String paramName,
|
||||
final String existingValue, final Consumer<String> setter) {
|
||||
if (command.isChangeInStringParameterNamed(paramName, existingValue)) {
|
||||
final String newValue = command.stringValueOfParameterNamed(paramName);
|
||||
actualChanges.put(paramName, newValue);
|
||||
setter.accept(newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* 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.dds.party.domain;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import java.time.LocalDate;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
|
||||
|
||||
/**
|
||||
* A single nominee recorded against a {@link Party}. Maker-checker on nominee edits is enforced at
|
||||
* the command layer (the whole Party update goes through the standard maker-checker command flow),
|
||||
* not on this child row individually.
|
||||
*/
|
||||
@Getter
|
||||
@Entity
|
||||
@Table(name = "m_dds_party_nominee")
|
||||
public class PartyNominee extends AbstractPersistableCustom<Long> {
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "party_id", nullable = false)
|
||||
private Party party;
|
||||
|
||||
@Column(name = "nomination_date", nullable = false)
|
||||
private LocalDate nominationDate;
|
||||
|
||||
@Column(name = "name", length = 100, nullable = false)
|
||||
private String name;
|
||||
|
||||
@Column(name = "mobile_no", length = 20)
|
||||
private String mobileNo;
|
||||
|
||||
@Column(name = "birth_date")
|
||||
private LocalDate birthDate;
|
||||
|
||||
@Column(name = "minor", nullable = false)
|
||||
private boolean minor;
|
||||
|
||||
@Column(name = "relation", length = 40, nullable = false)
|
||||
private String relation;
|
||||
|
||||
@Column(name = "gender", length = 20, nullable = false)
|
||||
private String gender;
|
||||
|
||||
@Column(name = "guardian_name", length = 100)
|
||||
private String guardianName;
|
||||
|
||||
protected PartyNominee() {
|
||||
//
|
||||
}
|
||||
|
||||
public PartyNominee(final LocalDate nominationDate, final String name, final String mobileNo, final LocalDate birthDate,
|
||||
final boolean minor, final String relation, final String gender, final String guardianName) {
|
||||
this.nominationDate = nominationDate;
|
||||
this.name = name;
|
||||
this.mobileNo = StringUtils.defaultIfEmpty(mobileNo, null);
|
||||
this.birthDate = birthDate;
|
||||
this.minor = minor;
|
||||
this.relation = relation;
|
||||
this.gender = gender;
|
||||
this.guardianName = StringUtils.defaultIfEmpty(guardianName, null);
|
||||
}
|
||||
|
||||
void setParty(final Party party) {
|
||||
this.party = party;
|
||||
}
|
||||
}
|
||||
+9
-5
@@ -16,13 +16,17 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.portfolio.savings.exception;
|
||||
package org.apache.fineract.portfolio.dds.party.exception;
|
||||
|
||||
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
|
||||
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException;
|
||||
|
||||
public class FacilityChargeMappingNotFoundException extends AbstractPlatformResourceNotFoundException {
|
||||
/**
|
||||
* Thrown when a Close Party command, or a Party Tran collection, targets a Party that is already
|
||||
* closed.
|
||||
*/
|
||||
public class PartyAlreadyClosedException extends AbstractPlatformDomainRuleException {
|
||||
|
||||
public FacilityChargeMappingNotFoundException(final Long id) {
|
||||
super("error.msg.facilitychargemapping.id.invalid", "Facility charge mapping with identifier " + id + " does not exist", id);
|
||||
public PartyAlreadyClosedException(final String partyCode) {
|
||||
super("error.msg.party.already.closed", "Party " + partyCode + " is already closed", partyCode);
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* 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.dds.party.exception;
|
||||
|
||||
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException;
|
||||
|
||||
/**
|
||||
* Thrown when a Close Party command is attempted while the Party's balance is still non-zero - the
|
||||
* remaining balance must be paid out (a Withdraw Deposite to zero) before the account can be closed.
|
||||
*/
|
||||
public class PartyHasBalanceException extends AbstractPlatformDomainRuleException {
|
||||
|
||||
public PartyHasBalanceException(final String partyCode) {
|
||||
super("error.msg.party.has.balance", "Party " + partyCode + " still has a non-zero balance and cannot be closed", partyCode);
|
||||
}
|
||||
}
|
||||
+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.dds.party.exception;
|
||||
|
||||
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
|
||||
/**
|
||||
* A {@link RuntimeException} thrown when a DDS party resource is not found.
|
||||
*/
|
||||
public class PartyNotFoundException extends AbstractPlatformResourceNotFoundException {
|
||||
|
||||
public PartyNotFoundException(final Long id) {
|
||||
super("error.msg.party.id.invalid", "Party with identifier " + id + " does not exist", id);
|
||||
}
|
||||
|
||||
public PartyNotFoundException(final Long id, final EmptyResultDataAccessException e) {
|
||||
super("error.msg.party.id.invalid", "Party with identifier " + id + " does not exist", id, e);
|
||||
}
|
||||
|
||||
public PartyNotFoundException(final String partyCode) {
|
||||
super("error.msg.party.code.invalid", "Party with code " + partyCode + " does not exist", partyCode);
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* 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.dds.party.exception;
|
||||
|
||||
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException;
|
||||
|
||||
/**
|
||||
* Thrown when the savingsAccountNo given for a Party belongs to a different client than the Party's
|
||||
* own clientId - a Party can only be linked to its own client's savings account.
|
||||
*/
|
||||
public class PartySavingsAccountClientMismatchException extends AbstractPlatformDomainRuleException {
|
||||
|
||||
public PartySavingsAccountClientMismatchException(final String savingsAccountNo) {
|
||||
super("error.msg.party.savings.account.client.mismatch",
|
||||
"Savings account " + savingsAccountNo + " does not belong to this party's client", savingsAccountNo);
|
||||
}
|
||||
}
|
||||
+10
-14
@@ -16,21 +16,17 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.useradministration.domain;
|
||||
package org.apache.fineract.portfolio.dds.party.exception;
|
||||
|
||||
public enum UserPendingRequestType {
|
||||
CREATE_USER,
|
||||
UPDATE_USER;
|
||||
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
|
||||
|
||||
public static UserPendingRequestType fromString(final String type) {
|
||||
if (type == null) {
|
||||
return null;
|
||||
}
|
||||
for (final UserPendingRequestType requestType : values()) {
|
||||
if (requestType.name().equalsIgnoreCase(type)) {
|
||||
return requestType;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown UserPendingRequestType: " + type);
|
||||
/**
|
||||
* Thrown when a Party's savingsAccountNo does not match any non-closed Savings Account.
|
||||
*/
|
||||
public class PartySavingsAccountNotFoundException extends AbstractPlatformResourceNotFoundException {
|
||||
|
||||
public PartySavingsAccountNotFoundException(final String savingsAccountNo) {
|
||||
super("error.msg.party.savings.account.not.found", "No open savings account found with account number " + savingsAccountNo,
|
||||
savingsAccountNo);
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* 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.dds.report.data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* A generic tabular result shape shared by every DDS report - one column list plus one row list, both
|
||||
* keyed the same way, so a single report viewer screen can render any of them without a bespoke
|
||||
* result type per report.
|
||||
*/
|
||||
@Getter
|
||||
@Builder
|
||||
public final class DdsReportData implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final String reportKey;
|
||||
private final boolean available;
|
||||
private final String message;
|
||||
private final List<String> columns;
|
||||
private final List<Map<String, Object>> rows;
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* 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.dds.transaction.data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public final class PartyTransactionData implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Long id;
|
||||
private final Long partyId;
|
||||
private final String partyCode;
|
||||
private final String partyName;
|
||||
private final Long agentId;
|
||||
private final String agentCode;
|
||||
private final LocalDate transactionDate;
|
||||
private final String transactionType;
|
||||
private final String direction;
|
||||
private final String transactionMode;
|
||||
private final String accountType;
|
||||
private final String accountNo;
|
||||
private final BigDecimal amount;
|
||||
private final String chequeNo;
|
||||
private final String tokenNo;
|
||||
private final String description;
|
||||
private final BigDecimal balanceAfterTransaction;
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* 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.dds.transaction.domain;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import lombok.Getter;
|
||||
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
|
||||
import org.apache.fineract.organisation.agent.domain.Agent;
|
||||
import org.apache.fineract.portfolio.dds.party.domain.Party;
|
||||
|
||||
/**
|
||||
* A single posted entry on the DDS ledger: a Party's day's collection ("Party Tran", direction
|
||||
* CREDIT), one leg of a "Withdraw Deposite" transfer between two parties (the creditor leg CREDIT,
|
||||
* the debtor leg DEBIT), or an Agent's settlement of collected cash to its branch ("Agent Tran",
|
||||
* direction DEBIT - no {@link Party} involved, so {@code party} is null for this type).
|
||||
* {@code balanceAfterTransaction} holds the Party's balance for Party-linked rows, or the Agent's
|
||||
* balance for an Agent Tran row. Immutable once posted - like any transaction, it is reversed with
|
||||
* an opposing entry, not edited, so there is deliberately no update API for this entity.
|
||||
*/
|
||||
@Getter
|
||||
@Entity
|
||||
@Table(name = "m_dds_party_transaction")
|
||||
public class PartyTransaction extends AbstractPersistableCustom<Long> {
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "party_id")
|
||||
private Party party;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "agent_id", nullable = false)
|
||||
private Agent agent;
|
||||
|
||||
@Column(name = "transaction_date", nullable = false)
|
||||
private LocalDate transactionDate;
|
||||
|
||||
@Column(name = "transaction_type", length = 30, nullable = false)
|
||||
private String transactionType;
|
||||
|
||||
@Column(name = "direction", length = 10, nullable = false)
|
||||
private String direction;
|
||||
|
||||
@Column(name = "transaction_mode", length = 20)
|
||||
private String transactionMode;
|
||||
|
||||
@Column(name = "account_type", length = 100)
|
||||
private String accountType;
|
||||
|
||||
@Column(name = "account_no", length = 50)
|
||||
private String accountNo;
|
||||
|
||||
@Column(name = "amount", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal amount;
|
||||
|
||||
@Column(name = "cheque_no", length = 40)
|
||||
private String chequeNo;
|
||||
|
||||
@Column(name = "token_no", length = 40)
|
||||
private String tokenNo;
|
||||
|
||||
@Column(name = "description", length = 500)
|
||||
private String description;
|
||||
|
||||
@Column(name = "balance_after_transaction", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal balanceAfterTransaction;
|
||||
|
||||
protected PartyTransaction() {
|
||||
//
|
||||
}
|
||||
|
||||
public PartyTransaction(final Party party, final Agent agent, final LocalDate transactionDate, final String transactionType,
|
||||
final String direction, final String transactionMode, final String accountType, final String accountNo,
|
||||
final BigDecimal amount, final String chequeNo, final String tokenNo, final String description,
|
||||
final BigDecimal balanceAfterTransaction) {
|
||||
this.party = party;
|
||||
this.agent = agent;
|
||||
this.transactionDate = transactionDate;
|
||||
this.transactionType = transactionType;
|
||||
this.direction = direction;
|
||||
this.transactionMode = transactionMode;
|
||||
this.accountType = accountType;
|
||||
this.accountNo = accountNo;
|
||||
this.amount = amount;
|
||||
this.chequeNo = chequeNo;
|
||||
this.tokenNo = tokenNo;
|
||||
this.description = description;
|
||||
this.balanceAfterTransaction = balanceAfterTransaction;
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* 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.dds.transaction.exception;
|
||||
|
||||
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException;
|
||||
|
||||
/**
|
||||
* Thrown when an Agent Tran settlement amount exceeds the Agent's current (collected but not yet
|
||||
* settled) balance.
|
||||
*/
|
||||
public class InsufficientAgentBalanceException extends AbstractPlatformDomainRuleException {
|
||||
|
||||
public InsufficientAgentBalanceException(final String agentCode) {
|
||||
super("error.msg.agent.insufficient.balance",
|
||||
"Agent " + agentCode + " does not have sufficient collected balance for this settlement", agentCode);
|
||||
}
|
||||
}
|
||||
+10
-15
@@ -16,22 +16,17 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.useradministration.domain;
|
||||
package org.apache.fineract.portfolio.dds.transaction.exception;
|
||||
|
||||
public enum UserPendingRequestStatus {
|
||||
PENDING,
|
||||
APPROVED,
|
||||
REJECTED;
|
||||
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException;
|
||||
|
||||
public static UserPendingRequestStatus fromString(final String status) {
|
||||
if (status == null) {
|
||||
return null;
|
||||
}
|
||||
for (final UserPendingRequestStatus requestStatus : values()) {
|
||||
if (requestStatus.name().equalsIgnoreCase(status)) {
|
||||
return requestStatus;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown UserPendingRequestStatus: " + status);
|
||||
/**
|
||||
* Thrown when a Withdraw Deposite transfer would take the debtor Party's balance below zero.
|
||||
*/
|
||||
public class InsufficientPartyBalanceException extends AbstractPlatformDomainRuleException {
|
||||
|
||||
public InsufficientPartyBalanceException(final String partyCode) {
|
||||
super("error.msg.party.insufficient.balance", "Party " + partyCode + " does not have sufficient balance for this transfer",
|
||||
partyCode);
|
||||
}
|
||||
}
|
||||
+8
-13
@@ -16,22 +16,17 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.portfolio.savings.service;
|
||||
package org.apache.fineract.portfolio.dds.transaction.exception;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.fineract.portfolio.savings.data.DormantAccountData;
|
||||
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
|
||||
/**
|
||||
* Reads the accounts the dormancy job has marked inactive, dormant or escheated.
|
||||
* A {@link RuntimeException} thrown when a DDS party transaction resource is not found.
|
||||
*/
|
||||
public interface DormantAccountReadPlatformService {
|
||||
public class PartyTransactionNotFoundException extends AbstractPlatformResourceNotFoundException {
|
||||
|
||||
/**
|
||||
* @param subStatus
|
||||
* 100 inactive, 200 dormant, 300 escheat; null for all three
|
||||
* @param officeName
|
||||
* restricts to one branch; null or blank for every branch
|
||||
* @return the matching accounts, longest idle first
|
||||
*/
|
||||
List<DormantAccountData> retrieveDormantAccounts(Integer subStatus, String officeName);
|
||||
public PartyTransactionNotFoundException(final Long id, final EmptyResultDataAccessException e) {
|
||||
super("error.msg.partytransaction.id.invalid", "Party transaction with identifier " + id + " does not exist", id, e);
|
||||
}
|
||||
}
|
||||
+1
-7
@@ -31,8 +31,7 @@ public enum DepositAccountOnClosureType {
|
||||
WITHDRAW_DEPOSIT(100, "depositAccountClosureType.withdrawDeposit"), //
|
||||
TRANSFER_TO_SAVINGS(200, "depositAccountClosureType.transferToSavings"), //
|
||||
REINVEST_PRINCIPAL_AND_INTEREST(300, "depositAccountClosureType.reinvestPrincipalAndInterest"), //
|
||||
REINVEST_PRINCIPAL_ONLY(400, "depositAccountClosureType.reinvestPrincipalOnly"), //
|
||||
PARTIAL_REINVEST(500, "depositAccountClosureType.partialReinvest"); //
|
||||
REINVEST_PRINCIPAL_ONLY(400, "depositAccountClosureType.reinvestPrincipalOnly"); //
|
||||
|
||||
private final Integer value;
|
||||
private final String code;
|
||||
@@ -52,7 +51,6 @@ public enum DepositAccountOnClosureType {
|
||||
case 200 -> TRANSFER_TO_SAVINGS;
|
||||
case 300 -> REINVEST_PRINCIPAL_AND_INTEREST;
|
||||
case 400 -> REINVEST_PRINCIPAL_ONLY;
|
||||
case 500 -> PARTIAL_REINVEST;
|
||||
default -> INVALID;
|
||||
};
|
||||
}
|
||||
@@ -87,10 +85,6 @@ public enum DepositAccountOnClosureType {
|
||||
return this.equals(INVALID);
|
||||
}
|
||||
|
||||
public boolean isPartialReinvest() {
|
||||
return this.equals(PARTIAL_REINVEST);
|
||||
}
|
||||
|
||||
// TODO: do we really need this?!?
|
||||
public static Object[] integerValues() {
|
||||
return Arrays.stream(values()).filter(value -> !INVALID.equals(value)).map(value -> value.value).toList().toArray();
|
||||
|
||||
-7
@@ -123,7 +123,6 @@ public final class DepositsApiConstants {
|
||||
public static final String isSeniorCitizenParamName = "isSeniorCitizen";
|
||||
public static final String seniorCitizenInterestRateParamName = "seniorCitizenInterestRate";
|
||||
public static final String tenureInMonthsParamName = "tenureInMonths";
|
||||
public static final String tenureInDaysParamName = "tenureInDays";
|
||||
public static final String interestCompoundingPeriodInMonthsParamName = "interestCompoundingPeriodInMonths";
|
||||
|
||||
// Preclosure parameters
|
||||
@@ -209,7 +208,6 @@ public final class DepositsApiConstants {
|
||||
public static final String onAccountClosureIdParamName = "onAccountClosureId";
|
||||
public static final String transferDescriptionParamName = "transferDescription";
|
||||
public static final String toSavingsAccountIdParamName = "toSavingsAccountId";
|
||||
public static final String reinvestAmountParamName = "reinvestAmount";
|
||||
public static final String savingsAccounts = "savingsAccounts";
|
||||
public static final String maturityInstructionIdParamName = "maturityInstructionId";
|
||||
public static final String transferToSavingsIdParamName = "transferToSavingsId";
|
||||
@@ -512,7 +510,6 @@ public final class DepositsApiConstants {
|
||||
fixedDepositInterestCalculationData.add(principalAmountParamName);
|
||||
fixedDepositInterestCalculationData.add(annualInterestRateParamName);
|
||||
fixedDepositInterestCalculationData.add(tenureInMonthsParamName);
|
||||
fixedDepositInterestCalculationData.add(tenureInDaysParamName);
|
||||
fixedDepositInterestCalculationData.add(interestPostingPeriodInMonthsParamName);
|
||||
fixedDepositInterestCalculationData.add(interestCompoundingPeriodInMonthsParamName);
|
||||
// Exact calendar-based calculation params
|
||||
@@ -591,10 +588,6 @@ public final class DepositsApiConstants {
|
||||
fixedDepositResponseData.add(SavingsApiConstants.jointHoldersParamName);
|
||||
fixedDepositResponseData.add(SavingsApiConstants.nominationFacilityParamName);
|
||||
fixedDepositResponseData.add(SavingsApiConstants.autoDebitFacilityParamName);
|
||||
// FD Special's engine-computed monthly interest schedule (see FixedDepositAccountsApiResource#retrieveOne)
|
||||
fixedDepositResponseData.add("projectedInterestSchedule");
|
||||
fixedDepositResponseData.add("totalProjectedInterest");
|
||||
fixedDepositResponseData.add("totalValueAtMaturity");
|
||||
return fixedDepositResponseData;
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -92,9 +92,6 @@ public class SavingsApiConstants {
|
||||
public static final String statusParamName = "status";
|
||||
public static final String subStatusParamName = "subStatus";
|
||||
public static final String reasonForBlockParamName = "reasonForBlock";
|
||||
/** "CASH" (default, a manual/staff-placed lien) or "CLEARING" (money still moving through the
|
||||
* clearing process — a not-yet-realized cheque/DD deposit, or a presented cheque not yet settled). */
|
||||
public static final String holdCategoryParamName = "holdCategory";
|
||||
public static final String clientIdParamName = "clientId";
|
||||
public static final String isRetailAccountParamName = "isRetailAccount";
|
||||
public static final String autogenerateTransactionIdParamName = "autogenerateTransactionId";
|
||||
@@ -229,7 +226,6 @@ public class SavingsApiConstants {
|
||||
public static final String endDateParamName = "endDate";
|
||||
public static final String introducerRequiredParamName = "introducerRequired";
|
||||
public static final String shareLinkingEnabledParamName = "shareLinkingEnabled";
|
||||
public static final String shareAccountIdParamName = "shareAccountId";
|
||||
public static final String nominationFacilityParamName = "nominationFacility";
|
||||
public static final String dormancyAlertParamName = "dormancyAlert";
|
||||
public static final String interestCalculateSelectorParamName = "interestCalculateSelector";
|
||||
@@ -258,6 +254,7 @@ public class SavingsApiConstants {
|
||||
public static final String neftFacilityParamName = "neftFacility";
|
||||
public static final String rtgsFacilityParamName = "rtgsFacility";
|
||||
public static final String interBankTotalCapFacilityParamName = "interBankTotalCapFacility";
|
||||
public static final String withdrawalFacilityParamName = "withdrawalFacility";
|
||||
public static final String depositFacilityKycParamName = "depositFacilityKyc";
|
||||
public static final String virtualDebitCardParamName = "virtualDebitCard";
|
||||
|
||||
@@ -278,6 +275,7 @@ public class SavingsApiConstants {
|
||||
// Additional custom fields
|
||||
public static final String balanceFrequencyParamName = "balanceFrequency";
|
||||
public static final String accountClosedZeroBalanceInDayClosingParamName = "accountClosedZeroBalanceInDayClosing";
|
||||
public static final String productCategoryParamName = "productCategory";
|
||||
|
||||
// Current Product — new UI fields
|
||||
public static final String balanceSwapOptionParamName = "balanceSwapOption";
|
||||
|
||||
-17
@@ -157,8 +157,6 @@ public final class SavingsAccountData implements Serializable {
|
||||
private LocalDate endDate;
|
||||
private Boolean introducerRequired;
|
||||
private Boolean shareLinkingEnabled;
|
||||
private Long shareAccountId;
|
||||
private String shareAccountNo;
|
||||
private Boolean nominationFacility;
|
||||
private Boolean dormancyAlert;
|
||||
private Boolean isDormancyTrackingActiveFromProduct;
|
||||
@@ -219,21 +217,6 @@ public final class SavingsAccountData implements Serializable {
|
||||
private BigDecimal interestPosting;
|
||||
private BigDecimal overdraftPosting;
|
||||
|
||||
/**
|
||||
* True when this deposit pays its interest out to a linked savings account every period (FD Special).
|
||||
* Such interest never stays in the account, so it must never compound -- every period earns on the
|
||||
* principal alone. Transient because it is only read by the batch interest-posting engine.
|
||||
*/
|
||||
private transient boolean transferInterestToLinkedAccount;
|
||||
|
||||
public void setTransferInterestToLinkedAccount(final boolean transferInterestToLinkedAccount) {
|
||||
this.transferInterestToLinkedAccount = transferInterestToLinkedAccount;
|
||||
}
|
||||
|
||||
public boolean isTransferInterestToLinkedAccount() {
|
||||
return this.transferInterestToLinkedAccount;
|
||||
}
|
||||
|
||||
public static SavingsAccountData importInstanceIndividual(Long clientId, Long productId, Long fieldOfficerId, LocalDate submittedOnDate,
|
||||
BigDecimal nominalAnnualInterestRate, EnumOptionData interestCompoundingPeriodTypeEnum,
|
||||
EnumOptionData interestPostingPeriodTypeEnum, EnumOptionData interestCalculationTypeEnum,
|
||||
|
||||
+1
@@ -144,6 +144,7 @@ public final class SavingsProductData implements Serializable {
|
||||
@Getter @Setter private Boolean enableLockinPeriod;
|
||||
@Getter @Setter private String balanceFrequency;
|
||||
@Getter @Setter private Boolean accountClosedZeroBalanceInDayClosing;
|
||||
@Getter @Setter private String productCategory;
|
||||
|
||||
// New current product fields
|
||||
@Getter @Setter private Boolean balanceSwapOption;
|
||||
|
||||
+1
-10
@@ -256,16 +256,7 @@ public final class PostingPeriod {
|
||||
this.daysInYear = daysInYear;
|
||||
this.compoundingPeriods = compoundingPeriods;
|
||||
|
||||
if (isUserPosting) {
|
||||
// "Post interest as on D" — a closure, or the same action from the account screen. The
|
||||
// period it covers ends at D-1, because interest is earned up to but not including the
|
||||
// day it is paid, and SavingsHelper closes the period there. The transaction itself
|
||||
// still belongs on D: that is the day the member was credited, the day the branch did
|
||||
// the work, and the day the cash is handed over. Dating it to the period end instead
|
||||
// stamps it a day before the account was even closed, and the ledger then disagrees with
|
||||
// the closure request, the voucher and the passbook — all of which carry D.
|
||||
this.dateOfPostingTransaction = periodInterval.endDate().plusDays(1);
|
||||
} else if (isSavingsInterestPostingAtCurrentPeriodEnd) {
|
||||
if (isSavingsInterestPostingAtCurrentPeriodEnd) {
|
||||
this.dateOfPostingTransaction = periodInterval.endDate();
|
||||
} else {
|
||||
this.dateOfPostingTransaction = periodInterval.endDate().plusDays(1);
|
||||
|
||||
-4
@@ -797,10 +797,6 @@ public final class SavingsEnumerations {
|
||||
optionData = new EnumOptionData(DepositAccountOnClosureType.REINVEST_PRINCIPAL_ONLY.getValue().longValue(),
|
||||
DepositAccountOnClosureType.REINVEST_PRINCIPAL_ONLY.getCode(), "Re-Invest Principal Only");
|
||||
break;
|
||||
case PARTIAL_REINVEST:
|
||||
optionData = new EnumOptionData(DepositAccountOnClosureType.PARTIAL_REINVEST.getValue().longValue(),
|
||||
DepositAccountOnClosureType.PARTIAL_REINVEST.getCode(), "Partial Re-Invest");
|
||||
break;
|
||||
}
|
||||
return optionData;
|
||||
}
|
||||
|
||||
+4
@@ -77,6 +77,9 @@ public class CurrentAccountFacilityConfig extends AbstractPersistableCustom<Long
|
||||
@Column(name = "inter_bank_total_cap_facility", nullable = false)
|
||||
private boolean interBankTotalCapFacility = false;
|
||||
|
||||
@Column(name = "withdrawal_facility", nullable = false)
|
||||
private boolean withdrawalFacility = false;
|
||||
|
||||
@Column(name = "deposit_facility_kyc", nullable = false)
|
||||
private boolean depositFacilityKyc = false;
|
||||
|
||||
@@ -117,6 +120,7 @@ public class CurrentAccountFacilityConfig extends AbstractPersistableCustom<Long
|
||||
if (config.has("neftFacility")) setNeftFacility(config.get("neftFacility").getAsBoolean());
|
||||
if (config.has("rtgsFacility")) setRtgsFacility(config.get("rtgsFacility").getAsBoolean());
|
||||
if (config.has("interBankTotalCapFacility")) setInterBankTotalCapFacility(config.get("interBankTotalCapFacility").getAsBoolean());
|
||||
if (config.has("withdrawalFacility")) setWithdrawalFacility(config.get("withdrawalFacility").getAsBoolean());
|
||||
if (config.has("depositFacilityKyc")) setDepositFacilityKyc(config.get("depositFacilityKyc").getAsBoolean());
|
||||
if (config.has("virtualDebitCard")) setVirtualDebitCard(config.get("virtualDebitCard").getAsBoolean());
|
||||
if (config.has("internetBanking")) setInternetBanking(config.get("internetBanking").getAsBoolean());
|
||||
|
||||
+3
@@ -136,6 +136,9 @@ public class CurrentAccountPendingEdit extends AbstractPersistableCustom<Long> {
|
||||
@Column(name = "inter_bank_total_cap_facility")
|
||||
private Boolean interBankTotalCapFacility;
|
||||
|
||||
@Column(name = "withdrawal_facility")
|
||||
private Boolean withdrawalFacility;
|
||||
|
||||
@Column(name = "deposit_facility_kyc")
|
||||
private Boolean depositFacilityKyc;
|
||||
|
||||
|
||||
+1
@@ -378,6 +378,7 @@ public class CurrentProductAssembler {
|
||||
config.setNeftFacility(facilityConfigJson.has("neftFacility") ? facilityConfigJson.get("neftFacility").getAsBoolean() : false);
|
||||
config.setRtgsFacility(facilityConfigJson.has("rtgsFacility") ? facilityConfigJson.get("rtgsFacility").getAsBoolean() : false);
|
||||
config.setInterBankTotalCapFacility(facilityConfigJson.has("interBankTotalCapFacility") ? facilityConfigJson.get("interBankTotalCapFacility").getAsBoolean() : false);
|
||||
config.setWithdrawalFacility(facilityConfigJson.has("withdrawalFacility") ? facilityConfigJson.get("withdrawalFacility").getAsBoolean() : false);
|
||||
config.setDepositFacilityKyc(facilityConfigJson.has("depositFacilityKyc") ? facilityConfigJson.get("depositFacilityKyc").getAsBoolean() : false);
|
||||
config.setVirtualDebitCard(facilityConfigJson.has("virtualDebitCard") ? facilityConfigJson.get("virtualDebitCard").getAsBoolean() : false);
|
||||
return config;
|
||||
|
||||
+6
@@ -75,6 +75,9 @@ public class CurrentProductFacilityConfig extends AbstractPersistableCustom<Long
|
||||
@Column(name = "inter_bank_total_cap_facility")
|
||||
private Boolean interBankTotalCapFacility = false;
|
||||
|
||||
@Column(name = "withdrawal_facility")
|
||||
private Boolean withdrawalFacility = false;
|
||||
|
||||
@Column(name = "deposit_facility_kyc")
|
||||
private Boolean depositFacilityKyc = false;
|
||||
|
||||
@@ -122,6 +125,8 @@ public class CurrentProductFacilityConfig extends AbstractPersistableCustom<Long
|
||||
public void setRtgsFacility(Boolean v) { this.rtgsFacility = v != null ? v : false; }
|
||||
public Boolean getInterBankTotalCapFacility() { return interBankTotalCapFacility; }
|
||||
public void setInterBankTotalCapFacility(Boolean v) { this.interBankTotalCapFacility = v != null ? v : false; }
|
||||
public Boolean getWithdrawalFacility() { return withdrawalFacility; }
|
||||
public void setWithdrawalFacility(Boolean v) { this.withdrawalFacility = v != null ? v : false; }
|
||||
public Boolean getDepositFacilityKyc() { return depositFacilityKyc; }
|
||||
public void setDepositFacilityKyc(Boolean v) { this.depositFacilityKyc = v != null ? v : false; }
|
||||
public Boolean getVirtualDebitCard() { return virtualDebitCard; }
|
||||
@@ -142,6 +147,7 @@ public class CurrentProductFacilityConfig extends AbstractPersistableCustom<Long
|
||||
this.neftFacility = other.getNeftFacility();
|
||||
this.rtgsFacility = other.getRtgsFacility();
|
||||
this.interBankTotalCapFacility = other.getInterBankTotalCapFacility();
|
||||
this.withdrawalFacility = other.getWithdrawalFacility();
|
||||
this.depositFacilityKyc = other.getDepositFacilityKyc();
|
||||
this.virtualDebitCard = other.getVirtualDebitCard();
|
||||
}
|
||||
|
||||
+1
@@ -117,6 +117,7 @@ public class CurrentProductReadPlatformServiceImpl implements CurrentProductRead
|
||||
facilityConfigMap.put("neftFacility", facilityConfig.getNeftFacility());
|
||||
facilityConfigMap.put("rtgsFacility", facilityConfig.getRtgsFacility());
|
||||
facilityConfigMap.put("interBankTotalCapFacility", facilityConfig.getInterBankTotalCapFacility());
|
||||
facilityConfigMap.put("withdrawalFacility", facilityConfig.getWithdrawalFacility());
|
||||
facilityConfigMap.put("depositFacilityKyc", facilityConfig.getDepositFacilityKyc());
|
||||
facilityConfigMap.put("virtualDebitCard", facilityConfig.getVirtualDebitCard());
|
||||
product.setAccountFacilityConfig(facilityConfigMap);
|
||||
|
||||
-243
@@ -1,243 +0,0 @@
|
||||
/**
|
||||
* 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.balancesheet.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.QueryParam;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* An "as on date" balance sheet built directly off the live chart of accounts and journal entries,
|
||||
* rather than a stock Fineract trial balance report — this reproduces the specific sub-group-wise
|
||||
* layout this bank's own paper balance sheet uses: every top-level Header account (Capital, Deposit
|
||||
* Account, Other Liabilities, ...) is one named block, with its Detail (and any nested Header)
|
||||
* children indented underneath it and a subtotal on the block itself. A Detail account with no
|
||||
* Header at all (see GLAccountTransactionGuard's sibling concern - some accounts are seeded standalone)
|
||||
* still needs to appear somewhere, so it is listed as its own root-level line rather than silently
|
||||
* dropped.
|
||||
*
|
||||
* A Header account never itself carries a journal entry (see the header/detail discussion this
|
||||
* feature grew out of), so its balance is always the recursive sum of its children - never read off
|
||||
* acc_gl_journal_entry directly.
|
||||
*/
|
||||
@Path("/v1/accounting/balancesheet")
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public class BalanceSheetApiResource {
|
||||
|
||||
private static final String RESOURCE_NAME_FOR_PERMISSION = "GLACCOUNT";
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final Gson gson = new Gson();
|
||||
|
||||
// classification_enum values (see acc_gl_account / GLAccountType).
|
||||
private static final int ASSET = 1;
|
||||
private static final int LIABILITY = 2;
|
||||
private static final int EQUITY = 3;
|
||||
private static final int INCOME = 4;
|
||||
private static final int EXPENSE = 5;
|
||||
// account_usage values (see GLAccountUsage).
|
||||
private static final int DETAIL = 1;
|
||||
private static final int HEADER = 2;
|
||||
|
||||
private static final class Node {
|
||||
|
||||
Long id;
|
||||
String name;
|
||||
String glCode;
|
||||
int usage;
|
||||
int classification;
|
||||
Long parentId;
|
||||
BigDecimal ownBalance = BigDecimal.ZERO;
|
||||
final List<Node> children = new ArrayList<>();
|
||||
|
||||
BigDecimal balance() {
|
||||
if (usage == DETAIL) {
|
||||
return ownBalance;
|
||||
}
|
||||
BigDecimal sum = BigDecimal.ZERO;
|
||||
for (final Node child : children) {
|
||||
sum = sum.add(child.balance());
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
Map<String, Object> toJson() {
|
||||
final Map<String, Object> json = new LinkedHashMap<>();
|
||||
json.put("id", id);
|
||||
json.put("name", name);
|
||||
json.put("glCode", glCode);
|
||||
json.put("usage", usage == HEADER ? "HEADER" : "DETAIL");
|
||||
json.put("balance", balance());
|
||||
final List<Map<String, Object>> childJson = new ArrayList<>();
|
||||
for (final Node child : children) {
|
||||
childJson.add(child.toJson());
|
||||
}
|
||||
json.put("children", childJson);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveBalanceSheet(@QueryParam("asOnDate") final String asOnDateParam,
|
||||
@QueryParam("officeId") final Long officeId) {
|
||||
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSION);
|
||||
|
||||
final LocalDate asOnDate = (asOnDateParam == null || asOnDateParam.isBlank()) ? DateUtils.getBusinessLocalDate()
|
||||
: LocalDate.parse(asOnDateParam);
|
||||
|
||||
final Map<Long, Node> nodesById = new LinkedHashMap<>();
|
||||
for (final Map<String, Object> row : this.jdbcTemplate.queryForList(
|
||||
"SELECT id, name, gl_code, parent_id, account_usage, classification_enum FROM acc_gl_account "
|
||||
+ "WHERE disabled = false ORDER BY gl_code")) {
|
||||
final Node node = new Node();
|
||||
node.id = ((Number) row.get("id")).longValue();
|
||||
node.name = (String) row.get("name");
|
||||
node.glCode = (String) row.get("gl_code");
|
||||
node.parentId = row.get("parent_id") == null ? null : ((Number) row.get("parent_id")).longValue();
|
||||
node.usage = ((Number) row.get("account_usage")).intValue();
|
||||
node.classification = ((Number) row.get("classification_enum")).intValue();
|
||||
nodesById.put(node.id, node);
|
||||
}
|
||||
|
||||
// entry_date (not transaction_date) and "reversed = false" are this codebase's settled
|
||||
// convention for reading balances off the ledger - ProfitAndLossApiResource, the dividend
|
||||
// reports and IncomeProfitTransferService all cut the same way, so this report agrees with
|
||||
// them rather than quietly producing a second set of numbers.
|
||||
//
|
||||
// The reversal_id exclusion covers a case that plain "reversed = false" gets wrong. This
|
||||
// codebase reverses in two different ways: the clerk/sponsor-DD undo paths just flip the
|
||||
// flag on the original leg (no counter entry - excluding it is exactly right), while
|
||||
// Fineract's own revertJournalEntry additionally posts an opposite-sign counter entry and
|
||||
// links it back through reversal_id. For that second kind, dropping only the original would
|
||||
// leave its counter entry standing alone and swing the balance by the full amount in the
|
||||
// wrong direction, so the counter entry has to go too.
|
||||
final Map<Long, BigDecimal[]> balances = new LinkedHashMap<>();
|
||||
final String balanceSql = "SELECT account_id, "
|
||||
+ "COALESCE(SUM(CASE WHEN type_enum = 2 THEN amount ELSE 0 END), 0) AS total_debit, "
|
||||
+ "COALESCE(SUM(CASE WHEN type_enum = 1 THEN amount ELSE 0 END), 0) AS total_credit "
|
||||
+ "FROM acc_gl_journal_entry WHERE entry_date <= ? "
|
||||
+ "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)"
|
||||
+ (officeId != null ? " AND office_id = ?" : "") + " GROUP BY account_id";
|
||||
final List<Map<String, Object>> balanceRows = officeId != null
|
||||
? this.jdbcTemplate.queryForList(balanceSql, java.sql.Date.valueOf(asOnDate), officeId)
|
||||
: this.jdbcTemplate.queryForList(balanceSql, java.sql.Date.valueOf(asOnDate));
|
||||
for (final Map<String, Object> row : balanceRows) {
|
||||
balances.put(((Number) row.get("account_id")).longValue(),
|
||||
new BigDecimal[] { (BigDecimal) row.get("total_debit"), (BigDecimal) row.get("total_credit") });
|
||||
}
|
||||
|
||||
for (final Node node : nodesById.values()) {
|
||||
if (node.usage != DETAIL) {
|
||||
continue;
|
||||
}
|
||||
final BigDecimal[] debitCredit = balances.get(node.id);
|
||||
if (debitCredit == null) {
|
||||
continue;
|
||||
}
|
||||
final boolean debitNatured = node.classification == ASSET || node.classification == EXPENSE;
|
||||
node.ownBalance = debitNatured ? debitCredit[0].subtract(debitCredit[1]) : debitCredit[1].subtract(debitCredit[0]);
|
||||
}
|
||||
|
||||
final List<Node> roots = new ArrayList<>();
|
||||
for (final Node node : nodesById.values()) {
|
||||
if (node.parentId == null) {
|
||||
roots.add(node);
|
||||
} else {
|
||||
final Node parent = nodesById.get(node.parentId);
|
||||
if (parent != null) {
|
||||
parent.children.add(node);
|
||||
} else {
|
||||
// Parent was disabled (filtered out above) - surface this node at the top level
|
||||
// rather than silently losing its balance from the report.
|
||||
roots.add(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final Map<String, Object> debitSide = buildSide("ASSETS", roots, ASSET, EXPENSE);
|
||||
final Map<String, Object> creditSide = buildSide("LIABILITIES", roots, LIABILITY, EQUITY, INCOME);
|
||||
|
||||
final Map<String, Object> response = new LinkedHashMap<>();
|
||||
response.put("asOnDate", asOnDate.toString());
|
||||
response.put("officeId", officeId);
|
||||
response.put("debitSide", debitSide);
|
||||
response.put("creditSide", creditSide);
|
||||
return this.gson.toJson(response);
|
||||
}
|
||||
|
||||
private Map<String, Object> buildSide(final String label, final List<Node> roots, final int... classifications) {
|
||||
final List<Map<String, Object>> groups = new ArrayList<>();
|
||||
BigDecimal sideTotal = BigDecimal.ZERO;
|
||||
for (final int classification : classifications) {
|
||||
final List<Map<String, Object>> nodeJsons = new ArrayList<>();
|
||||
BigDecimal groupTotal = BigDecimal.ZERO;
|
||||
for (final Node root : roots) {
|
||||
if (root.classification != classification) {
|
||||
continue;
|
||||
}
|
||||
nodeJsons.add(root.toJson());
|
||||
groupTotal = groupTotal.add(root.balance());
|
||||
}
|
||||
if (!nodeJsons.isEmpty()) {
|
||||
final Map<String, Object> group = new LinkedHashMap<>();
|
||||
group.put("classification", classificationLabel(classification));
|
||||
group.put("total", groupTotal);
|
||||
group.put("nodes", nodeJsons);
|
||||
groups.add(group);
|
||||
sideTotal = sideTotal.add(groupTotal);
|
||||
}
|
||||
}
|
||||
final Map<String, Object> side = new LinkedHashMap<>();
|
||||
side.put("label", label);
|
||||
side.put("total", sideTotal);
|
||||
side.put("groups", groups);
|
||||
return side;
|
||||
}
|
||||
|
||||
private String classificationLabel(final int classification) {
|
||||
return switch (classification) {
|
||||
case ASSET -> "ASSET";
|
||||
case LIABILITY -> "LIABILITY";
|
||||
case EQUITY -> "EQUITY";
|
||||
case INCOME -> "INCOME";
|
||||
case EXPENSE -> "EXPENSE";
|
||||
default -> "OTHER";
|
||||
};
|
||||
}
|
||||
}
|
||||
-112
@@ -1,112 +0,0 @@
|
||||
/**
|
||||
* 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.common;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.accounting.common.AccountingConstants.FinancialActivity;
|
||||
import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* Resolves the GL accounts the dividend lifecycle posts to, from the Financial Activity Mappings an administrator
|
||||
* configures.
|
||||
*
|
||||
* <p>
|
||||
* These accounts used to be found by hardcoded GL code - {@code BANKPROFITND01} and {@code BANKPROFIT01} - spread
|
||||
* across five classes. A society whose chart of accounts did not happen to use those exact codes got no dividend
|
||||
* journal entries at all, and nothing said so: every call site checked for null and returned quietly. Reading them from
|
||||
* the mapping table instead lets each society name its own accounts, and keeps the whole lifecycle answerable from one
|
||||
* screen.
|
||||
*
|
||||
* <p>
|
||||
* Resolution is mapping-only, with no fallback to the old codes: a society that has not mapped an account has not made
|
||||
* the decision yet, and quietly posting to an account it never chose is worse than refusing. Every method here throws
|
||||
* rather than returning null, so a missing mapping surfaces at the point of posting with the name of the activity to
|
||||
* configure, instead of leaving a declaration that appears to have worked but moved nothing.
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DividendGlAccountResolver {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
/** The year's closed-out profit a dividend is declared against. */
|
||||
public Long distributableProfitAccount() {
|
||||
return requireMapped(FinancialActivity.DISTRIBUTABLE_PROFIT);
|
||||
}
|
||||
|
||||
/** Where profit settles once it is no longer distributable: the undistributed remainder, rounding, forfeitures. */
|
||||
public Long retainedProfitAccount() {
|
||||
return requireMapped(FinancialActivity.RETAINED_PROFIT);
|
||||
}
|
||||
|
||||
/** Equity the declared profit is set aside in, between declaration and board approval. */
|
||||
public Long reserveForDividendAccount() {
|
||||
return requireMapped(FinancialActivity.RESERVE_FOR_DIVIDEND);
|
||||
}
|
||||
|
||||
/** The liability to members, created on approval and discharged as each member claims. */
|
||||
public Long payableDividendsAccount() {
|
||||
return requireMapped(FinancialActivity.PAYABLE_DIVIDENDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Where the paise a dividend cannot divide evenly are swept.
|
||||
*
|
||||
* Falls back to retained profit when unmapped, which is exactly where the residue went before this account existed
|
||||
* - so a society that does not care to separate it keeps the behaviour it already had, and one that maps it gets
|
||||
* the arithmetic artefact out of a figure it reads as a business result. This is a presentation choice rather than
|
||||
* a decision the society has failed to make, which is why it resolves rather than throwing.
|
||||
*/
|
||||
public Long dividendRoundOffAccount() {
|
||||
final Long roundOff = mappedAccount(FinancialActivity.DIVIDEND_ROUND_OFF);
|
||||
return roundOff != null ? roundOff : retainedProfitAccount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Contra the claim is routed through, so claimed and unclaimed read as two balances rather than one net figure.
|
||||
*
|
||||
* Optional by design - a society that has not mapped it still gets a correct payout, posted straight from Dividend
|
||||
* Payable, just without that separate measure. This is the one account here that may legitimately be absent, so it
|
||||
* returns null instead of throwing.
|
||||
*/
|
||||
public Long dividendPaidAccountOrNull() {
|
||||
return mappedAccount(FinancialActivity.DIVIDEND_PAID);
|
||||
}
|
||||
|
||||
/** The GL mapped to an activity, or null when the society has not configured it. */
|
||||
public Long mappedAccount(final FinancialActivity activity) {
|
||||
return this.jdbcTemplate
|
||||
.queryForList("SELECT gl_account_id FROM acc_gl_financial_activity_account WHERE financial_activity_type = ?", Long.class,
|
||||
activity.getValue())
|
||||
.stream().findFirst().orElse(null);
|
||||
}
|
||||
|
||||
private Long requireMapped(final FinancialActivity activity) {
|
||||
final Long glAccountId = mappedAccount(activity);
|
||||
if (glAccountId == null) {
|
||||
throw new GeneralPlatformDomainRuleException("error.msg.financial.activity.mapping." + activity.getCode() + ".not.configured",
|
||||
"No GL account is mapped to the '" + activity + "' financial activity. Map one under Accounting > Financial Activity "
|
||||
+ "Mappings before running the dividend cycle.",
|
||||
activity.getValue());
|
||||
}
|
||||
return glAccountId;
|
||||
}
|
||||
}
|
||||
-185
@@ -1,185 +0,0 @@
|
||||
/**
|
||||
* 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.dividendpaidreport.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Every declared dividend, financial year by financial year: how much was declared, how much members have collected,
|
||||
* how much is still unclaimed, and how much has come back to profit.
|
||||
*
|
||||
* The GL accounts are shared across years, so their balances only ever give running totals — "how much of FY 2026-27 is
|
||||
* still unclaimed" cannot be read off Dividend Payable. This walks the declarations themselves instead: locks carry the
|
||||
* per-member entitlement and their status says what became of it, which is the authoritative record. The GL is where the
|
||||
* money moved; the locks are what it moved for.
|
||||
*
|
||||
* The columns mirror the money's actual path, which begins and ends in the same place:
|
||||
*
|
||||
* <pre>
|
||||
* declare Dr Bank Profit Cr Dividend Payable
|
||||
* member claims Dr Dividend Payable Cr Dividend Paid → Cr Sponsor DD Payable
|
||||
* 3 yrs unclaimed Dr Dividend Payable Cr Bank Profit
|
||||
* </pre>
|
||||
*
|
||||
* So for a closed year, claimed + forfeited + rounding residue should account for the whole declaration; anything left
|
||||
* is what is still sitting unclaimed and still within its three-year window.
|
||||
*/
|
||||
@Path("/v1/accounting/dividend-yearwise-report")
|
||||
@Component
|
||||
@Tag(name = "Dividend Year-wise Report", description = "Declared, claimed, unclaimed and forfeited dividend per financial year.")
|
||||
@RequiredArgsConstructor
|
||||
public class DividendYearwiseReportApiResource {
|
||||
|
||||
private static final String RESOURCE_NAME_FOR_PERMISSIONS = "DIVIDEND_SHAREPRODUCT";
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final PlatformSecurityContext context;
|
||||
private final Gson gson = new GsonBuilder().serializeNulls().create();
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String report() {
|
||||
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
|
||||
|
||||
// A declaration is labelled by the financial year its period CLOSES in, which is how a member
|
||||
// and an auditor both refer to it: a period ending 31-Mar-2027 is FY 2026-27. Locks are joined
|
||||
// through the per-member detail rather than counted off the declaration, because a lock is only
|
||||
// created for a member who actually had something to collect.
|
||||
// Declared amounts and lock outcomes are aggregated separately before being joined by year.
|
||||
// Summing the declaration amount across a join to its locks would multiply it by the number
|
||||
// of members it was split between.
|
||||
final List<Map<String, Object>> rows = jdbcTemplate.queryForList("""
|
||||
WITH fy AS (
|
||||
SELECT d.id,
|
||||
CASE WHEN EXTRACT(MONTH FROM d.dividend_period_end_date) >= 4
|
||||
THEN EXTRACT(YEAR FROM d.dividend_period_end_date)
|
||||
ELSE EXTRACT(YEAR FROM d.dividend_period_end_date) - 1 END AS fy_start,
|
||||
d.amount
|
||||
FROM m_share_product_dividend_pay_out d
|
||||
),
|
||||
declared AS (
|
||||
SELECT fy_start, COUNT(*) AS declaration_count, SUM(amount) AS declared_amount
|
||||
FROM fy GROUP BY fy_start
|
||||
),
|
||||
outcomes AS (
|
||||
SELECT fy.fy_start,
|
||||
COALESCE(SUM(CASE WHEN l.status = 'CLAIMED' THEN l.amount ELSE 0 END), 0) AS claimed_amount,
|
||||
COUNT(l.id) FILTER (WHERE l.status = 'CLAIMED') AS claimed_count,
|
||||
COALESCE(SUM(CASE WHEN l.status = 'UNCLAIMED' THEN l.amount ELSE 0 END), 0) AS unclaimed_amount,
|
||||
COUNT(l.id) FILTER (WHERE l.status = 'UNCLAIMED') AS unclaimed_count,
|
||||
COALESCE(SUM(CASE WHEN l.status = 'FORFEITED' THEN l.amount ELSE 0 END), 0) AS forfeited_amount,
|
||||
COUNT(l.id) FILTER (WHERE l.status = 'FORFEITED') AS forfeited_count,
|
||||
MIN(l.release_due_date) FILTER (WHERE l.status = 'UNCLAIMED') AS earliest_release_due
|
||||
FROM fy
|
||||
LEFT JOIN m_share_account_dividend_details sad ON sad.dividend_pay_out_id = fy.id
|
||||
LEFT JOIN m_share_dividend_lock l ON l.dividend_detail_id = sad.id
|
||||
GROUP BY fy.fy_start
|
||||
)
|
||||
SELECT d.fy_start, d.declaration_count, d.declared_amount,
|
||||
COALESCE(o.claimed_amount, 0) AS claimed_amount, COALESCE(o.claimed_count, 0) AS claimed_count,
|
||||
COALESCE(o.unclaimed_amount, 0) AS unclaimed_amount, COALESCE(o.unclaimed_count, 0) AS unclaimed_count,
|
||||
COALESCE(o.forfeited_amount, 0) AS forfeited_amount, COALESCE(o.forfeited_count, 0) AS forfeited_count,
|
||||
o.earliest_release_due
|
||||
FROM declared d
|
||||
LEFT JOIN outcomes o ON o.fy_start = d.fy_start
|
||||
ORDER BY d.fy_start DESC
|
||||
""");
|
||||
|
||||
// Rounding residue is tracked per declaration rather than per lock — it never belonged to a
|
||||
// member, so no lock was ever created for it. Pulled separately and matched by year.
|
||||
final Map<String, BigDecimal> residueByYear = new LinkedHashMap<>();
|
||||
for (final Map<String, Object> row : jdbcTemplate.queryForList("""
|
||||
SELECT CASE WHEN EXTRACT(MONTH FROM period_end_date) >= 4
|
||||
THEN EXTRACT(YEAR FROM period_end_date)
|
||||
ELSE EXTRACT(YEAR FROM period_end_date) - 1 END AS fy_start,
|
||||
COALESCE(SUM(residue_amount), 0) AS residue
|
||||
FROM m_share_dividend_rounding_residue
|
||||
GROUP BY fy_start
|
||||
""")) {
|
||||
residueByYear.put(financialYearLabel(((Number) row.get("fy_start")).intValue()), (BigDecimal) row.get("residue"));
|
||||
}
|
||||
|
||||
final List<Map<String, Object>> years = new ArrayList<>();
|
||||
BigDecimal totalDeclared = BigDecimal.ZERO;
|
||||
BigDecimal totalClaimed = BigDecimal.ZERO;
|
||||
BigDecimal totalUnclaimed = BigDecimal.ZERO;
|
||||
BigDecimal totalForfeited = BigDecimal.ZERO;
|
||||
|
||||
for (final Map<String, Object> row : rows) {
|
||||
final String financialYear = financialYearLabel(((Number) row.get("fy_start")).intValue());
|
||||
final BigDecimal declared = (BigDecimal) row.get("declared_amount");
|
||||
final BigDecimal claimed = (BigDecimal) row.get("claimed_amount");
|
||||
final BigDecimal unclaimed = (BigDecimal) row.get("unclaimed_amount");
|
||||
final BigDecimal forfeited = (BigDecimal) row.get("forfeited_amount");
|
||||
final BigDecimal residue = residueByYear.getOrDefault(financialYear, BigDecimal.ZERO);
|
||||
|
||||
final Map<String, Object> entry = new LinkedHashMap<>();
|
||||
entry.put("financialYear", financialYear);
|
||||
entry.put("declarationCount", row.get("declaration_count"));
|
||||
entry.put("declaredAmount", declared);
|
||||
entry.put("claimedAmount", claimed);
|
||||
entry.put("claimedCount", row.get("claimed_count"));
|
||||
entry.put("unclaimedAmount", unclaimed);
|
||||
entry.put("unclaimedCount", row.get("unclaimed_count"));
|
||||
entry.put("forfeitedAmount", forfeited);
|
||||
entry.put("forfeitedCount", row.get("forfeited_count"));
|
||||
entry.put("roundingResidueAmount", residue);
|
||||
// What has already gone back to profit for this year: forfeited entitlements plus the
|
||||
// rounding residue swept at declaration time.
|
||||
entry.put("returnedToProfitAmount", forfeited.add(residue));
|
||||
// When this year's oldest unclaimed lock forfeits — the date the remaining unclaimed
|
||||
// amount starts returning to profit.
|
||||
entry.put("earliestReleaseDueDate",
|
||||
row.get("earliest_release_due") == null ? null : String.valueOf(row.get("earliest_release_due")));
|
||||
years.add(entry);
|
||||
|
||||
totalDeclared = totalDeclared.add(declared);
|
||||
totalClaimed = totalClaimed.add(claimed);
|
||||
totalUnclaimed = totalUnclaimed.add(unclaimed);
|
||||
totalForfeited = totalForfeited.add(forfeited);
|
||||
}
|
||||
|
||||
final Map<String, Object> response = new LinkedHashMap<>();
|
||||
response.put("years", years);
|
||||
response.put("totalDeclared", totalDeclared);
|
||||
response.put("totalClaimed", totalClaimed);
|
||||
response.put("totalUnclaimed", totalUnclaimed);
|
||||
response.put("totalForfeited", totalForfeited);
|
||||
return gson.toJson(response);
|
||||
}
|
||||
|
||||
private String financialYearLabel(final int startYear) {
|
||||
return startYear + "-" + String.format("%02d", (startYear + 1) % 100);
|
||||
}
|
||||
}
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
/**
|
||||
* 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.glaccount.validation;
|
||||
|
||||
import org.apache.fineract.accounting.glaccount.domain.GLAccountUsage;
|
||||
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
/**
|
||||
* A Header GL account (account_usage = HEADER) is a pure grouping node in the chart-of-accounts tree - it
|
||||
* exists to organize Detail accounts underneath it, never to receive a transaction itself. The standard
|
||||
* Fineract journal-entry command path (JournalEntryWritePlatformServiceJpaRepositoryImpl) never checked
|
||||
* this - only "disabled" and "manual entries allowed" - and several features in this codebase post journal
|
||||
* entries via direct JDBC INSERT into acc_gl_journal_entry, bypassing that command path entirely. This is
|
||||
* the one shared check every such call site uses so a Header account can never end up with its own
|
||||
* transaction (which would silently break every report that assumes a Header's balance is just the sum of
|
||||
* its Detail children).
|
||||
*/
|
||||
public final class GLAccountTransactionGuard {
|
||||
|
||||
private GLAccountTransactionGuard() {}
|
||||
|
||||
public static void assertPostable(final JdbcTemplate jdbcTemplate, final Long glAccountId) {
|
||||
if (glAccountId == null) {
|
||||
return;
|
||||
}
|
||||
final Integer usage;
|
||||
try {
|
||||
usage = jdbcTemplate.queryForObject("SELECT account_usage FROM acc_gl_account WHERE id = ?", Integer.class, glAccountId);
|
||||
} catch (final EmptyResultDataAccessException e) {
|
||||
throw new PlatformDataIntegrityException("error.msg.glaccount.not.found",
|
||||
"GL account with id " + glAccountId + " does not exist.", "glAccountId", glAccountId);
|
||||
}
|
||||
if (GLAccountUsage.HEADER.getValue().equals(usage)) {
|
||||
throw new PlatformDataIntegrityException("error.msg.glaccount.header.account.not.postable",
|
||||
"GL account " + glAccountId + " is a Header account (a chart-of-accounts grouping node) and cannot receive a "
|
||||
+ "transaction directly. Select a Detail account instead.",
|
||||
"glAccountId", glAccountId);
|
||||
}
|
||||
}
|
||||
}
|
||||
-188
@@ -25,14 +25,12 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.fineract.accounting.closure.domain.GLClosure;
|
||||
import org.apache.fineract.accounting.closure.domain.GLClosureRepository;
|
||||
import org.apache.fineract.accounting.common.AccountingConstants;
|
||||
import org.apache.fineract.accounting.common.AccountingConstants.AccrualAccountsForLoan;
|
||||
import org.apache.fineract.accounting.common.AccountingConstants.AccrualAccountsForSavings;
|
||||
import org.apache.fineract.accounting.common.AccountingConstants.CashAccountsForLoan;
|
||||
import org.apache.fineract.accounting.common.AccountingConstants.CashAccountsForSavings;
|
||||
import org.apache.fineract.accounting.common.AccountingConstants.CashAccountsForShares;
|
||||
@@ -79,7 +77,6 @@ import org.apache.fineract.portfolio.loanaccount.data.LoanTransactionEnumData;
|
||||
import org.apache.fineract.portfolio.savings.data.SavingsAccountTransactionEnumData;
|
||||
import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountTransactionEnumData;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class AccountingProcessorHelper {
|
||||
@@ -92,14 +89,6 @@ public class AccountingProcessorHelper {
|
||||
public static final String PROVISIONING_TRANSACTION_IDENTIFIER = "P";
|
||||
public static final String SHARE_TRANSACTION_IDENTIFIER = "SH";
|
||||
|
||||
/**
|
||||
* Reserved names on the savings product's Accounting tab, naming the two accounts an interest
|
||||
* posting is routed through. The names are the contract with the product screen; the GL codes
|
||||
* behind them are the bank's choice, so no code is named here.
|
||||
*/
|
||||
public static final String SAVINGS_INTEREST_PAYABLE_MAPPING = "Savings Interest Payable";
|
||||
public static final String SAVINGS_INTEREST_PAID_MAPPING = "Savings Interest Paid";
|
||||
|
||||
private static final ThreadLocal<Integer> DEPOSIT_ACCOUNT_TYPE_CONTEXT = ThreadLocal.withInitial(() -> 100);
|
||||
|
||||
public static void setDepositAccountTypeContext(int depositAccountType) {
|
||||
@@ -127,10 +116,6 @@ public class AccountingProcessorHelper {
|
||||
private final AccountTransfersReadPlatformService accountTransfersReadPlatformService;
|
||||
private final ChargeRepositoryWrapper chargeRepositoryWrapper;
|
||||
private final BusinessEventNotifierService businessEventNotifierService;
|
||||
// The savings interest payable/paid accounts live in m_savings_product.other_gl_mappings as a
|
||||
// JSON document rather than in acc_product_mapping, so they are read directly. See
|
||||
// namedSavingsGlAccount.
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
public LoanDTO populateLoanDtoFromDTO(
|
||||
final org.apache.fineract.portfolio.loanaccount.data.AccountingBridgeDataDTO accountingBridgeData) {
|
||||
@@ -615,144 +600,6 @@ public class AccountingProcessorHelper {
|
||||
createCreditJournalEntryForSavings(office, currencyCode, creditAccount, savingsId, transactionId, transactionDate, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interest credited to a member, routed through the payable and paid accounts the product names.
|
||||
*
|
||||
* <pre>
|
||||
* Dr Interest On Savings (expense) the bank incurs the cost
|
||||
* Cr Savings Interest Payable (liability) and now owes it
|
||||
*
|
||||
* Dr Savings Interest Payable
|
||||
* Cr Savings Interest Paid the debt is on its way out
|
||||
*
|
||||
* Dr Savings Interest Paid
|
||||
* Cr Savings Control and reaches the member
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* The two middle accounts net to nil across the three steps, so the trial balance is unchanged
|
||||
* from the plain two-legged entry; what they add is a reading of how much interest has been
|
||||
* declared but not yet credited, which a single Dr/Cr pair cannot show.
|
||||
*
|
||||
* <p>
|
||||
* Both are read from the product's Accounting tab and neither is required. A product that names
|
||||
* no paid account collapses the middle step, and one that names no payable falls back to its own
|
||||
* Savings Control - either way the posting degrades to exactly the two-legged entry it was
|
||||
* before, so products configured before these mappings existed are unaffected.
|
||||
*
|
||||
* <p>
|
||||
* Reversals swap every leg, the same way {@code createCashBasedJournalEntriesAndReversalsForSavings}
|
||||
* does for the two-legged case.
|
||||
*/
|
||||
public void createInterestPostingJournalEntriesForSavings(final Office office, final String currencyCode,
|
||||
final Long savingsProductId, final Long paymentTypeId, final Long savingsId, final String transactionId,
|
||||
final LocalDate transactionDate, final BigDecimal amount, final boolean isReversal) {
|
||||
|
||||
final GLAccount controlAccount = getLinkedGLAccountForSavingsProduct(savingsProductId,
|
||||
CashAccountsForSavings.SAVINGS_CONTROL.getValue(), paymentTypeId);
|
||||
|
||||
// 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
|
||||
// consulted only after that, for a product configured before that row was mapped, and the
|
||||
// Savings Control last of all - interest owed is a liability either way.
|
||||
final GLAccount payableAccount = Optional
|
||||
.ofNullable(optionalLinkedGLAccountForSavingsProduct(savingsProductId,
|
||||
AccrualAccountsForSavings.INTEREST_PAYABLE.getValue(), paymentTypeId))
|
||||
.or(() -> Optional.ofNullable(namedSavingsGlAccount(savingsProductId, SAVINGS_INTEREST_PAYABLE_MAPPING)))
|
||||
.orElse(controlAccount);
|
||||
final GLAccount paidAccount = Optional.ofNullable(namedSavingsGlAccount(savingsProductId, SAVINGS_INTEREST_PAID_MAPPING))
|
||||
.orElse(payableAccount);
|
||||
|
||||
// The interest expense is not raised here. It is recognised as the interest accrues, day by
|
||||
// day, and this posting settles that recognised debt - raising the expense again at payout
|
||||
// would put the same interest on the P&L twice. This mirrors the pooled posting service,
|
||||
// which pays a product's whole membership the same way; a closure reaching this path must
|
||||
// produce the same entries as the nightly run, or the two disagree on what one payment did.
|
||||
//
|
||||
// Stage 1: the liability moves from the payable to the account it is paid out of. Where the
|
||||
// product names no paid account both resolve to the payable and this says nothing, so it is
|
||||
// skipped and the payout comes straight out of the payable.
|
||||
final boolean payableIsPaid = payableAccount.getId().equals(paidAccount.getId());
|
||||
if (!payableIsPaid) {
|
||||
postSavingsLeg(office, currencyCode, payableAccount, paidAccount, savingsId, transactionId, transactionDate, amount,
|
||||
isReversal);
|
||||
}
|
||||
|
||||
// Stage 2: into the member's own balance.
|
||||
final GLAccount payoutFromAccount = payableIsPaid ? payableAccount : paidAccount;
|
||||
postSavingsLeg(office, currencyCode, payoutFromAccount, controlAccount, savingsId, transactionId, transactionDate, amount,
|
||||
isReversal);
|
||||
}
|
||||
|
||||
/**
|
||||
* One Dr/Cr pair, with both sides swapped when the transaction is a reversal.
|
||||
*
|
||||
* <p>
|
||||
* A leg whose two sides are the same account writes nothing. That is not a defensive check but
|
||||
* the mechanism by which the three stages above collapse: a product that names no payable and no
|
||||
* paid account resolves all three to its Savings Control, and what should remain is the plain
|
||||
* {@code Dr Interest On Savings / Cr Savings Control} pair Fineract has always posted. Skipping
|
||||
* the middle stage by hand was not enough — stage 3 still resolved to Control against Control and
|
||||
* wrote a pair of entries against one account, which nets to nothing yet leaves the transaction's
|
||||
* debits and credits unequal per account and shows up on the trial balance as movement that never
|
||||
* happened. Deciding it here rather than at each call site means every collapse works the same
|
||||
* way, whichever of the two names a product happens to leave unset.
|
||||
*/
|
||||
private void postSavingsLeg(final Office office, final String currencyCode, final GLAccount debitAccount,
|
||||
final GLAccount creditAccount, final Long savingsId, final String transactionId, final LocalDate transactionDate,
|
||||
final BigDecimal amount, final boolean isReversal) {
|
||||
if (debitAccount == null || creditAccount == null || debitAccount.getId().equals(creditAccount.getId())) {
|
||||
return;
|
||||
}
|
||||
final GLAccount toDebit = isReversal ? creditAccount : debitAccount;
|
||||
final GLAccount toCredit = isReversal ? debitAccount : creditAccount;
|
||||
createDebitJournalEntryForSavings(office, currencyCode, toDebit, savingsId, transactionId, transactionDate, amount);
|
||||
createCreditJournalEntryForSavings(office, currencyCode, toCredit, savingsId, transactionId, transactionDate, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* A GL account the savings product maps under one of the reserved names on its Accounting tab.
|
||||
*
|
||||
* <p>
|
||||
* These live in {@code m_savings_product.other_gl_mappings} as a JSON document of
|
||||
* {@code {assets|liabilities|expenses|income: [{accountName, glCode}]}} rather than in
|
||||
* {@code acc_product_mapping}, because they are named extensions rather than one of Fineract's
|
||||
* fixed financial account types. The name is matched across all four groups: which group a bank
|
||||
* files it under is a presentation choice, and an account configured under the wrong heading
|
||||
* should still be honoured rather than silently ignored.
|
||||
*
|
||||
* @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) {
|
||||
return null;
|
||||
}
|
||||
// The column holds an empty string on a product saved with no named mappings, and casting
|
||||
// that to jsonb is an error rather than an empty document - so the cast is done inside a
|
||||
// subquery that has already filtered those rows out. Postgres is free to evaluate a WHERE
|
||||
// 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("""
|
||||
SELECT gl.id
|
||||
FROM (SELECT other_gl_mappings::jsonb AS doc
|
||||
FROM m_savings_product
|
||||
WHERE id = ?
|
||||
AND other_gl_mappings IS NOT NULL
|
||||
AND other_gl_mappings <> ''
|
||||
AND other_gl_mappings LIKE '{%') sp
|
||||
CROSS JOIN LATERAL jsonb_array_elements(
|
||||
COALESCE(sp.doc -> 'assets', '[]'::jsonb)
|
||||
|| COALESCE(sp.doc -> 'liabilities', '[]'::jsonb)
|
||||
|| COALESCE(sp.doc -> 'expenses', '[]'::jsonb)
|
||||
|| COALESCE(sp.doc -> 'income', '[]'::jsonb)
|
||||
) AS m(entry)
|
||||
JOIN acc_gl_account gl ON gl.gl_code = m.entry ->> 'glCode'
|
||||
WHERE m.entry ->> 'accountName' = ?
|
||||
LIMIT 1
|
||||
""", Long.class, savingsProductId, accountName);
|
||||
return found.isEmpty() ? null : glAccountRepository.findById(found.get(0)).orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a direct transfer journal entry between two savings-type accounts (savings or current),
|
||||
* each with their own product GL mapping and entity ID so the correct account number appears per entry.
|
||||
@@ -1394,29 +1241,6 @@ public class AccountingProcessorHelper {
|
||||
return accountMapping.getGlAccount();
|
||||
}
|
||||
|
||||
/**
|
||||
* One row of the savings product's Accounting tab, or null where the bank has not filled it in.
|
||||
*
|
||||
* <p>
|
||||
* Separate from {@link #getLinkedGLAccountForSavingsProduct}, which throws: not every row is
|
||||
* required. Interest Payable is offered on the product screen but a product configured before it
|
||||
* existed has none, and that has to fall through to the next choice rather than stopping the
|
||||
* account from being closed.
|
||||
*/
|
||||
private GLAccount optionalLinkedGLAccountForSavingsProduct(final Long savingsProductId, final int accountMappingTypeId,
|
||||
final Long paymentTypeId) {
|
||||
if (savingsProductId == null) {
|
||||
return null;
|
||||
}
|
||||
// Read directly rather than by catching what getLinkedGLAccountForSavingsProduct throws: on a
|
||||
// missing mapping that method builds its message through CashAccountsForSavings.fromInt,
|
||||
// which returns null for a row the cash enum does not carry - Interest Payable among them -
|
||||
// and the lookup would die on a NullPointerException instead of the exception meant for it.
|
||||
final ProductToGLAccountMapping mapping = this.accountMappingRepository.findCoreProductToFinAccountMapping(savingsProductId,
|
||||
PortfolioProductType.SAVING.getValue(), accountMappingTypeId);
|
||||
return mapping == null ? null : mapping.getGlAccount();
|
||||
}
|
||||
|
||||
private GLAccount getLinkedGLAccountForSavingsProduct(final Long savingsProductId, final int accountMappingTypeId,
|
||||
final Long paymentTypeId) {
|
||||
GLAccount glAccount;
|
||||
@@ -1439,11 +1263,6 @@ public class AccountingProcessorHelper {
|
||||
accountMapping = paymentChannelSpecificAccountMapping;
|
||||
}
|
||||
}
|
||||
|
||||
if (accountMapping == null) {
|
||||
throw new ProductToGLAccountMappingNotFoundException(PortfolioProductType.SAVING, savingsProductId,
|
||||
CashAccountsForSavings.fromInt(accountMappingTypeId).toString());
|
||||
}
|
||||
glAccount = accountMapping.getGlAccount();
|
||||
}
|
||||
return glAccount;
|
||||
@@ -1468,13 +1287,6 @@ public class AccountingProcessorHelper {
|
||||
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();
|
||||
}
|
||||
return glAccount;
|
||||
|
||||
+3
-6
@@ -170,12 +170,9 @@ public class CashBasedAccountingProcessorForSavings implements AccountingProcess
|
||||
// Post journal entry if earned interest amount is greater than
|
||||
// zero
|
||||
if (savingsTransactionDTO.getAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||
// 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
|
||||
// to the plain Dr Interest On Savings / Cr Savings Control pair for a product
|
||||
// that names neither.
|
||||
this.helper.createInterestPostingJournalEntriesForSavings(office, currencyCode, savingsProductId, paymentTypeId,
|
||||
savingsId, transactionId, transactionDate, amount, isReversal);
|
||||
this.helper.createCashBasedJournalEntriesAndReversalsForSavings(office, currencyCode,
|
||||
CashAccountsForSavings.INTEREST_ON_SAVINGS.getValue(), CashAccountsForSavings.SAVINGS_CONTROL.getValue(),
|
||||
savingsProductId, paymentTypeId, savingsId, transactionId, transactionDate, amount, isReversal);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-138
@@ -21,11 +21,9 @@ package org.apache.fineract.accounting.journalentry.service;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -106,8 +104,6 @@ import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionRepositor
|
||||
import org.apache.fineract.portfolio.loanproduct.service.LoanEnumerations;
|
||||
import org.apache.fineract.portfolio.paymentdetail.domain.PaymentDetail;
|
||||
import org.apache.fineract.portfolio.paymentdetail.service.PaymentDetailWritePlatformService;
|
||||
import org.apache.fineract.portfolio.voucher.service.VoucherLine;
|
||||
import org.apache.fineract.portfolio.voucher.service.VoucherService;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.dao.NonTransientDataAccessException;
|
||||
@@ -140,7 +136,6 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
|
||||
private final ExternalAssetOwnerRepository externalAssetOwnerRepository;
|
||||
private final LoanAmortizationAllocationMappingRepository loanAmortizationAllocationMappingRepository;
|
||||
private final LoanTransactionRepository loanTransactionRepository;
|
||||
private final VoucherService voucherService;
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
@@ -237,73 +232,14 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
|
||||
|
||||
}
|
||||
|
||||
// Raise the voucher from the entries that were actually written, rather than from the
|
||||
// command: an accounting rule can supply a side the request never named, so reading
|
||||
// back by transaction id is the only view that matches what the ledger now holds.
|
||||
final String voucherNo = raiseJournalVoucher(transactionId);
|
||||
if (voucherNo != null) {
|
||||
changes.put("voucherNo", voucherNo);
|
||||
}
|
||||
|
||||
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withOfficeId(officeId)
|
||||
.withTransactionId(transactionId).with(changes).build();
|
||||
.withTransactionId(transactionId).build();
|
||||
} catch (final JpaSystemException | DataIntegrityViolationException dve) {
|
||||
final Throwable throwable = dve.getMostSpecificCause();
|
||||
throw handleJournalEntryDataIntegrityIssues(throwable, dve);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Records a manual journal in the voucher register and returns its number.
|
||||
*
|
||||
* The sides are read back from the entries just written rather than taken from the request,
|
||||
* because an accounting rule can contribute a debit or credit the caller never named; only the
|
||||
* persisted rows show what the ledger actually holds.
|
||||
*
|
||||
* A failure here does not fail the journal. The entries are already posted and correct, and
|
||||
* refusing them because the register could not be written would reject a sound accounting
|
||||
* transaction over its paperwork. The problem is logged and the journal stands without a
|
||||
* voucher, which reads as a gap in the register rather than as a missing ledger entry.
|
||||
*/
|
||||
private String raiseJournalVoucher(final String transactionId) {
|
||||
// A register that posts its ledger movement through this command raises its own voucher,
|
||||
// naming the member and the instrument. Raising a journal one beside it would put the same
|
||||
// money in the register twice.
|
||||
if (!this.voucherService.shouldRaiseVoucher()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
final List<JournalEntry> entries = this.glJournalEntryRepository
|
||||
.findUnReversedManualJournalEntriesByTransactionId(transactionId);
|
||||
if (CollectionUtils.isEmpty(entries)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final List<VoucherLine> lines = new ArrayList<>();
|
||||
for (final JournalEntry entry : entries) {
|
||||
final GLAccount account = entry.getGlAccount();
|
||||
final Long accountId = account == null ? null : account.getId();
|
||||
final String name = account == null ? null : account.getName();
|
||||
final String code = account == null ? null : account.getGlCode();
|
||||
|
||||
final VoucherLine line = entry.isDebitEntry() ? VoucherLine.debitGl(accountId, name, code, entry.getAmount())
|
||||
: VoucherLine.creditGl(accountId, name, code, entry.getAmount());
|
||||
lines.add(entry.getDescription() == null ? line : line.withDescription(entry.getDescription()));
|
||||
}
|
||||
|
||||
// Debits first, so the voucher prints the way a slip is read.
|
||||
lines.sort(Comparator.comparing(VoucherLine::isDebit).reversed());
|
||||
|
||||
final AppUser currentUser = this.context.authenticatedUser();
|
||||
return this.voucherService.createVoucherWithLines(VoucherService.TYPE_JOURNAL, VoucherService.REF_JOURNAL_ENTRY, null,
|
||||
transactionId, currentUser, VoucherService.PREFIX_JOURNAL, lines);
|
||||
} catch (final RuntimeException e) {
|
||||
log.error("Could not raise a voucher for journal transaction {}", transactionId, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void validateDebitOrCreditArrayForExistingGLAccount(final GLAccount glaccount,
|
||||
final SingleDebitOrCreditEntryCommand[] creditOrDebits) {
|
||||
/**
|
||||
@@ -392,9 +328,6 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
|
||||
} else if (!creditOrDebitAccountHead.isManualEntriesAllowed()) {
|
||||
throw new JournalEntryInvalidException(GlJournalEntryInvalidReason.GL_ACCOUNT_MANUAL_ENTRIES_NOT_PERMITTED, null,
|
||||
creditOrDebitAccountHead.getName(), creditOrDebitAccountHead.getGlCode());
|
||||
} else if (creditOrDebitAccountHead.isHeaderAccount()) {
|
||||
throw new JournalEntryInvalidException(GlJournalEntryInvalidReason.GL_ACCOUNT_IS_HEADER, null,
|
||||
creditOrDebitAccountHead.getName(), creditOrDebitAccountHead.getGlCode());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -631,12 +564,7 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
|
||||
final boolean cashBasedAccountingEnabled = (Boolean) accountingBridgeData.get("cashBasedAccountingEnabled");
|
||||
final boolean accrualBasedAccountingEnabled = (Boolean) accountingBridgeData.get("accrualBasedAccountingEnabled");
|
||||
|
||||
// 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()) {
|
||||
if (cashBasedAccountingEnabled) {
|
||||
final SharesDTO sharesDTO = this.helper.populateSharesDtoFromMap(accountingBridgeData, cashBasedAccountingEnabled,
|
||||
accrualBasedAccountingEnabled);
|
||||
final AccountingProcessorForShares accountingProcessorForShares = this.accountingProcessorForSharesFactory
|
||||
@@ -784,30 +712,15 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
|
||||
final String currencyCode = command.stringValueOfParameterNamed(JournalEntryJsonInputParams.CURRENCY_CODE.getValue());
|
||||
|
||||
validateBusinessRulesForJournalEntries(journalEntryCommand);
|
||||
validateNoDenominationManagedCashAccounts(journalEntryCommand);
|
||||
|
||||
/**
|
||||
* revert old journal entries
|
||||
*
|
||||
* A transaction that carries a leg against the denomination-managed cash account (see
|
||||
* validateNoDenominationManagedCashAccounts) is skipped here rather than reversed: it is
|
||||
* tied to this same office+contra pairing (Migrate Cash Denomination posts its opening
|
||||
* entry against this same Opening Balances Contra account), so the query above finds it
|
||||
* too. Reversing it here, while the new submission is barred from ever re-posting a cash
|
||||
* leg, would silently erase the cash account's opening balance every time an admin
|
||||
* redefines opening balances for any OTHER account at this office.
|
||||
*/
|
||||
final List<Long> denominationManagedGlAccountIds = resolveDenominationManagedCashGlAccountIds();
|
||||
final List<String> transactionIdsToBeReversed = this.glJournalEntryRepository.findNonReversedContraTransactionIds(contraId,
|
||||
officeId);
|
||||
for (String transactionId : transactionIdsToBeReversed) {
|
||||
final List<JournalEntry> journalEntries = this.glJournalEntryRepository
|
||||
.findUnReversedManualJournalEntriesByTransactionId(transactionId);
|
||||
final boolean touchesDenominationManagedCashAccount = journalEntries.stream()
|
||||
.anyMatch(je -> je.getGlAccount() != null && denominationManagedGlAccountIds.contains(je.getGlAccount().getId()));
|
||||
if (touchesDenominationManagedCashAccount) {
|
||||
continue;
|
||||
}
|
||||
revertJournalEntry(journalEntries, "defining opening balance");
|
||||
}
|
||||
|
||||
@@ -889,55 +802,6 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The GL account(s) Financial Activity 101 (Cash at Vault) / 102 (Cash at Teller) map to. Shared
|
||||
* by the validation below and by defineOpeningBalance's own revert step, so both agree on exactly
|
||||
* which account(s) Migrate Cash Denomination owns.
|
||||
*/
|
||||
private List<Long> resolveDenominationManagedCashGlAccountIds() {
|
||||
final List<Long> ids = new ArrayList<>();
|
||||
for (final FinancialActivityAccount mapping : this.financialActivityAccountRepositoryWrapper.findAll()) {
|
||||
final Integer type = mapping.getFinancialActivityType();
|
||||
if ((type != null && (type == 101 || type == 102)) && mapping.getGlAccount() != null) {
|
||||
ids.add(mapping.getGlAccount().getId());
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* The GL account(s) mapped to Financial Activity 101 (Cash at Vault) / 102 (Cash at Teller) are
|
||||
* managed exclusively through Migrate Cash Denomination (BranchDayRegisterApiResource#migrateCashDenomination),
|
||||
* which keeps the GL figure tied to an actual counted note-and-coin breakdown, and validates any
|
||||
* redefinition against that same count. Defining or redefining that account's opening balance here
|
||||
* instead - as a bare number, with no denomination breakdown behind it - would let the GL figure
|
||||
* drift away from what is physically in the till, with nothing left to catch the mismatch. So this
|
||||
* command refuses to touch either of those accounts at all, on either side of the entry, rather than
|
||||
* only when the amount would differ from what is already posted: the physical count is the only
|
||||
* source of truth for this account, never a number typed into a generic opening-balance grid.
|
||||
*/
|
||||
private void validateNoDenominationManagedCashAccounts(final JournalEntryCommand command) {
|
||||
final List<Long> denominationManagedGlAccountIds = resolveDenominationManagedCashGlAccountIds();
|
||||
if (denominationManagedGlAccountIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
final List<SingleDebitOrCreditEntryCommand> allEntries = new ArrayList<>();
|
||||
if (command.getDebits() != null) {
|
||||
allEntries.addAll(Arrays.asList(command.getDebits()));
|
||||
}
|
||||
if (command.getCredits() != null) {
|
||||
allEntries.addAll(Arrays.asList(command.getCredits()));
|
||||
}
|
||||
for (final SingleDebitOrCreditEntryCommand entry : allEntries) {
|
||||
if (denominationManagedGlAccountIds.contains(entry.getGlAccountId())) {
|
||||
throw new GeneralPlatformDomainRuleException("error.msg.journalentry.opening.balance.cash.account.locked",
|
||||
"This account is the tenant's Cash at Vault / Cash at Teller account and is managed through "
|
||||
+ "Migrate Cash Denomination - it cannot be set or changed from Migrate Opening Balances.",
|
||||
entry.getGlAccountId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createJournalEntriesForClientTransactions(Map<String, Object> accountingBridgeData) {
|
||||
final ClientTransactionDTO clientTransactionDTO = this.helper.populateClientTransactionDtoFromMap(accountingBridgeData);
|
||||
|
||||
-157
@@ -1,157 +0,0 @@
|
||||
/**
|
||||
* 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
@@ -1,87 +0,0 @@
|
||||
/**
|
||||
* 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
@@ -1,83 +0,0 @@
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
+4
-6
@@ -52,7 +52,6 @@ import org.apache.fineract.portfolio.charge.domain.ChargeRepositoryWrapper;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanAmortizationAllocationMappingRepository;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionRepository;
|
||||
import org.apache.fineract.portfolio.paymentdetail.service.PaymentDetailWritePlatformService;
|
||||
import org.apache.fineract.portfolio.voucher.service.VoucherService;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -68,10 +67,10 @@ public class AccountingJournalEntryConfiguration {
|
||||
FinancialActivityAccountRepositoryWrapper financialActivityAccountRepository, GLClosureRepository closureRepository,
|
||||
GLAccountRepository glAccountRepository, OfficeRepository officeRepository,
|
||||
AccountTransfersReadPlatformService accountTransfersReadPlatformService, ChargeRepositoryWrapper chargeRepositoryWrapper,
|
||||
BusinessEventNotifierService businessEventNotifierService, JdbcTemplate jdbcTemplate) {
|
||||
BusinessEventNotifierService businessEventNotifierService) {
|
||||
return new AccountingProcessorHelper(glJournalEntryRepository, accountMappingRepository, financialActivityAccountRepository,
|
||||
closureRepository, glAccountRepository, officeRepository, accountTransfersReadPlatformService, chargeRepositoryWrapper,
|
||||
businessEventNotifierService, jdbcTemplate);
|
||||
businessEventNotifierService);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -99,13 +98,12 @@ public class AccountingJournalEntryConfiguration {
|
||||
ConfigurationReadPlatformService configurationReadPlatformService, AccountingService accountingService,
|
||||
ExternalAssetOwnerRepository externalAssetOwnerRepository,
|
||||
LoanAmortizationAllocationMappingRepository loanAmortizationAllocationMappingRepository,
|
||||
LoanTransactionRepository loanTransactionRepository, VoucherService voucherService) {
|
||||
LoanTransactionRepository loanTransactionRepository) {
|
||||
return new JournalEntryWritePlatformServiceJpaRepositoryImpl(glClosureRepository, glAccountRepository, glJournalEntryRepository,
|
||||
officeRepositoryWrapper, accountingProcessorForLoanFactory, accountingProcessorForSavingsFactory,
|
||||
accountingProcessorForSharesFactory, helper, fromApiJsonDeserializer, accountingRuleRepository,
|
||||
glAccountReadPlatformService, organisationCurrencyRepository, context, paymentDetailWritePlatformService,
|
||||
financialActivityAccountRepositoryWrapper, accountingProcessorForClientTransactions, configurationReadPlatformService,
|
||||
accountingService, externalAssetOwnerRepository, loanAmortizationAllocationMappingRepository, loanTransactionRepository,
|
||||
voucherService);
|
||||
accountingService, externalAssetOwnerRepository, loanAmortizationAllocationMappingRepository, loanTransactionRepository);
|
||||
}
|
||||
}
|
||||
|
||||
-9
@@ -301,15 +301,6 @@ public class ProductToGLAccountMappingWritePlatformServiceImpl implements Produc
|
||||
CashAccountsForSavings.ESCHEAT_LIABILITY.getValue());
|
||||
}
|
||||
|
||||
// Optional: only mapped when the product screen supplies it. Every savings product that
|
||||
// existed before this row was added has none, and a closure on one of those still has to
|
||||
// work — see the closure's own fallback.
|
||||
if (this.fromApiJsonHelper.parameterExists(SavingProductAccountingParams.ROUNDING_ADJUSTMENT.getValue(), element)) {
|
||||
this.savingsProductToGLAccountMappingHelper.saveSavingsToExpenseAccountMapping(element,
|
||||
SavingProductAccountingParams.ROUNDING_ADJUSTMENT.getValue(), savingProductId,
|
||||
CashAccountsForSavings.ROUNDING_ADJUSTMENT.getValue());
|
||||
}
|
||||
|
||||
// advanced accounting mappings
|
||||
this.savingsProductToGLAccountMappingHelper.savePaymentChannelToFundSourceMappings(command, element, savingProductId, null);
|
||||
this.savingsProductToGLAccountMappingHelper.saveChargesToIncomeAccountMappings(command, element, savingProductId, null);
|
||||
|
||||
-264
@@ -1,264 +0,0 @@
|
||||
/**
|
||||
* 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.profitandloss.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
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.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.sql.Date;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.accounting.common.DividendGlAccountResolver;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* How much profit is available to fund a share dividend, for a given period.
|
||||
*
|
||||
* This is not what sizes a dividend — that is the declared rate on members' paid-up capital. It is what the society has
|
||||
* to pay it with: the profit standing in the Bank Profit (Non-Distributable) GL, less every dividend already declared
|
||||
* for another share product over the same period, since they all draw on the same balance.
|
||||
*
|
||||
* The statutory reserve and education fund are not deducted here. They are appropriated on the profit-distribution
|
||||
* screen before any dividend is declared, so the balance this reads has already had them taken out; deducting them a
|
||||
* second time would hold back money that has already left the account.
|
||||
*
|
||||
* Held in one place so the declaration screen and the declaration-time validation cannot disagree about the ceiling.
|
||||
*/
|
||||
@Path("/v1/accounting/distributable-profit")
|
||||
@Component
|
||||
@Tag(name = "Distributable Profit", description = "Profit available to fund a share dividend, less dividends already declared against the same period.")
|
||||
@RequiredArgsConstructor
|
||||
public class DistributableProfitApiResource {
|
||||
|
||||
/**
|
||||
* The year's closed-out profit, which is what a dividend may be declared against.
|
||||
*
|
||||
* Deliberately not Retained Profit — that holds what earlier declarations left behind, and reading it here would
|
||||
* offer profit already distributed once for distribution again.
|
||||
*/
|
||||
private final DividendGlAccountResolver dividendGlAccounts;
|
||||
|
||||
private static final String CONFIG_MAXIMUM_RATE = "dividend-maximum-rate-percentage";
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final Gson gson = new GsonBuilder().serializeNulls().create();
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String getDistributableProfit(@QueryParam("fromDate") final String fromDate, @QueryParam("toDate") final String toDate,
|
||||
@QueryParam("excludeProductId") final Long excludeProductId) {
|
||||
if (fromDate == null || fromDate.isBlank() || toDate == null || toDate.isBlank()) {
|
||||
throw apiError(400, "fromDate and toDate (yyyy-MM-dd) are both required");
|
||||
}
|
||||
final Date from;
|
||||
final Date to;
|
||||
try {
|
||||
from = Date.valueOf(fromDate);
|
||||
to = Date.valueOf(toDate);
|
||||
} catch (final IllegalArgumentException e) {
|
||||
throw apiError(400, "fromDate and toDate must be in yyyy-MM-dd format");
|
||||
}
|
||||
if (to.before(from)) {
|
||||
throw apiError(400, "toDate must not be before fromDate");
|
||||
}
|
||||
|
||||
// A dividend is normally declared for a whole, closed financial year, and then the audited
|
||||
// profit in Bank Profit is the figure to use. A period that is not a full financial year can
|
||||
// only be an interim declaration, which necessarily runs against the still-open P&L.
|
||||
final String financialYear = financialYearOf(from.toLocalDate());
|
||||
final LocalDate[] fyRange = financialYearRange(financialYear);
|
||||
final boolean coversWholeFinancialYear = !from.toLocalDate().isAfter(fyRange[0]) && !to.toLocalDate().isBefore(fyRange[1]);
|
||||
|
||||
final BigDecimal closedProfit = coversWholeFinancialYear ? closedProfitForFinancialYear(financialYear) : null;
|
||||
final boolean yearClosed = closedProfit != null;
|
||||
final BigDecimal netProfit = yearClosed ? closedProfit : netProfitForPeriod(from, to);
|
||||
|
||||
final BigDecimal maximumRatePercentage = configuredPercentage(CONFIG_MAXIMUM_RATE);
|
||||
|
||||
// The statutory reserve and education fund are NOT deducted here. They are appropriated on
|
||||
// the profit-distribution screen before any dividend is declared, so the profit this reads
|
||||
// has already had them taken out — subtracting them again would hold back money that is no
|
||||
// longer in the account. A loss-making period funds nothing, so it collapses to zero rather
|
||||
// than a negative figure a caller could read as a credit.
|
||||
final BigDecimal distributableProfit = netProfit.signum() > 0 ? netProfit : BigDecimal.ZERO;
|
||||
|
||||
final List<Map<String, Object>> existingDeclarations = declarationsOverlapping(from, to, excludeProductId);
|
||||
BigDecimal alreadyDeclared = BigDecimal.ZERO;
|
||||
for (final Map<String, Object> declaration : existingDeclarations) {
|
||||
alreadyDeclared = alreadyDeclared.add((BigDecimal) declaration.get("amount"));
|
||||
}
|
||||
|
||||
// An over-declaration that already happened (or appropriation rates raised after the fact)
|
||||
// must not present as negative headroom, which a caller could read as a credit.
|
||||
final BigDecimal availableForDeclaration = distributableProfit.subtract(alreadyDeclared).max(BigDecimal.ZERO);
|
||||
|
||||
final Map<String, Object> response = new LinkedHashMap<>();
|
||||
response.put("fromDate", fromDate);
|
||||
response.put("toDate", toDate);
|
||||
response.put("financialYear", financialYear);
|
||||
response.put("coversWholeFinancialYear", coversWholeFinancialYear);
|
||||
response.put("yearClosed", yearClosed);
|
||||
// Names the figure so the screen can say where it came from — the closed books, or a P&L
|
||||
// that is still moving — rather than showing a bare number the officer has to interpret.
|
||||
response.put("profitSource", yearClosed ? "BANK_PROFIT_GL" : "OPEN_PROFIT_AND_LOSS");
|
||||
response.put("netProfit", netProfit);
|
||||
response.put("distributableProfit", distributableProfit);
|
||||
response.put("alreadyDeclared", alreadyDeclared);
|
||||
response.put("availableForDeclaration", availableForDeclaration);
|
||||
response.put("maximumRatePercentage", maximumRatePercentage);
|
||||
response.put("existingDeclarations", existingDeclarations);
|
||||
return gson.toJson(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* The year's profit as the books actually record it, once the year has been closed.
|
||||
*
|
||||
* A dividend is declared out of the AUDITED profit of a completed financial year, and that figure lives in the
|
||||
* Bank Profit equity GL after year-end closing moves every income and expense GL into it. Reading it here — rather
|
||||
* than re-deriving income-less-expense — means the dividend can never disagree with the closed books: if a
|
||||
* closing entry was adjusted, reversed, or posted late, the dividend ceiling moves with it.
|
||||
*
|
||||
* Returns null when the year has not been closed, which the caller reports as a blocking condition rather than
|
||||
* silently falling back to the live P&L. Distributing against an unclosed year would be distributing a profit
|
||||
* figure that is still moving.
|
||||
*/
|
||||
private BigDecimal closedProfitForFinancialYear(final String financialYear) {
|
||||
final Integer closedCount = jdbcTemplate.queryForObject(
|
||||
"SELECT COUNT(*) FROM m_income_profit_transfer WHERE financial_year = ?", Integer.class, financialYear);
|
||||
if (closedCount == null || closedCount == 0) {
|
||||
return null;
|
||||
}
|
||||
final LocalDate[] range = financialYearRange(financialYear);
|
||||
final BigDecimal balance = jdbcTemplate.queryForObject("""
|
||||
SELECT COALESCE(SUM(CASE WHEN je.type_enum = 1 THEN je.amount ELSE -je.amount END), 0)
|
||||
FROM acc_gl_journal_entry je
|
||||
WHERE je.account_id = ? AND je.reversed = false AND je.entry_date BETWEEN ? AND ?
|
||||
""", BigDecimal.class, dividendGlAccounts.distributableProfitAccount(), java.sql.Date.valueOf(range[0]),
|
||||
java.sql.Date.valueOf(range[1]));
|
||||
return balance == null ? BigDecimal.ZERO : balance;
|
||||
}
|
||||
|
||||
/** "2026-27" -> 1 April 2026 to 31 March 2027. */
|
||||
private LocalDate[] financialYearRange(final String financialYear) {
|
||||
try {
|
||||
final int startYear = Integer.parseInt(financialYear.substring(0, 4));
|
||||
return new LocalDate[] { LocalDate.of(startYear, 4, 1), LocalDate.of(startYear + 1, 3, 31) };
|
||||
} catch (final RuntimeException e) {
|
||||
throw apiError(400, "financialYear must look like 2026-27. Received: " + financialYear);
|
||||
}
|
||||
}
|
||||
|
||||
/** The Indian financial year a date falls in, as a "YYYY-YY" label. */
|
||||
private String financialYearOf(final LocalDate date) {
|
||||
final int startYear = date.getMonthValue() >= 4 ? date.getYear() : date.getYear() - 1;
|
||||
return startYear + "-" + String.format("%02d", (startYear + 1) % 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Same income-less-expense computation as {@link ProfitAndLossApiResource}, over posted, non-reversed journal
|
||||
* entries only. Used only for the interim case — a period inside a year that has not been closed yet.
|
||||
*/
|
||||
private BigDecimal netProfitForPeriod(final Date from, final Date to) {
|
||||
final Map<String, Object> row = jdbcTemplate.queryForMap("""
|
||||
SELECT
|
||||
COALESCE(SUM(CASE WHEN a.classification_enum = 4 AND je.type_enum = 1 THEN je.amount
|
||||
WHEN a.classification_enum = 4 AND je.type_enum = 2 THEN -je.amount
|
||||
ELSE 0 END), 0) AS total_income,
|
||||
COALESCE(SUM(CASE WHEN a.classification_enum = 5 AND je.type_enum = 2 THEN je.amount
|
||||
WHEN a.classification_enum = 5 AND je.type_enum = 1 THEN -je.amount
|
||||
ELSE 0 END), 0) AS total_expense
|
||||
FROM acc_gl_journal_entry je
|
||||
JOIN acc_gl_account a ON a.id = je.account_id
|
||||
WHERE je.reversed = false
|
||||
AND je.entry_date BETWEEN ? AND ?
|
||||
""", from, to);
|
||||
final BigDecimal totalIncome = (BigDecimal) row.get("total_income");
|
||||
final BigDecimal totalExpense = (BigDecimal) row.get("total_expense");
|
||||
return totalIncome.subtract(totalExpense);
|
||||
}
|
||||
|
||||
/**
|
||||
* Every dividend already declared against a period overlapping this one, across ALL share products — the profit is
|
||||
* society-wide, so a second product's declaration competes for the same balance as the first.
|
||||
*
|
||||
* excludeProductId lets the declaration screen leave out the product being declared for, whose own overlapping
|
||||
* declaration is separately blocked outright.
|
||||
*/
|
||||
private List<Map<String, Object>> declarationsOverlapping(final Date from, final Date to, final Long excludeProductId) {
|
||||
final StringBuilder sql = new StringBuilder("""
|
||||
SELECT d.id AS declaration_id, d.product_id, p.name AS product_name, d.amount,
|
||||
d.dividend_period_start_date, d.dividend_period_end_date, d.status
|
||||
FROM m_share_product_dividend_pay_out d
|
||||
JOIN m_share_product p ON p.id = d.product_id
|
||||
WHERE d.dividend_period_start_date <= ? AND d.dividend_period_end_date >= ?
|
||||
""");
|
||||
final List<Object> params = new ArrayList<>(List.of(to, from));
|
||||
if (excludeProductId != null) {
|
||||
sql.append(" AND d.product_id <> ? ");
|
||||
params.add(excludeProductId);
|
||||
}
|
||||
sql.append(" ORDER BY d.dividend_period_start_date, d.id");
|
||||
|
||||
final List<Map<String, Object>> declarations = new ArrayList<>();
|
||||
for (final Map<String, Object> row : jdbcTemplate.queryForList(sql.toString(), params.toArray())) {
|
||||
final Map<String, Object> declaration = new LinkedHashMap<>();
|
||||
declaration.put("declarationId", row.get("declaration_id"));
|
||||
declaration.put("productId", row.get("product_id"));
|
||||
declaration.put("productName", row.get("product_name"));
|
||||
declaration.put("amount", row.get("amount"));
|
||||
declaration.put("periodStartDate", String.valueOf(row.get("dividend_period_start_date")));
|
||||
declaration.put("periodEndDate", String.valueOf(row.get("dividend_period_end_date")));
|
||||
declaration.put("status", row.get("status"));
|
||||
declarations.add(declaration);
|
||||
}
|
||||
return declarations;
|
||||
}
|
||||
|
||||
/**
|
||||
* A missing or disabled configuration row means the society does not make that appropriation (or has no ceiling),
|
||||
* which is 0 — not a failure. Only an enabled row with a value applies.
|
||||
*/
|
||||
private BigDecimal configuredPercentage(final String configurationName) {
|
||||
final List<Map<String, Object>> rows = jdbcTemplate
|
||||
.queryForList("SELECT value FROM c_configuration WHERE name = ? AND enabled = true", configurationName);
|
||||
if (rows.isEmpty() || rows.get(0).get("value") == null) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
return new BigDecimal(String.valueOf(rows.get(0).get("value")));
|
||||
}
|
||||
|
||||
private WebApplicationException apiError(final int httpStatus, final String message) {
|
||||
return new WebApplicationException(
|
||||
Response.status(httpStatus).entity(gson.toJson(Map.of("message", message))).type(MediaType.APPLICATION_JSON).build());
|
||||
}
|
||||
}
|
||||
-180
@@ -1,180 +0,0 @@
|
||||
package org.apache.fineract.accounting.yearend.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.POST;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.QueryParam;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.accounting.yearend.service.IncomeProfitTransferService;
|
||||
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
|
||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Financial year-end closing of the share entry fee into the Bank Profit equity GL.
|
||||
*
|
||||
* <p>
|
||||
* {@code GET} reports how much is waiting to be posted for the year and what has been posted before; {@code POST}
|
||||
* performs the closing. The scheduled job {@code Post Share Entry Fee To Profit} runs the same service on 31 March, so
|
||||
* this endpoint is the manual equivalent — useful when the job did not run, or the accountant wants to close early.
|
||||
*/
|
||||
@Path("/v1/accounting/incomeprofittransfer")
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public class IncomeProfitTransferApiResource {
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final IncomeProfitTransferService service;
|
||||
private final Gson gson = new Gson();
|
||||
|
||||
// ══════════════════════════════════════════════════════════════════════
|
||||
// GET — how much is waiting to be posted, and what has been posted before
|
||||
// ══════════════════════════════════════════════════════════════════════
|
||||
@GET
|
||||
public Response preview(@QueryParam("incomeGlCode") final String incomeGlCodeParam,
|
||||
@QueryParam("financialYear") final String financialYearParam) {
|
||||
|
||||
this.context.authenticatedUser();
|
||||
|
||||
final String incomeGlCode = incomeGlCodeParam == null || incomeGlCodeParam.isBlank()
|
||||
? IncomeProfitTransferService.DEFAULT_INCOME_GL_CODE
|
||||
: incomeGlCodeParam.trim();
|
||||
final Map<String, Object> incomeGl = service.loadGlByCode(incomeGlCode);
|
||||
final Map<String, Object> profitGl = service.loadDistributableProfitGl();
|
||||
|
||||
final String financialYear = financialYearParam == null || financialYearParam.isBlank() ? service.currentFinancialYear()
|
||||
: financialYearParam.trim();
|
||||
final LocalDate[] range = service.financialYearRange(financialYear);
|
||||
|
||||
final Long incomeGlId = toLong(incomeGl.get("id"));
|
||||
final BigDecimal pending = service.balanceOf(incomeGlId, range);
|
||||
final int entryCount = service.entryCountOf(incomeGlId, range);
|
||||
|
||||
final List<Map<String, Object>> history = jdbcTemplate
|
||||
.queryForList("SELECT t.id, t.financial_year, t.amount, t.entry_count, t.posted_on_date, t.posted_by_name, "
|
||||
+ " t.gl_transaction_id, g.gl_code AS income_gl_code, g.name AS income_gl_name "
|
||||
+ " FROM m_income_profit_transfer t JOIN acc_gl_account g ON g.id = t.income_gl_id "
|
||||
+ " WHERE t.income_gl_id = ? ORDER BY t.financial_year DESC, t.id DESC", incomeGlId);
|
||||
|
||||
final boolean alreadyPosted = history.stream().anyMatch(h -> financialYear.equals(h.get("financial_year")));
|
||||
|
||||
final Map<String, Object> out = new LinkedHashMap<>();
|
||||
out.put("financialYear", financialYear);
|
||||
out.put("fromDate", range[0].toString());
|
||||
out.put("toDate", range[1].toString());
|
||||
out.put("incomeGlCode", incomeGl.get("gl_code"));
|
||||
out.put("incomeGlName", incomeGl.get("name"));
|
||||
out.put("profitGlCode", profitGl.get("gl_code"));
|
||||
out.put("profitGlName", profitGl.get("name"));
|
||||
out.put("pendingAmount", pending);
|
||||
out.put("entryCount", entryCount);
|
||||
out.put("alreadyPosted", alreadyPosted);
|
||||
out.put("postedHistory", history);
|
||||
out.put("totalPostedToProfit", history.stream().map(h -> (BigDecimal) h.get("amount")).reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||
return Response.ok(gson.toJson(out)).build();
|
||||
}
|
||||
|
||||
// ══════════════════════════════════════════════════════════════════════
|
||||
// POST — close the income GL into Bank Profit
|
||||
// ══════════════════════════════════════════════════════════════════════
|
||||
@POST
|
||||
@Transactional
|
||||
public Response post(final String body) {
|
||||
|
||||
final AppUser currentUser = this.context.authenticatedUser();
|
||||
currentUser.validateHasPermissionTo("CREATE_JOURNALENTRY");
|
||||
|
||||
final JsonObject json = parseBody(body);
|
||||
final String incomeGlCode = getString(json, "incomeGlCode") == null ? IncomeProfitTransferService.DEFAULT_INCOME_GL_CODE
|
||||
: getString(json, "incomeGlCode").trim();
|
||||
final String financialYear = getString(json, "financialYear") == null ? service.currentFinancialYear()
|
||||
: getString(json, "financialYear").trim();
|
||||
|
||||
// strict = true: a manual posting reports "already closed" or "nothing to post" as an
|
||||
// error, so the user is told why nothing happened.
|
||||
final Map<String, Object> result = service.postToProfit(incomeGlCode, financialYear, currentUser.getId(), currentUser.getUsername(),
|
||||
sanitiseNote(getString(json, "note")), true);
|
||||
|
||||
return Response.ok(gson.toJson(result)).build();
|
||||
}
|
||||
|
||||
// ══════════════════════════════════════════════════════════════════════
|
||||
// POST /close-year — close the WHOLE P&L into Bank Profit
|
||||
// ══════════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Closes every income and expense GL for the year, so Bank Profit ends up holding the year's real net profit.
|
||||
*
|
||||
* This is the full year-end close; the endpoint above closes one named income GL and remains for the narrower
|
||||
* share-entry-fee case. The share dividend declaration reads Bank Profit as the year's profit, so it is this that
|
||||
* has to have run — after a single-GL posting the rest of the profit is still sitting in the income accounts.
|
||||
*/
|
||||
@POST
|
||||
@Path("/close-year")
|
||||
@Transactional
|
||||
public Response closeYear(final String body) {
|
||||
|
||||
final AppUser currentUser = this.context.authenticatedUser();
|
||||
currentUser.validateHasPermissionTo("CREATE_JOURNALENTRY");
|
||||
|
||||
final JsonObject json = parseBody(body);
|
||||
final String financialYear = getString(json, "financialYear") == null ? service.currentFinancialYear()
|
||||
: getString(json, "financialYear").trim();
|
||||
|
||||
// strict = true: a manual close reports "nothing left to close" as an error, so the user is
|
||||
// told why nothing happened rather than getting a silent success.
|
||||
final Map<String, Object> result = service.closeAllToProfit(financialYear, currentUser.getId(), currentUser.getUsername(),
|
||||
sanitiseNote(getString(json, "note")), true);
|
||||
|
||||
return Response.ok(gson.toJson(result)).build();
|
||||
}
|
||||
|
||||
// ══════════════════════════════════════════════════════════════════════
|
||||
// Helpers
|
||||
// ══════════════════════════════════════════════════════════════════════
|
||||
|
||||
private JsonObject parseBody(final String body) {
|
||||
if (body == null || body.isBlank()) {
|
||||
return new JsonObject();
|
||||
}
|
||||
try {
|
||||
return JsonParser.parseString(body).getAsJsonObject();
|
||||
} catch (RuntimeException e) {
|
||||
throw new PlatformDataIntegrityException("error.msg.incomeprofit.request.invalid", "Request body must be valid JSON.");
|
||||
}
|
||||
}
|
||||
|
||||
private String sanitiseNote(final String raw) {
|
||||
if (raw == null || raw.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
final String trimmed = raw.trim();
|
||||
return trimmed.length() > 490 ? trimmed.substring(0, 490) : trimmed;
|
||||
}
|
||||
|
||||
private String getString(final JsonObject json, final String field) {
|
||||
return json.has(field) && !json.get(field).isJsonNull() ? json.get(field).getAsString() : null;
|
||||
}
|
||||
|
||||
private Long toLong(final Object o) {
|
||||
return o instanceof Number ? ((Number) o).longValue() : null;
|
||||
}
|
||||
}
|
||||
-60
@@ -1,60 +0,0 @@
|
||||
/**
|
||||
* 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.yearend.jobs.postshareentryfeetoprofit;
|
||||
|
||||
import org.apache.fineract.accounting.yearend.service.IncomeProfitTransferService;
|
||||
import org.apache.fineract.infrastructure.jobs.service.JobName;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.job.builder.JobBuilder;
|
||||
import org.springframework.batch.core.launch.support.RunIdIncrementer;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.builder.StepBuilder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
@Configuration
|
||||
public class PostShareEntryFeeToProfitConfig {
|
||||
|
||||
@Autowired
|
||||
private JobRepository jobRepository;
|
||||
@Autowired
|
||||
private PlatformTransactionManager transactionManager;
|
||||
@Autowired
|
||||
private IncomeProfitTransferService incomeProfitTransferService;
|
||||
|
||||
@Bean
|
||||
protected Step postShareEntryFeeToProfitStep() {
|
||||
return new StepBuilder(JobName.POST_SHARE_ENTRY_FEE_TO_PROFIT.name(), jobRepository)
|
||||
.tasklet(postShareEntryFeeToProfitTasklet(), transactionManager).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job postShareEntryFeeToProfitJob() {
|
||||
return new JobBuilder(JobName.POST_SHARE_ENTRY_FEE_TO_PROFIT.name(), jobRepository).start(postShareEntryFeeToProfitStep())
|
||||
.incrementer(new RunIdIncrementer()).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PostShareEntryFeeToProfitTasklet postShareEntryFeeToProfitTasklet() {
|
||||
return new PostShareEntryFeeToProfitTasklet(incomeProfitTransferService);
|
||||
}
|
||||
}
|
||||
-61
@@ -1,61 +0,0 @@
|
||||
/**
|
||||
* 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.yearend.jobs.postshareentryfeetoprofit;
|
||||
|
||||
import java.util.Map;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.fineract.accounting.yearend.service.IncomeProfitTransferService;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
|
||||
/**
|
||||
* Year-end closing of the share entry fee: on 31 March the balance of Share Entry Fee Income is posted to the Bank
|
||||
* Profit equity GL, leaving the income account at nil for the new year.
|
||||
*
|
||||
* <p>
|
||||
* Runs unattended, so a no-op (already closed for the year, or no fee collected) is a normal outcome and is logged
|
||||
* rather than failing the job. Only a genuine posting failure is raised.
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class PostShareEntryFeeToProfitTasklet implements Tasklet {
|
||||
|
||||
/** Fineract's system user id, used because a scheduled run has no logged-in user. */
|
||||
private static final long SYSTEM_USER_ID = 1L;
|
||||
|
||||
private final IncomeProfitTransferService incomeProfitTransferService;
|
||||
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
|
||||
final String financialYear = incomeProfitTransferService.currentFinancialYear();
|
||||
|
||||
// Closes the WHOLE P&L, not just the share entry fee it was originally written for. Bank Profit
|
||||
// is now what the share dividend declaration reads as "the year's profit", and a partial close
|
||||
// would leave most of the profit still sitting in the income GLs — understating what may be
|
||||
// distributed. Per-GL guards inside closeAllToProfit make a re-run safe.
|
||||
final Map<String, Object> result = incomeProfitTransferService.closeAllToProfit(financialYear, SYSTEM_USER_ID, "system",
|
||||
"Automatic year-end closing", false);
|
||||
|
||||
log.info("Year-end closing for {}: {}", financialYear, result.get("message"));
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}
|
||||
-398
@@ -1,398 +0,0 @@
|
||||
package org.apache.fineract.accounting.yearend.service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.fineract.accounting.common.DividendGlAccountResolver;
|
||||
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.service.DateUtils;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Closes an income GL into the Bank Profit equity GL at financial year end.
|
||||
*
|
||||
* <pre>
|
||||
* Dr Share Entry Fee Income (10.4) = balance for the year
|
||||
* Cr Distributable Profit (the GL mapped to that financial activity)
|
||||
* </pre>
|
||||
*
|
||||
* Debiting the income account brings it back to nil so the new year starts clean; the credit accumulates in equity as
|
||||
* retained profit.
|
||||
*
|
||||
* <p>
|
||||
* Shared by the scheduled year-end job and the manual posting endpoint, so both paths post identical entries and are
|
||||
* protected by the same "once per year" guard. The caller supplies the acting user id because the job runs without a
|
||||
* logged-in user.
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class IncomeProfitTransferService {
|
||||
|
||||
// Fineract convention: 1 = CREDIT, 2 = DEBIT.
|
||||
private static final int DEBIT = 2;
|
||||
private static final int CREDIT = 1;
|
||||
|
||||
/** Income GL closed to profit by the year-end job — the share entry fee. */
|
||||
public static final String DEFAULT_INCOME_GL_CODE = "10.4";
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
/**
|
||||
* The year's profit is closed into the Distributable Profit account, not the Retained one.
|
||||
*
|
||||
* A dividend is declared against this balance; whatever the members do not receive moves across to Retained Profit
|
||||
* once the declaration is approved. Closing into Retained directly would mix the year just ended with earlier
|
||||
* years' leftovers, and the next declaration would be sized on profit that had already been through a distribution
|
||||
* decision — offering the same money for distribution twice.
|
||||
*
|
||||
* Both accounts are configured on Financial Activity Mappings; this was the hardcoded GL code BANKPROFITND01.
|
||||
*/
|
||||
private final DividendGlAccountResolver dividendGlAccounts;
|
||||
|
||||
/**
|
||||
* Posts the year-end transfer. Returns a summary of what was posted, or a summary with {@code posted = false} when
|
||||
* there was nothing to do (already closed, or a nil balance) — those are normal outcomes for a scheduled run, not
|
||||
* errors.
|
||||
*
|
||||
* @param strict
|
||||
* when true (manual posting) a no-op raises an error so the user sees why; when false (scheduled job) it
|
||||
* returns quietly.
|
||||
*/
|
||||
@Transactional
|
||||
public Map<String, Object> postToProfit(final String incomeGlCode, final String financialYear, final Long userId, final String userName,
|
||||
final String note, final boolean strict) {
|
||||
|
||||
final Map<String, Object> incomeGl = loadGlByCode(incomeGlCode);
|
||||
final Map<String, Object> profitGl = loadDistributableProfitGl();
|
||||
final Long incomeGlId = toLong(incomeGl.get("id"));
|
||||
final Long profitGlId = toLong(profitGl.get("id"));
|
||||
|
||||
final LocalDate[] range = financialYearRange(financialYear);
|
||||
final Long officeId = headOfficeId();
|
||||
|
||||
final Map<String, Object> out = new LinkedHashMap<>();
|
||||
out.put("financialYear", financialYear);
|
||||
out.put("incomeGlCode", incomeGl.get("gl_code"));
|
||||
out.put("incomeGlName", incomeGl.get("name"));
|
||||
out.put("profitGlCode", profitGl.get("gl_code"));
|
||||
out.put("profitGlName", profitGl.get("name"));
|
||||
|
||||
final Integer existing = jdbcTemplate.queryForObject(
|
||||
"SELECT COUNT(*) FROM m_income_profit_transfer WHERE financial_year = ? AND income_gl_id = ? AND office_id = ?",
|
||||
Integer.class, financialYear, incomeGlId, officeId);
|
||||
if (existing != null && existing > 0) {
|
||||
if (strict) {
|
||||
throw new PlatformDataIntegrityException("error.msg.incomeprofit.already.posted",
|
||||
incomeGl.get("name") + " has already been closed to profit for " + financialYear + ".");
|
||||
}
|
||||
out.put("posted", false);
|
||||
out.put("reason", "Already closed for " + financialYear);
|
||||
return out;
|
||||
}
|
||||
|
||||
final BigDecimal balance = balanceOf(incomeGlId, range);
|
||||
if (balance.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
if (strict) {
|
||||
throw new PlatformDataIntegrityException("error.msg.incomeprofit.nothing.to.post",
|
||||
"There is no income in " + incomeGl.get("name") + " to close for " + financialYear + ".");
|
||||
}
|
||||
out.put("posted", false);
|
||||
out.put("reason", "No income to close for " + financialYear);
|
||||
return out;
|
||||
}
|
||||
|
||||
final int entryCount = entryCountOf(incomeGlId, range);
|
||||
final String currencyCode = resolveCurrency(incomeGlId);
|
||||
final LocalDateTime now = LocalDateTime.now(DateUtils.getDateTimeZoneOfTenant());
|
||||
final LocalDate postingDate = range[1];
|
||||
final String txnId = LedgerTransactionId.next(this.jdbcTemplate, LedgerTxnPrefix.YEAR_END_PROFIT);
|
||||
final String desc = "Year-end closing " + financialYear + " — " + incomeGl.get("name") + " to profit"
|
||||
+ (note != null ? " | " + note : "");
|
||||
|
||||
insertEntry(officeId, incomeGlId, DEBIT, balance, txnId, postingDate, userId, now, currencyCode, desc);
|
||||
insertEntry(officeId, profitGlId, CREDIT, balance, txnId, postingDate, userId, now, currencyCode,
|
||||
"Profit for " + financialYear + " from " + incomeGl.get("name"));
|
||||
|
||||
jdbcTemplate.update(
|
||||
"INSERT INTO m_income_profit_transfer "
|
||||
+ "(financial_year, income_gl_id, profit_gl_id, office_id, from_date, to_date, amount, entry_count, "
|
||||
+ " currency_code, gl_transaction_id, posted_on_date, posted_by_user, posted_by_name, note) "
|
||||
+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
|
||||
financialYear, incomeGlId, profitGlId, officeId, java.sql.Date.valueOf(range[0]), java.sql.Date.valueOf(range[1]), balance,
|
||||
entryCount, currencyCode, txnId, java.sql.Date.valueOf(postingDate), userId, userName, note);
|
||||
|
||||
log.info("Year-end profit posting: {} {} from {} to {} for {}", balance, currencyCode, incomeGl.get("name"), profitGl.get("name"),
|
||||
financialYear);
|
||||
|
||||
out.put("posted", true);
|
||||
out.put("amountPostedToProfit", balance);
|
||||
out.put("entryCount", entryCount);
|
||||
out.put("postedOnDate", postingDate.toString());
|
||||
out.put("glTransactionId", txnId);
|
||||
out.put("currency", currencyCode);
|
||||
out.put("message", balance + " " + currencyCode + " posted to " + profitGl.get("name") + " for " + financialYear + ".");
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes EVERY income and expense GL into Bank Profit for the year, leaving the equity GL holding the year's real
|
||||
* net profit.
|
||||
*
|
||||
* <pre>
|
||||
* each income GL: Dr Income GL Cr Bank Profit (income raises profit)
|
||||
* each expense GL: Dr Bank Profit Cr Expense GL (expense reduces profit)
|
||||
* </pre>
|
||||
*
|
||||
* {@link #postToProfit} closes one named income GL and is what the legacy share-entry-fee job calls; this closes
|
||||
* the whole P&L, which is what an actual year-end close is. Anything reading Bank Profit as "the year's profit" —
|
||||
* the share dividend declaration in particular — depends on this having run, because a partial close leaves the
|
||||
* profit split across two places and understates it.
|
||||
*
|
||||
* Each GL still gets its own m_income_profit_transfer row, so the same "once per year per GL" guard applies: a
|
||||
* re-run after new GL accounts appear closes only the ones not yet closed, and never double-posts one that was.
|
||||
* Accounts with a nil balance are skipped rather than posted as zero entries.
|
||||
*/
|
||||
@Transactional
|
||||
public Map<String, Object> closeAllToProfit(final String financialYear, final Long userId, final String userName, final String note,
|
||||
final boolean strict) {
|
||||
|
||||
final Map<String, Object> profitGl = loadDistributableProfitGl();
|
||||
final Long profitGlId = toLong(profitGl.get("id"));
|
||||
final LocalDate[] range = financialYearRange(financialYear);
|
||||
final Long officeId = headOfficeId();
|
||||
|
||||
// 4 = INCOME, 5 = EXPENSE (GLAccountType). Disabled accounts are excluded: they can hold a
|
||||
// historical balance but must not attract new postings.
|
||||
final List<Map<String, Object>> plAccounts = jdbcTemplate.queryForList(
|
||||
"SELECT id, gl_code, name, classification_enum FROM acc_gl_account "
|
||||
+ " WHERE classification_enum IN (4, 5) AND disabled = false ORDER BY classification_enum, gl_code");
|
||||
|
||||
final List<Map<String, Object>> closed = new ArrayList<>();
|
||||
final List<Map<String, Object>> skipped = new ArrayList<>();
|
||||
BigDecimal totalIncome = BigDecimal.ZERO;
|
||||
BigDecimal totalExpense = BigDecimal.ZERO;
|
||||
|
||||
for (final Map<String, Object> gl : plAccounts) {
|
||||
final Long glId = toLong(gl.get("id"));
|
||||
final boolean isIncome = ((Number) gl.get("classification_enum")).intValue() == 4;
|
||||
|
||||
final Integer existing = jdbcTemplate.queryForObject(
|
||||
"SELECT COUNT(*) FROM m_income_profit_transfer WHERE financial_year = ? AND income_gl_id = ? AND office_id = ?",
|
||||
Integer.class, financialYear, glId, officeId);
|
||||
if (existing != null && existing > 0) {
|
||||
skipped.add(skipRow(gl, "Already closed for " + financialYear));
|
||||
continue;
|
||||
}
|
||||
|
||||
// balanceOf returns credit-less-debit. For an income GL that is the income earned; for an
|
||||
// expense GL the natural balance is a debit, so the same figure comes back negative and
|
||||
// is flipped here to read as a positive expense.
|
||||
final BigDecimal rawBalance = balanceOf(glId, range);
|
||||
final BigDecimal balance = isIncome ? rawBalance : rawBalance.negate();
|
||||
if (balance.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
skipped.add(skipRow(gl, "Nothing to close for " + financialYear));
|
||||
continue;
|
||||
}
|
||||
|
||||
final int entryCount = entryCountOf(glId, range);
|
||||
final String currencyCode = resolveCurrency(glId);
|
||||
final LocalDateTime now = LocalDateTime.now(DateUtils.getDateTimeZoneOfTenant());
|
||||
final LocalDate postingDate = range[1];
|
||||
final String txnId = LedgerTransactionId.next(this.jdbcTemplate, LedgerTxnPrefix.YEAR_END_CLOSE);
|
||||
final String descr = "Year-end closing " + financialYear + " — " + gl.get("name") + " to profit"
|
||||
+ (note != null ? " | " + note : "");
|
||||
|
||||
if (isIncome) {
|
||||
insertEntry(officeId, glId, DEBIT, balance, txnId, postingDate, userId, now, currencyCode, descr);
|
||||
insertEntry(officeId, profitGlId, CREDIT, balance, txnId, postingDate, userId, now, currencyCode,
|
||||
"Profit for " + financialYear + " from " + gl.get("name"));
|
||||
totalIncome = totalIncome.add(balance);
|
||||
} else {
|
||||
insertEntry(officeId, glId, CREDIT, balance, txnId, postingDate, userId, now, currencyCode, descr);
|
||||
insertEntry(officeId, profitGlId, DEBIT, balance, txnId, postingDate, userId, now, currencyCode,
|
||||
"Expense for " + financialYear + " from " + gl.get("name"));
|
||||
totalExpense = totalExpense.add(balance);
|
||||
}
|
||||
|
||||
jdbcTemplate.update("INSERT INTO m_income_profit_transfer "
|
||||
+ "(financial_year, income_gl_id, profit_gl_id, office_id, from_date, to_date, amount, entry_count, "
|
||||
+ " currency_code, gl_transaction_id, posted_on_date, posted_by_user, posted_by_name, note) "
|
||||
+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)", financialYear, glId, profitGlId, officeId,
|
||||
java.sql.Date.valueOf(range[0]), java.sql.Date.valueOf(range[1]), balance, entryCount, currencyCode, txnId,
|
||||
java.sql.Date.valueOf(postingDate), userId, userName, note);
|
||||
|
||||
final Map<String, Object> row = new LinkedHashMap<>();
|
||||
row.put("glCode", gl.get("gl_code"));
|
||||
row.put("glName", gl.get("name"));
|
||||
row.put("type", isIncome ? "INCOME" : "EXPENSE");
|
||||
row.put("amount", balance);
|
||||
row.put("entryCount", entryCount);
|
||||
row.put("glTransactionId", txnId);
|
||||
closed.add(row);
|
||||
}
|
||||
|
||||
if (closed.isEmpty() && strict) {
|
||||
throw new PlatformDataIntegrityException("error.msg.incomeprofit.nothing.to.close",
|
||||
"There is nothing left to close to profit for " + financialYear + ".");
|
||||
}
|
||||
|
||||
final BigDecimal netProfit = totalIncome.subtract(totalExpense);
|
||||
log.info("Year-end close {}: income {}, expense {}, net profit {} posted to {}", financialYear, totalIncome, totalExpense,
|
||||
netProfit, profitGl.get("name"));
|
||||
|
||||
final Map<String, Object> out = new LinkedHashMap<>();
|
||||
out.put("financialYear", financialYear);
|
||||
out.put("fromDate", range[0].toString());
|
||||
out.put("toDate", range[1].toString());
|
||||
out.put("profitGlCode", profitGl.get("gl_code"));
|
||||
out.put("profitGlName", profitGl.get("name"));
|
||||
out.put("totalIncomeClosed", totalIncome);
|
||||
out.put("totalExpenseClosed", totalExpense);
|
||||
out.put("netProfitPosted", netProfit);
|
||||
out.put("accountsClosed", closed);
|
||||
out.put("accountsSkipped", skipped);
|
||||
out.put("message", closed.size() + " account(s) closed to " + profitGl.get("name") + " for " + financialYear + "; net profit "
|
||||
+ netProfit + ".");
|
||||
return out;
|
||||
}
|
||||
|
||||
private Map<String, Object> skipRow(final Map<String, Object> gl, final String reason) {
|
||||
final Map<String, Object> row = new LinkedHashMap<>();
|
||||
row.put("glCode", gl.get("gl_code"));
|
||||
row.put("glName", gl.get("name"));
|
||||
row.put("reason", reason);
|
||||
return row;
|
||||
}
|
||||
|
||||
/**
|
||||
* The year's profit as it stands in the Bank Profit equity GL — what a dividend may be declared out of once the
|
||||
* year has been closed.
|
||||
*
|
||||
* Only entries dated inside the financial year count, so each year's profit is separable rather than being one
|
||||
* ever-growing equity balance. Returns zero (not an error) when the year has not been closed yet; callers decide
|
||||
* whether that is a blocking condition.
|
||||
*/
|
||||
public BigDecimal profitForFinancialYear(final String financialYear) {
|
||||
final LocalDate[] range = financialYearRange(financialYear);
|
||||
final Map<String, Object> profitGl = loadDistributableProfitGl();
|
||||
final BigDecimal balance = jdbcTemplate.queryForObject(
|
||||
"SELECT COALESCE(SUM(CASE WHEN type_enum = ? THEN amount ELSE -amount END), 0) "
|
||||
+ " FROM acc_gl_journal_entry WHERE account_id = ? AND reversed = false AND entry_date BETWEEN ? AND ?",
|
||||
BigDecimal.class, CREDIT, toLong(profitGl.get("id")), java.sql.Date.valueOf(range[0]), java.sql.Date.valueOf(range[1]));
|
||||
return balance == null ? BigDecimal.ZERO : balance;
|
||||
}
|
||||
|
||||
/** Whether the year's P&L has been closed into Bank Profit at all. */
|
||||
public boolean isYearClosed(final String financialYear) {
|
||||
final Integer count = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM m_income_profit_transfer WHERE financial_year = ?",
|
||||
Integer.class, financialYear);
|
||||
return count != null && count > 0;
|
||||
}
|
||||
|
||||
/** Net credit balance sitting in the income GL for the year. */
|
||||
public BigDecimal balanceOf(final Long incomeGlId, final LocalDate[] range) {
|
||||
final BigDecimal balance = jdbcTemplate.queryForObject(
|
||||
"SELECT COALESCE(SUM(CASE WHEN type_enum = ? THEN amount ELSE -amount END), 0) "
|
||||
+ " FROM acc_gl_journal_entry WHERE account_id = ? AND reversed = false " + " AND entry_date BETWEEN ? AND ?",
|
||||
BigDecimal.class, CREDIT, incomeGlId, java.sql.Date.valueOf(range[0]), java.sql.Date.valueOf(range[1]));
|
||||
return balance == null ? BigDecimal.ZERO : balance;
|
||||
}
|
||||
|
||||
/** How many fee postings made up that balance. */
|
||||
public int entryCountOf(final Long incomeGlId, final LocalDate[] range) {
|
||||
final Integer count = jdbcTemplate.queryForObject(
|
||||
"SELECT COUNT(*) FROM acc_gl_journal_entry WHERE account_id = ? AND reversed = false "
|
||||
+ " AND type_enum = ? AND entry_date BETWEEN ? AND ?",
|
||||
Integer.class, incomeGlId, CREDIT, java.sql.Date.valueOf(range[0]), java.sql.Date.valueOf(range[1]));
|
||||
return count == null ? 0 : count;
|
||||
}
|
||||
|
||||
/** Indian financial year label for today, e.g. "2026-27" for 19 Aug 2026. */
|
||||
public String currentFinancialYear() {
|
||||
final LocalDate today = DateUtils.getBusinessLocalDate();
|
||||
final int startYear = today.getMonthValue() >= 4 ? today.getYear() : today.getYear() - 1;
|
||||
return startYear + "-" + String.format("%02d", (startYear + 1) % 100);
|
||||
}
|
||||
|
||||
/** 1 April to 31 March for a "YYYY-YY" label. */
|
||||
public LocalDate[] financialYearRange(final String financialYear) {
|
||||
try {
|
||||
final int startYear = Integer.parseInt(financialYear.substring(0, 4));
|
||||
return new LocalDate[] { LocalDate.of(startYear, 4, 1), LocalDate.of(startYear + 1, 3, 31) };
|
||||
} catch (RuntimeException e) {
|
||||
throw new PlatformDataIntegrityException("error.msg.incomeprofit.year.invalid",
|
||||
"financialYear must look like 2026-27. Received: " + financialYear);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, Object> loadGlByCode(final String glCode) {
|
||||
try {
|
||||
return jdbcTemplate.queryForMap("SELECT id, gl_code, name, classification_enum FROM acc_gl_account WHERE gl_code = ?", glCode);
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
throw new PlatformDataIntegrityException("error.msg.incomeprofit.gl.not.found", "GL account " + glCode + " does not exist.");
|
||||
}
|
||||
}
|
||||
|
||||
/** As {@link #loadGlByCode}, for an account already identified by a financial activity mapping. */
|
||||
public Map<String, Object> loadGlById(final Long glAccountId) {
|
||||
try {
|
||||
return jdbcTemplate.queryForMap("SELECT id, gl_code, name, classification_enum FROM acc_gl_account WHERE id = ?", glAccountId);
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
throw new PlatformDataIntegrityException("error.msg.incomeprofit.gl.not.found",
|
||||
"GL account " + glAccountId + " does not exist.");
|
||||
}
|
||||
}
|
||||
|
||||
/** The distributable-profit GL the year's income closes into, as configured on Financial Activity Mappings. */
|
||||
public Map<String, Object> loadDistributableProfitGl() {
|
||||
return loadGlById(this.dividendGlAccounts.distributableProfitAccount());
|
||||
}
|
||||
|
||||
public Long headOfficeId() {
|
||||
return jdbcTemplate.queryForObject("SELECT id FROM m_office ORDER BY hierarchy LIMIT 1", Long.class);
|
||||
}
|
||||
|
||||
private String resolveCurrency(final Long glAccountId) {
|
||||
try {
|
||||
final String code = jdbcTemplate.queryForObject(
|
||||
"SELECT currency_code FROM acc_gl_journal_entry WHERE account_id = ? ORDER BY id DESC LIMIT 1", String.class,
|
||||
glAccountId);
|
||||
return code == null ? "INR" : code;
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
return "INR";
|
||||
}
|
||||
}
|
||||
|
||||
private void insertEntry(final Long officeId, final Long glAccountId, final int typeEnum, final BigDecimal amount, final String txnId,
|
||||
final LocalDate entryDate, final Long userId, final LocalDateTime now, final String currencyCode, final String description) {
|
||||
GLAccountTransactionGuard.assertPostable(jdbcTemplate, glAccountId);
|
||||
jdbcTemplate.update(
|
||||
"INSERT INTO acc_gl_journal_entry " + "(account_id, office_id, currency_code, transaction_id, reversed, manual_entry, "
|
||||
+ " entry_date, type_enum, amount, description, "
|
||||
+ " created_by, last_modified_by, created_date, lastmodified_date, "
|
||||
+ " is_running_balance_calculated, office_running_balance, "
|
||||
+ " organization_running_balance, submitted_on_date, transaction_date, " + " created_on_utc, last_modified_on_utc) "
|
||||
+ "VALUES (?,?,?,?,false,true,?,?,?,?,?,?,?,?,false,0,0,?,?,?,?)",
|
||||
glAccountId, officeId, currencyCode, txnId, java.sql.Date.valueOf(entryDate), typeEnum, amount, description, userId, userId,
|
||||
now, now, java.sql.Date.valueOf(entryDate), java.sql.Date.valueOf(entryDate), now.atOffset(ZoneOffset.UTC),
|
||||
now.atOffset(ZoneOffset.UTC));
|
||||
}
|
||||
|
||||
private Long toLong(final Object o) {
|
||||
return o instanceof Number ? ((Number) o).longValue() : null;
|
||||
}
|
||||
}
|
||||
-52
@@ -1,52 +0,0 @@
|
||||
/**
|
||||
* 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.infrastructure.businessdate.jobs.syncbusinessdate;
|
||||
|
||||
import org.apache.fineract.infrastructure.jobs.service.JobName;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.job.builder.JobBuilder;
|
||||
import org.springframework.batch.core.launch.support.RunIdIncrementer;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.builder.StepBuilder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
@Configuration
|
||||
public class SyncBusinessDateConfig {
|
||||
|
||||
@Autowired
|
||||
private JobRepository jobRepository;
|
||||
@Autowired
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
@Bean
|
||||
protected Step syncBusinessDateStep(final SyncBusinessDateTasklet syncBusinessDateTasklet) {
|
||||
return new StepBuilder(JobName.SYNC_BUSINESS_DATE_TO_SYSTEM_DATE.name(), jobRepository)
|
||||
.tasklet(syncBusinessDateTasklet, transactionManager).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job syncBusinessDateJob(final SyncBusinessDateTasklet syncBusinessDateTasklet) {
|
||||
return new JobBuilder(JobName.SYNC_BUSINESS_DATE_TO_SYSTEM_DATE.name(), jobRepository)
|
||||
.start(syncBusinessDateStep(syncBusinessDateTasklet)).incrementer(new RunIdIncrementer()).build();
|
||||
}
|
||||
}
|
||||
-88
@@ -1,88 +0,0 @@
|
||||
/**
|
||||
* 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.infrastructure.businessdate.jobs.syncbusinessdate;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.fineract.infrastructure.businessdate.data.service.BusinessDateDTO;
|
||||
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
|
||||
import org.apache.fineract.infrastructure.businessdate.service.BusinessDateWritePlatformService;
|
||||
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
|
||||
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Sets the business date to the tenant's own calendar date, every midnight.
|
||||
*
|
||||
* <p>
|
||||
* Fineract's stock job adds one day to whatever the business date already holds. That is only the
|
||||
* same thing as "today" while the scheduler has never missed a night: a server stopped over a
|
||||
* weekend, a laptop that was closed, a tenant restored from an older backup, and the date is left
|
||||
* behind by however many runs did not happen. It then stays behind, because adding a day to a stale
|
||||
* date gives another stale date, and each night's run preserves the gap rather than closing it.
|
||||
*
|
||||
* <p>
|
||||
* Drift is not a cosmetic problem. Every transaction is stamped with the business date, so while it
|
||||
* lags: a Demand Draft raised today is rejected as being dated in the future, the day's savings
|
||||
* interest never accrues and a closure pays out short, and staff see yesterday's date on work they
|
||||
* are doing now.
|
||||
*
|
||||
* <p>
|
||||
* Reading the clock instead of incrementing is self-correcting: however many days were missed, the
|
||||
* next run lands on today. Bringing the date forward is all this does — a date deliberately set
|
||||
* ahead, which is how testing against a future day works, is left alone rather than pulled back
|
||||
* under someone's feet.
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Component
|
||||
public class SyncBusinessDateTasklet implements Tasklet {
|
||||
|
||||
private final BusinessDateWritePlatformService businessDateWritePlatformService;
|
||||
private final ConfigurationDomainService configurationDomainService;
|
||||
|
||||
@Override
|
||||
public RepeatStatus execute(final StepContribution contribution, final ChunkContext chunkContext) {
|
||||
if (!configurationDomainService.isBusinessDateEnabled()) {
|
||||
// Without the setting on, the platform reads the clock directly and m_business_date is
|
||||
// not consulted — writing to it would be busywork that misleads anyone reading the table.
|
||||
log.debug("Business date is not enabled; nothing to sync.");
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
|
||||
final LocalDate systemDate = DateUtils.getLocalDateOfTenant();
|
||||
final LocalDate businessDate = DateUtils.getBusinessLocalDate();
|
||||
|
||||
if (!businessDate.isBefore(systemDate)) {
|
||||
log.debug("Business date {} is already at or ahead of the system date {}; leaving it alone.", businessDate, systemDate);
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
|
||||
businessDateWritePlatformService.updateBusinessDate(BusinessDateDTO.builder().type(BusinessDateType.BUSINESS_DATE)
|
||||
.description(BusinessDateType.BUSINESS_DATE.getDescription()).date(systemDate).build());
|
||||
|
||||
log.info("Business date moved from {} to the system date {}.", businessDate, systemDate);
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}
|
||||
-5
@@ -61,11 +61,6 @@ public class ConfigurationDomainServiceJpa implements ConfigurationDomainService
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMakerCheckerEnabled() {
|
||||
return getGlobalConfigurationPropertyData(GlobalConfigurationConstants.MAKER_CHECKER).isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAllowedLoanStatusesForExternalAssetTransfer() {
|
||||
final GlobalConfigurationPropertyData property = getGlobalConfigurationPropertyData(
|
||||
|
||||
+1
-27
@@ -33,7 +33,6 @@ import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDoma
|
||||
import org.apache.fineract.infrastructure.core.domain.FineractRequestContextHolder;
|
||||
import org.apache.fineract.infrastructure.core.filters.CallerIpTrackingFilter;
|
||||
import org.apache.fineract.infrastructure.core.filters.CorrelationHeaderFilter;
|
||||
import org.apache.fineract.infrastructure.core.filters.DisabledFeatureApiFilter;
|
||||
import org.apache.fineract.infrastructure.core.filters.IdempotencyStoreFilter;
|
||||
import org.apache.fineract.infrastructure.core.filters.IdempotencyStoreHelper;
|
||||
import org.apache.fineract.infrastructure.core.filters.RequestResponseFilter;
|
||||
@@ -164,24 +163,6 @@ public class SecurityConfig {
|
||||
// packages here without a Fineract Bearer token; security is enforced by the
|
||||
// envelope's RSA signature/encryption (NpciCryptoUtil) inside the handler.
|
||||
.requestMatchers(API_MATCHER.matcher(HttpMethod.POST, "/api/*/npci/**")).permitAll()
|
||||
// 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
|
||||
// POST /v1/apiclients, super-user only). Same posture as IMPS/NPCI above: the
|
||||
// outer gate stays open for this one narrow GET path, and
|
||||
// ClientAllAccountsApiResource#retrieveByClientNo is what actually authenticates
|
||||
// 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,
|
||||
// it just fails inside the handler instead of at this filter.
|
||||
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/clientaccounts/**")).permitAll()
|
||||
// Tenant menu access — same dual-mode X-Api-Key posture as clientaccounts above
|
||||
// for the two GETs (TenantMenuAccessApiResource#read still requires an ordinary
|
||||
// session when no key is sent, same as ClientAllAccountsApiResource does; permitAll
|
||||
// here only opens Spring Security's outer gate for the key path, it does not skip
|
||||
// the handler's own check). The PUT has no session fallback inside the handler at
|
||||
// all, even for a logged-in super user — see TenantMenuAccessApiResource#save.
|
||||
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/tenant-menu-access")).permitAll()
|
||||
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/tenant-menu-access/tenants")).permitAll()
|
||||
.requestMatchers(API_MATCHER.matcher(HttpMethod.PUT, "/api/*/tenant-menu-access")).permitAll()
|
||||
// Login OTP — same posture as PAN/GSTIN public verification: provider-credentialed,
|
||||
// no Fineract auth required.
|
||||
.requestMatchers(API_MATCHER.matcher(HttpMethod.POST, "/api/*/login/otp/generate")).permitAll()
|
||||
@@ -427,10 +408,7 @@ public class SecurityConfig {
|
||||
.addFilterBefore(tenantAwareBasicAuthenticationFilter(), SecurityContextHolderFilter.class)
|
||||
.addFilterAfter(requestResponseFilter(), ExceptionTranslationFilter.class)
|
||||
.addFilterAfter(correlationHeaderFilter(), RequestResponseFilter.class)
|
||||
.addFilterAfter(fineractInstanceModeApiFilter(), CorrelationHeaderFilter.class)
|
||||
// Refuses the handful of accounting features switched off for this installation.
|
||||
// Nothing is deleted - see DisabledFeatureApiFilter for what is blocked and why.
|
||||
.addFilterAfter(disabledFeatureApiFilter(), FineractInstanceModeApiFilter.class);
|
||||
.addFilterAfter(fineractInstanceModeApiFilter(), CorrelationHeaderFilter.class);
|
||||
|
||||
if (loanCOBFilterHelper != null) {
|
||||
http.addFilterAfter(loanCOBApiFilter(), FineractInstanceModeApiFilter.class).addFilterAfter(idempotencyStoreFilter(),
|
||||
@@ -467,10 +445,6 @@ public class SecurityConfig {
|
||||
return new RequestResponseFilter();
|
||||
}
|
||||
|
||||
public DisabledFeatureApiFilter disabledFeatureApiFilter() {
|
||||
return new DisabledFeatureApiFilter();
|
||||
}
|
||||
|
||||
public LoanCOBApiFilter loanCOBApiFilter() {
|
||||
return new LoanCOBApiFilter(loanCOBFilterHelper);
|
||||
}
|
||||
|
||||
-128
@@ -1,128 +0,0 @@
|
||||
/**
|
||||
* 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.infrastructure.core.filters;
|
||||
|
||||
import jakarta.servlet.FilterChain;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
|
||||
/**
|
||||
* Turns off a handful of accounting features at the HTTP edge, without deleting any of the code
|
||||
* behind them: the resources, services and command handlers all stay exactly as they are, and only
|
||||
* an inbound API call is refused. Re-enabling a feature is deleting its rule from RULES below.
|
||||
*
|
||||
* Blocking here rather than inside the resources matters for one specific reason: several internal
|
||||
* flows raise journal entries through CommandWrapperBuilder().createJournalEntry() in Java
|
||||
* (ClerkDisbursementRequestApiResource's GL offsets, clerk closure rounding, bank transfers). Those
|
||||
* never travel over HTTP, so they keep working, while the "Create Journal Entries" screen and any
|
||||
* direct call to the endpoint are refused.
|
||||
*
|
||||
* A rule carries an optional set of allowed "command" query parameter values, because
|
||||
* POST /v1/journalentries is three different features behind one path: no command is the manual
|
||||
* journal entry screen (blocked), command=defineOpeningBalance is Migrate Opening Balances and
|
||||
* command=updateRunningBalance is the running-balance maintenance job (both still needed).
|
||||
*/
|
||||
public class DisabledFeatureApiFilter extends OncePerRequestFilter {
|
||||
|
||||
private record Rule(String feature, Set<String> methods, Pattern path, Set<String> allowedCommands) {
|
||||
|
||||
boolean matches(final String method, final String pathInfo, final String command) {
|
||||
if (!methods.isEmpty() && !methods.contains(method)) {
|
||||
return false;
|
||||
}
|
||||
if (!path.matcher(pathInfo).matches()) {
|
||||
return false;
|
||||
}
|
||||
// A command this rule explicitly spares (a different feature sharing the same path).
|
||||
return !(command != null && allowedCommands.contains(command));
|
||||
}
|
||||
}
|
||||
|
||||
private static final List<Rule> RULES = List.of(
|
||||
// Create Journal Entries, and Frequent Postings which posts through the same endpoint.
|
||||
new Rule("Create Journal Entries", Set.of("POST"), Pattern.compile("/v[1-9][0-9]*/journalentries/?"),
|
||||
Set.of("defineOpeningBalance", "updateRunningBalance")),
|
||||
// Closing Entries.
|
||||
new Rule("Closing Entries", Set.of(), Pattern.compile("/v[1-9][0-9]*/glclosures(/.*)?"), Set.of()),
|
||||
// Accruals.
|
||||
new Rule("Accruals", Set.of(), Pattern.compile("/v[1-9][0-9]*/runaccruals(/.*)?"), Set.of()),
|
||||
// Provisioning Entries, including the journal entries screen that belongs to it.
|
||||
new Rule("Provisioning Entries", Set.of(), Pattern.compile("/v[1-9][0-9]*/provisioningentries(/.*)?"), Set.of()),
|
||||
new Rule("Provisioning Entries", Set.of(), Pattern.compile("/v[1-9][0-9]*/journalentries/provisioning/?"), Set.of()),
|
||||
// Accounting Rules. Only the Accounting Rules screens and Frequent Postings (disabled
|
||||
// above) read these, so nothing still reachable depends on them.
|
||||
new Rule("Accounting Rules", Set.of(), Pattern.compile("/v[1-9][0-9]*/accountingrules(/.*)?"), Set.of()));
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain)
|
||||
throws ServletException, IOException {
|
||||
|
||||
final String pathInfo = request.getPathInfo();
|
||||
if (StringUtils.isBlank(pathInfo)) {
|
||||
filterChain.doFilter(request, response);
|
||||
return;
|
||||
}
|
||||
|
||||
final String method = request.getMethod();
|
||||
// Read "command" out of the query string rather than through getParameter(): the latter
|
||||
// triggers servlet parameter parsing, which for a form-encoded or multipart POST consumes
|
||||
// the request body before the resource ever sees it. This filter sits in front of every
|
||||
// API call, so it must not touch the body of requests it has no interest in.
|
||||
final String command = commandFromQueryString(request.getQueryString());
|
||||
for (final Rule rule : RULES) {
|
||||
if (rule.matches(method, pathInfo, command)) {
|
||||
reject(response, rule.feature());
|
||||
return;
|
||||
}
|
||||
}
|
||||
filterChain.doFilter(request, response);
|
||||
}
|
||||
|
||||
private String commandFromQueryString(final String queryString) {
|
||||
if (StringUtils.isBlank(queryString)) {
|
||||
return null;
|
||||
}
|
||||
for (final String pair : queryString.split("&")) {
|
||||
if (pair.startsWith("command=")) {
|
||||
return URLDecoder.decode(pair.substring("command=".length()), StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void reject(final HttpServletResponse response, final String feature) throws IOException {
|
||||
response.setStatus(HttpStatus.SC_FORBIDDEN);
|
||||
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||
response.getWriter()
|
||||
.write("{\"developerMessage\":\"" + feature + " is disabled on this installation.\","
|
||||
+ "\"httpStatusCode\":\"403\",\"defaultUserMessage\":\"" + feature + " is not available.\","
|
||||
+ "\"userMessageGlobalisationCode\":\"error.msg.feature.disabled\"}");
|
||||
}
|
||||
}
|
||||
-17
@@ -66,23 +66,6 @@ public class JobSchedulerServiceImpl implements ApplicationListener<ContextRefre
|
||||
final List<ScheduledJobDetail> scheduledJobDetails = schedularWritePlatformService
|
||||
.retrieveAllJobs(fineractProperties.getNodeId());
|
||||
for (final ScheduledJobDetail jobDetails : scheduledJobDetails) {
|
||||
// Release any currently_running flag left over from before this boot.
|
||||
//
|
||||
// The flag is set in the scheduler's veto check before a job's body runs and cleared
|
||||
// by the Quartz listener when it returns. Two things leave it set with nothing
|
||||
// running: a JVM that stopped mid-run, and a job started through its own API rather
|
||||
// than through Quartz — no listener is involved there, so nothing ever clears it.
|
||||
//
|
||||
// Once set, the veto silently drops every later trigger: no run-history row, no
|
||||
// error, nothing in the log. The job reads as though it ran and did nothing, and one
|
||||
// dead run mutes it for good. That is how a night of unpaid savings interest goes
|
||||
// unnoticed.
|
||||
//
|
||||
// This loop is the platform coming up, so by definition none of these jobs is
|
||||
// running: whatever the flag says, it is stale. scheduleJob() below already clears
|
||||
// it on the paths it reaches, but not when it throws before that line, and the
|
||||
// saveOrUpdate() after this loop persists whatever we set here either way.
|
||||
jobDetails.setCurrentlyRunning(false);
|
||||
try {
|
||||
jobRegisterService.scheduleJob(jobDetails);
|
||||
} catch (JobIsNotFoundOrNotEnabledException e) {
|
||||
|
||||
-109
@@ -1,109 +0,0 @@
|
||||
/**
|
||||
* 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.infrastructure.security.apiclient;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.DELETE;
|
||||
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.WebApplicationException;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* username/password, restricted to a super user (ALL_FUNCTIONS). Only the endpoints that use a minted
|
||||
* 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.
|
||||
*/
|
||||
@Path("/v1/apiclients")
|
||||
@Component
|
||||
@Tag(name = "API Client Keys", description = "Admin management of third-party API keys used by endpoints that skip Fineract login.")
|
||||
@RequiredArgsConstructor
|
||||
public class ApiClientAdminApiResource {
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final ApiClientCredentialService credentialService;
|
||||
private final FromJsonHelper fromJsonHelper;
|
||||
private final Gson gson = new GsonBuilder().serializeNulls().create();
|
||||
|
||||
@POST
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String create(final String body) {
|
||||
final AppUser user = requireSuperUser();
|
||||
final JsonElement root = fromJsonHelper.parse(body);
|
||||
final String clientName = fromJsonHelper.extractStringNamed("clientName", root);
|
||||
final String allowedIps = fromJsonHelper.extractStringNamed("allowedIps", root);
|
||||
|
||||
final Map<String, Object> result = credentialService.createClient(clientName, allowedIps, user.getId());
|
||||
return gson.toJson(result);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String list() {
|
||||
requireSuperUser();
|
||||
final List<Map<String, Object>> clients = credentialService.listClients();
|
||||
return gson.toJson(clients);
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/{id}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String deactivate(@PathParam("id") final Long id) {
|
||||
requireSuperUser();
|
||||
credentialService.setActive(id, false);
|
||||
return gson.toJson(Map.of("resourceId", id, "isActive", false));
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/{id}/reactivate")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String reactivate(@PathParam("id") final Long id) {
|
||||
requireSuperUser();
|
||||
credentialService.setActive(id, true);
|
||||
return gson.toJson(Map.of("resourceId", id, "isActive", true));
|
||||
}
|
||||
|
||||
private AppUser requireSuperUser() {
|
||||
final AppUser user = context.authenticatedUser();
|
||||
if (!user.hasAnyPermission("ALL_FUNCTIONS")) {
|
||||
throw new WebApplicationException(Response.status(403)
|
||||
.entity("{\"message\":\"Only a super user can manage third-party API keys.\"}").type(MediaType.APPLICATION_JSON)
|
||||
.build());
|
||||
}
|
||||
return user;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user