bankdeposit-00-postings.spp
bankdeposit/posting/bankdeposit-00-postings.spp
Download original file · Bank deposit source contents
1domain bankdeposit;23// the legacy deposit program: 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,38RejectionCode.NEGATIVE_DEPOSIT_ACCOUNTING_AMOUNT39);40require(41depositAccounting.fundingTotal == depositAccounting.transactionAmount42+ depositAccounting.depositDecrease43&& depositAccounting.allocationTotal == depositAccounting.depositIncrease44+ depositAccounting.principalPaid45+ depositAccounting.interestPaid46+ depositAccounting.collectionPaid,47RejectionCode.DEPOSIT_ACCOUNTING_TOTAL_MISMATCH48);49require(50depositAccounting.fundingTotal == depositAccounting.allocationTotal,51RejectionCode.DEPOSIT_ACCOUNTING_NOT_BALANCED52);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 : depositPostingLines) {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(117depositPostingTotals.debit == depositPostingTotals.credit,118RejectionCode.DEPOSIT_POSTINGS_NOT_BALANCED119);120}121122atomic check checkPostingRules(DepositPostingLine[], DepositFeePlan) {123int expected = 1;124for (DepositPostingLine line : depositPostingLines) {125require(126line.slot == expected && line.subject != BLANK,127RejectionCode.INVALID_DEPOSIT_POSTING_RULES128);129if (line.slot == 1 || line.slot == 2 || line.slot == 7) {130require(line.side == "Debit", RejectionCode.INVALID_DEPOSIT_POSTING_SIDE);131} else {132require(line.side == "Credit", RejectionCode.INVALID_DEPOSIT_POSTING_SIDE);133}134expected++;135}136require(expected == 9 && depositFeePlan.fee >= 0, RejectionCode.INVALID_DEPOSIT_POSTING_RULES);137}138139atomic calculate attachDepositPostings(CashDepositAgreement, DepositPostingLine[]) {140for (DepositPostingLine line : depositPostingLines) {141line.deposit = cashDepositAgreement;142}143}144145atomic calculate preserveDepositPostingEvidence(CashDepositAgreement, DepositPostingLine[]) {146cashDepositAgreement.postingEvidence = new DepositPostingLine[] {147};148for (DepositPostingLine line : depositPostingLines) {149DepositPostingLine evidence = new DepositPostingLine();150evidence.slot = line.slot;151evidence.subject = line.subject;152evidence.side = line.side;153evidence.amount = line.amount;154cashDepositAgreement.postingEvidence = append(cashDepositAgreement.postingEvidence, evidence);155}156}157158readonly Scenario serial previewDepositAllocation(DepositRequest, DepositPlan, DepositAccounting) {159classifyDepositAccounting;160checkDepositAccounting;161}162163readonly Scenario serial previewDepositPostings(164DepositAccounting,165DepositFeePlan,166DepositPostingLine[],167DepositPostingTotals168) {169checkDepositAccounting;170checkPostingRules;171calculateDepositPostings;172checkDepositPostings;173}