bankdeposit-00-rules.spp
bankdeposit/reversal/bankdeposit-00-rules.spp
Download original file · Bank deposit source contents
1domain bankdeposit;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,23RejectionCode.INVALID_ORIGINAL_DEPOSIT_MOVEMENT24);25require(26cashDepositAgreement.amount == cashDepositAgreement.interestBaseDelta27+ cashDepositAgreement.interestPaid28+ cashDepositAgreement.collectionPaid29+ cashDepositAgreement.principalPaid,30RejectionCode.ORIGINAL_DEPOSIT_MOVEMENT_NOT_BALANCED31);32require(!cashDepositAgreement.reversed, RejectionCode.DEPOSIT_ALREADY_REVERSED);33require(cashDepositAgreement.fee >= 0, RejectionCode.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),46RejectionCode.ES02047);48BigDecimal interestBase = depositAccount.interestBase - cashDepositAgreement.interestBaseDelta;49require(interestBase >= 0, RejectionCode.EN249);50require(51!(interestBase > 052&& depositAccount.overdraftPrincipal53- cashDepositAgreement.principalPaid < 054&& interestBase > depositAccount.frozenAmount),55RejectionCode.EN17756);57}5859atomic check checkCashReversalFacts(CashDepositAgreement, CashReversalAgreement, DepositAccrualState) {60require(61cashReversalAgreement.newDetailItems > 0 && cashDepositAgreement.addedBackdatedProduct >= 0,62RejectionCode.INVALID_CASH_REVERSAL_FACTS63);64require(65depositAccrualState.normalProduct >= cashDepositAgreement.addedBackdatedProduct,66RejectionCode.EN09767);68}6970atomic calculate calculateBankDepositCashReversalMetadata(71CashDepositAgreement,72CashReversalAgreement,73AccountEligibility,74DepositAccrualState,75CashReversalMetadataPlan76) {77cashReversalMetadataPlan.normalProduct = depositAccrualState.normalProduct78- cashDepositAgreement.addedBackdatedProduct;79cashReversalMetadataPlan.actualProduct = cashReversalMetadataPlan.normalProduct80- depositAccrualState.overdraftProduct;81cashReversalMetadataPlan.detailCount = accountEligibility.detailCount82+ cashReversalAgreement.newDetailItems;83if (accountEligibility.detailCount == cashDepositAgreement.settledDetailCount) {84cashReversalMetadataPlan.lastTransactionDate = cashDepositAgreement.previousTransactionDate;85} else {86cashReversalMetadataPlan.lastTransactionDate = cashReversalAgreement.businessDate;87}88if (cashReversalAgreement.overnightMode2) {89cashReversalMetadataPlan.lastTransactionDate = cashReversalAgreement.businessDate;90}91cashReversalMetadataPlan.cashDepositedToday = max(920,93accountEligibility.cashDepositedToday - cashDepositAgreement.amount94);95cashReversalMetadataPlan.reverseInstitutionLimit = cashDepositAgreement.transactionDate == cashReversalAgreement.businessDate96&& accountEligibility.detailCount == cashDepositAgreement.settledDetailCount;97}9899atomic calculate prepareCashReversalAgreement(100CashDepositAgreement,101CashReversalAgreement,102CashReversalMetadataPlan103) {104cashReversalAgreement.original = cashDepositAgreement;105cashReversalAgreement.refundAmount = cashDepositAgreement.fee;106cashReversalAgreement.reverseInstitutionLimit = cashReversalMetadataPlan.reverseInstitutionLimit;107}108109quantum update reverseCashDeposit(110DepositAccount,111CashSettlementAccount,112InterestIncomeAccount,113CollectionInterestIncomeAccount,114CashDepositAgreement115) {116if (cashDepositAgreement.interestBaseDelta >= 0) {117depositAccount.interestBase -> cashSettlementAccount.balance : cashDepositAgreement.interestBaseDelta;118} else {119cashSettlementAccount.balance -> depositAccount.interestBase : -cashDepositAgreement.interestBaseDelta;120}121depositAccount.overdraftInterest -> cashSettlementAccount.balance : cashDepositAgreement.interestPaid;122depositAccount.collectionInterest -> cashSettlementAccount.balance : cashDepositAgreement.collectionPaid;123depositAccount.overdraftPrincipal -> cashSettlementAccount.balance : cashDepositAgreement.principalPaid;124}125126atomic calculate completeCashReversal(127DepositAccount,128CashDepositAgreement,129CashReversalMetadataPlan,130AccountEligibility,131DepositAccrualState132) {133accountEligibility.accountBalance = depositAccount.interestBase134+ depositAccount.overdraftInterest135+ depositAccount.collectionInterest136+ depositAccount.overdraftPrincipal;137accountEligibility.cashDepositedToday = cashReversalMetadataPlan.cashDepositedToday;138cashDepositAgreement.reversed = true;139accountEligibility.detailCount = cashReversalMetadataPlan.detailCount;140accountEligibility.lastTransactionDate = cashReversalMetadataPlan.lastTransactionDate;141depositAccrualState.normalProduct = cashReversalMetadataPlan.normalProduct;142depositAccrualState.actualProduct = cashReversalMetadataPlan.actualProduct;143}144145atomic check checkBankDepositCashReversalPath(DepositOperatorFacts, CashChannel) {146require(147cashChannel.teller148&& cashChannel.channel == "Teller"149&& cashChannel.transactionId == "DEP_CASH"150&& depositOperatorFacts.operationCode == "1102"151&& depositOperatorFacts.transactionPrefix == "SA01102",152RejectionCode.UNSUPPORTED_CASH_REVERSAL_PATH153);154}155156atomic check checkOriginalDepositAccount(DepositAccount, CashDepositAgreement) {157require(158cashDepositAgreement.account.accountNumber == depositAccount.accountNumber,159RejectionCode.ORIGINAL_DEPOSIT_ACCOUNT_MISMATCH160);161}162163atomic check checkOriginalSettlementAccounts(164CashDepositAgreement,165CashSettlementAccount,166InterestIncomeAccount,167CollectionInterestIncomeAccount,168PrincipalRecoveryAccount169) {170require(171cashDepositAgreement.settlement.accountNumber == cashSettlementAccount.accountNumber172&& cashDepositAgreement.interestIncome.accountNumber == interestIncomeAccount.accountNumber173&& cashDepositAgreement.collectionIncome.accountNumber == collectionInterestIncomeAccount.accountNumber174&& cashDepositAgreement.principalRecovery.accountNumber == principalRecoveryAccount.accountNumber,175RejectionCode.ORIGINAL_SETTLEMENT_ACCOUNTS_MISMATCH176);177}178179readonly Scenario serial assessCashReversalFunding(180DepositAccount,181CashDepositAgreement,182DepositReversalCapacity183) {184checkOriginalCashMovement;185checkCashReversalCapacity;186}187188readonly Scenario serial previewCashReversalMetadata(189CashDepositAgreement,190CashReversalAgreement,191AccountEligibility,192DepositAccrualState,193CashReversalMetadataPlan194) {195checkCashReversalFacts;196calculateBankDepositCashReversalMetadata;197}198199readonly Scenario serial quoteCashReversal(200CashDepositAgreement,201CashReversalAgreement,202CashReversalMetadataPlan203) {204checkOriginalCashMovement;205prepareCashReversalAgreement;206}