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