S++Business systems language
DEMO SOURCE · SPP / APP / PHYRead the book

cboddeposit-00-rules.spp

cboddeposit/reversal/cboddeposit-00-rules.spp

Download original file · Bank deposit source contents

1domain cboddeposit;23Role DepositReversalCapacity {4    boolean overdraftPermitted;5    BigDecimal(19, 2) overdraftLimit;6}78Role CashReversalMetadataPlan {9    int detailCount;10    int lastTransactionDate;11    BigDecimal(19, 2) cashDepositedToday;12    BigDecimal(25, 2) normalProduct;13    BigDecimal(25, 2) actualProduct;14    boolean reverseInstitutionLimit;15}1617atomic check checkOriginalCashMovement(CashDepositAgreement) {18    require(19        CashDepositAgreement.amount >= 020            && CashDepositAgreement.interestPaid >= 021            && CashDepositAgreement.collectionPaid >= 022            && CashDepositAgreement.principalPaid >= 0,23        "INVALID_ORIGINAL_DEPOSIT_MOVEMENT"24    );25    require(26        CashDepositAgreement.amount == CashDepositAgreement.interestBaseDelta27            + CashDepositAgreement.interestPaid28            + CashDepositAgreement.collectionPaid29            + CashDepositAgreement.principalPaid,30        "ORIGINAL_DEPOSIT_MOVEMENT_NOT_BALANCED"31    );32    require(!CashDepositAgreement.reversed, "DEPOSIT_ALREADY_REVERSED");33    require(CashDepositAgreement.fee >= 0, "INVALID_ORIGINAL_DEPOSIT_FEE");34}3536atomic check checkCashReversalCapacity(DepositAccount, CashDepositAgreement, DepositReversalCapacity) {37    BigDecimal available = max(38        0,39        DepositAccount.interestBase - DepositAccount.frozenAmount - DepositAccount.authorizedAmount40    );41    require(42        CashDepositAgreement.amount <= available43            || (DepositReversalCapacity.overdraftPermitted44            && DepositReversalCapacity.overdraftLimit >= CashDepositAgreement.amount45            - available),46        "ES020"47    );48    BigDecimal interestBase = DepositAccount.interestBase - CashDepositAgreement.interestBaseDelta;49    require(interestBase >= 0, "EN249");50    require(51        !(interestBase > 052            && DepositAccount.overdraftPrincipal53            + CashDepositAgreement.principalPaid > 054            && interestBase > DepositAccount.frozenAmount),55        "EN177"56    );57}5859atomic check checkCashReversalFacts(CashDepositAgreement, CashReversalAgreement, DepositAccrualState) {60    require(61        CashReversalAgreement.newDetailItems > 0 && CashDepositAgreement.addedBackdatedProduct >= 0,62        "INVALID_CASH_REVERSAL_FACTS"63    );64    require(DepositAccrualState.normalProduct >= CashDepositAgreement.addedBackdatedProduct, "EN097");65}6667atomic calculate calculateXbodCashReversalMetadata(68    CashDepositAgreement,69    CashReversalAgreement,70    AccountEligibility,71    DepositAccrualState,72    CashReversalMetadataPlan73) {74    CashReversalMetadataPlan.normalProduct = DepositAccrualState.normalProduct75        - CashDepositAgreement.addedBackdatedProduct;76    CashReversalMetadataPlan.actualProduct = CashReversalMetadataPlan.normalProduct77        - DepositAccrualState.overdraftProduct;78    CashReversalMetadataPlan.detailCount = AccountEligibility.detailCount79        + CashReversalAgreement.newDetailItems;80    if (AccountEligibility.detailCount == CashDepositAgreement.settledDetailCount) {81        CashReversalMetadataPlan.lastTransactionDate = CashDepositAgreement.previousTransactionDate;82    } else {83        CashReversalMetadataPlan.lastTransactionDate = CashReversalAgreement.businessDate;84    }85    if (CashReversalAgreement.overnightMode2) {86        CashReversalMetadataPlan.lastTransactionDate = CashReversalAgreement.businessDate;87    }88    CashReversalMetadataPlan.cashDepositedToday = max(89        0,90        AccountEligibility.cashDepositedToday - CashDepositAgreement.amount91    );92    CashReversalMetadataPlan.reverseInstitutionLimit = CashDepositAgreement.transactionDate == CashReversalAgreement.businessDate93        && AccountEligibility.detailCount == CashDepositAgreement.settledDetailCount;94}9596atomic calculate prepareCashReversalAgreement(97    CashDepositAgreement,98    CashReversalAgreement,99    CashReversalMetadataPlan100) {101    CashReversalAgreement.original = CashDepositAgreement;102    CashReversalAgreement.refundAmount = CashDepositAgreement.fee;103    CashReversalAgreement.reverseInstitutionLimit = CashReversalMetadataPlan.reverseInstitutionLimit;104}105106quantum update reverseCashDeposit(107    DepositAccount,108    CashSettlementAccount,109    InterestIncomeAccount,110    CollectionInterestIncomeAccount,111    PrincipalRecoveryAccount,112    CashDepositAgreement113) {114    DepositAccount.interestBase -= CashDepositAgreement.interestBaseDelta;115    DepositAccount.overdraftInterest += CashDepositAgreement.interestPaid;116    DepositAccount.collectionInterest += CashDepositAgreement.collectionPaid;117    DepositAccount.overdraftPrincipal += CashDepositAgreement.principalPaid;118    DepositAccount.overdraftExposure += CashDepositAgreement.principalPaid;119    CashSettlementAccount.balance += CashDepositAgreement.amount;120    InterestIncomeAccount.balance -= CashDepositAgreement.interestPaid;121    CollectionInterestIncomeAccount.balance -= CashDepositAgreement.collectionPaid;122    PrincipalRecoveryAccount.balance -= CashDepositAgreement.principalPaid;123}124125atomic calculate completeCashReversal(126    DepositAccount,127    CashDepositAgreement,128    CashReversalMetadataPlan,129    AccountEligibility,130    DepositAccrualState131) {132    AccountEligibility.accountBalance = DepositAccount.interestBase133        - DepositAccount.overdraftInterest134        - DepositAccount.collectionInterest135        - DepositAccount.overdraftPrincipal;136    AccountEligibility.cashDepositedToday = CashReversalMetadataPlan.cashDepositedToday;137    CashDepositAgreement.reversed = true;138    AccountEligibility.detailCount = CashReversalMetadataPlan.detailCount;139    AccountEligibility.lastTransactionDate = CashReversalMetadataPlan.lastTransactionDate;140    DepositAccrualState.normalProduct = CashReversalMetadataPlan.normalProduct;141    DepositAccrualState.actualProduct = CashReversalMetadataPlan.actualProduct;142}143144atomic check checkXbodCashReversalPath(DepositOperatorFacts, CashChannel) {145    require(146        CashChannel.teller147            && CashChannel.channel == "Teller"148            && CashChannel.transactionId == "GSA01102"149            && DepositOperatorFacts.operationCode == "1102"150            && DepositOperatorFacts.transactionPrefix == "SA01102",151        "UNSUPPORTED_CASH_REVERSAL_PATH"152    );153}154155atomic check checkOriginalDepositAccount(DepositAccount, CashDepositAgreement) {156    require(157        CashDepositAgreement.account.accountNumber == DepositAccount.accountNumber,158        "ORIGINAL_DEPOSIT_ACCOUNT_MISMATCH"159    );160}161162atomic check checkOriginalSettlementAccounts(163    CashDepositAgreement,164    CashSettlementAccount,165    InterestIncomeAccount,166    CollectionInterestIncomeAccount,167    PrincipalRecoveryAccount168) {169    require(170        CashDepositAgreement.settlement.accountNumber == CashSettlementAccount.accountNumber171            && CashDepositAgreement.interestIncome.accountNumber == InterestIncomeAccount.accountNumber172            && CashDepositAgreement.collectionIncome.accountNumber == CollectionInterestIncomeAccount.accountNumber173            && CashDepositAgreement.principalRecovery.accountNumber == PrincipalRecoveryAccount.accountNumber,174        "ORIGINAL_SETTLEMENT_ACCOUNTS_MISMATCH"175    );176}