cboddeposit-00-postings.spp
cboddeposit/posting/cboddeposit-00-postings.spp
Download original file · Bank deposit source contents
1domain cboddeposit;23// KSADEP0 6100: business amount categories before runtime accounting rule selection.45Role DepositAccounting {6BigDecimal(19, 2) transactionAmount;7BigDecimal(19, 2) depositIncrease;8BigDecimal(19, 2) depositDecrease;9BigDecimal(19, 2) principalPaid;10BigDecimal(19, 2) interestPaid;11BigDecimal(19, 2) collectionPaid;12BigDecimal(19, 2) fundingTotal;13BigDecimal(19, 2) allocationTotal;14}1516atomic calculate classifyDepositAccounting(DepositRequest, DepositPlan, DepositAccounting) {17DepositAccounting.transactionAmount = DepositRequest.amount;18DepositAccounting.depositIncrease = DepositPlan.interestBaseIncrease;19DepositAccounting.depositDecrease = DepositPlan.interestBaseDecrease;20DepositAccounting.principalPaid = DepositPlan.principalPaid;21DepositAccounting.interestPaid = DepositPlan.interestPaid;22DepositAccounting.collectionPaid = DepositPlan.collectionInterestPaid;23DepositAccounting.fundingTotal = DepositAccounting.transactionAmount + DepositAccounting.depositDecrease;24DepositAccounting.allocationTotal = DepositAccounting.depositIncrease25+ DepositAccounting.principalPaid26+ DepositAccounting.interestPaid27+ DepositAccounting.collectionPaid;28}2930atomic check checkDepositAccounting(DepositAccounting) {31require(32DepositAccounting.transactionAmount >= 033&& DepositAccounting.depositIncrease >= 034&& DepositAccounting.depositDecrease >= 035&& DepositAccounting.principalPaid >= 036&& DepositAccounting.interestPaid >= 037&& DepositAccounting.collectionPaid >= 0,38"NEGATIVE_DEPOSIT_ACCOUNTING_AMOUNT"39);40require(41DepositAccounting.fundingTotal == DepositAccounting.transactionAmount42+ DepositAccounting.depositDecrease43&& DepositAccounting.allocationTotal == DepositAccounting.depositIncrease44+ DepositAccounting.principalPaid45+ DepositAccounting.interestPaid46+ DepositAccounting.collectionPaid,47"DEPOSIT_ACCOUNTING_TOTAL_MISMATCH"48);49require(50DepositAccounting.fundingTotal == DepositAccounting.allocationTotal,51"DEPOSIT_ACCOUNTING_NOT_BALANCED"52);53}5455// Explicit demo rule slots, not a reconstruction of the unavailable ART subject configuration.5657Role DepositPostingLine {58CashDepositAgreement deposit;59int slot;60String subject;61String side;62BigDecimal(19, 2) amount;63}6465Role DepositPostingTotals {66BigDecimal(19, 2) debit;67BigDecimal(19, 2) credit;68BigDecimal(19, 2) fee;69}7071atomic calculate calculateDepositPostings(72DepositAccounting,73DepositFeePlan,74DepositPostingLine[],75DepositPostingTotals76) {77DepositPostingTotals.debit = 0;78DepositPostingTotals.credit = 0;79DepositPostingTotals.fee = DepositFeePlan.fee;80for (DepositPostingLine line : DepositPostingLine[]) {81switch (line.slot) {82case 1:83line.amount = DepositAccounting.transactionAmount;84break;85case 2:86line.amount = DepositAccounting.depositDecrease;87break;88case 3:89line.amount = DepositAccounting.depositIncrease;90break;91case 4:92line.amount = DepositAccounting.principalPaid;93break;94case 5:95line.amount = DepositAccounting.interestPaid;96break;97case 6:98line.amount = DepositAccounting.collectionPaid;99break;100case 7:101line.amount = DepositFeePlan.fee;102break;103case 8:104line.amount = DepositFeePlan.fee;105break;106}107if (line.side == "Debit") {108DepositPostingTotals.debit += line.amount;109} else {110DepositPostingTotals.credit += line.amount;111}112}113}114115atomic check checkDepositPostings(DepositPostingTotals) {116require(DepositPostingTotals.debit == DepositPostingTotals.credit, "DEPOSIT_POSTINGS_NOT_BALANCED");117}118119atomic check checkPostingRules(DepositPostingLine[], DepositFeePlan) {120int expected = 1;121for (DepositPostingLine line : DepositPostingLine[]) {122require(123line.slot == expected && line.subject != null && line.subject != "",124"INVALID_DEPOSIT_POSTING_RULES"125);126if (line.slot == 1 || line.slot == 2 || line.slot == 7) {127require(line.side == "Debit", "INVALID_DEPOSIT_POSTING_SIDE");128} else {129require(line.side == "Credit", "INVALID_DEPOSIT_POSTING_SIDE");130}131expected++;132}133require(expected == 9 && DepositFeePlan.fee >= 0, "INVALID_DEPOSIT_POSTING_RULES");134}135136atomic calculate attachDepositPostings(CashDepositAgreement, DepositPostingLine[]) {137for (DepositPostingLine line : DepositPostingLine[]) {138line.deposit = CashDepositAgreement;139}140}141142atomic calculate preserveDepositPostingEvidence(CashDepositAgreement, DepositPostingLine[]) {143CashDepositAgreement.postingEvidence = new DepositPostingLine[] {144};145for (DepositPostingLine line : DepositPostingLine[]) {146DepositPostingLine evidence = new DepositPostingLine();147evidence.slot = line.slot;148evidence.subject = line.subject;149evidence.side = line.side;150evidence.amount = line.amount;151CashDepositAgreement.postingEvidence = append(CashDepositAgreement.postingEvidence, evidence);152}153}