S++Core systems, human-reviewable
DEMO SOURCE · SPP / APP / PHYRead the book

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 {6    BigDecimal(19, 2) transactionAmount;7    BigDecimal(19, 2) depositIncrease;8    BigDecimal(19, 2) depositDecrease;9    BigDecimal(19, 2) principalPaid;10    BigDecimal(19, 2) interestPaid;11    BigDecimal(19, 2) collectionPaid;12    BigDecimal(19, 2) fundingTotal;13    BigDecimal(19, 2) allocationTotal;14}1516atomic calculate classifyDepositAccounting(DepositRequest, DepositPlan, DepositAccounting) {17    depositAccounting.transactionAmount = depositRequest.amount;18    depositAccounting.depositIncrease = depositPlan.interestBaseIncrease;19    depositAccounting.depositDecrease = depositPlan.interestBaseDecrease;20    depositAccounting.principalPaid = depositPlan.principalPaid;21    depositAccounting.interestPaid = depositPlan.interestPaid;22    depositAccounting.collectionPaid = depositPlan.collectionInterestPaid;23    depositAccounting.fundingTotal = depositAccounting.transactionAmount + depositAccounting.depositDecrease;24    depositAccounting.allocationTotal = depositAccounting.depositIncrease25        + depositAccounting.principalPaid26        + depositAccounting.interestPaid27        + depositAccounting.collectionPaid;28}2930atomic check checkDepositAccounting(DepositAccounting) {31    require(32        depositAccounting.transactionAmount >= 033            && depositAccounting.depositIncrease >= 034            && depositAccounting.depositDecrease >= 035            && depositAccounting.principalPaid >= 036            && depositAccounting.interestPaid >= 037            && depositAccounting.collectionPaid >= 0,38        RejectionCode.NEGATIVE_DEPOSIT_ACCOUNTING_AMOUNT39    );40    require(41        depositAccounting.fundingTotal == depositAccounting.transactionAmount42            + depositAccounting.depositDecrease43            && depositAccounting.allocationTotal == depositAccounting.depositIncrease44            + depositAccounting.principalPaid45            + depositAccounting.interestPaid46            + depositAccounting.collectionPaid,47        RejectionCode.DEPOSIT_ACCOUNTING_TOTAL_MISMATCH48    );49    require(50        depositAccounting.fundingTotal == depositAccounting.allocationTotal,51        RejectionCode.DEPOSIT_ACCOUNTING_NOT_BALANCED52    );53}5455// Explicit demo rule slots, not a reconstruction of the unavailable ART subject configuration.5657Role DepositPostingLine {58    CashDepositAgreement deposit;59    int slot;60    String subject;61    String side;62    BigDecimal(19, 2) amount;63}6465Role DepositPostingTotals {66    BigDecimal(19, 2) debit;67    BigDecimal(19, 2) credit;68    BigDecimal(19, 2) fee;69}7071atomic calculate calculateDepositPostings(72    DepositAccounting,73    DepositFeePlan,74    DepositPostingLine[],75    DepositPostingTotals76) {77    depositPostingTotals.debit = 0;78    depositPostingTotals.credit = 0;79    depositPostingTotals.fee = depositFeePlan.fee;80    for (DepositPostingLine line : depositPostingLines) {81        switch (line.slot) {82            case 1:83                line.amount = depositAccounting.transactionAmount;84                break;85            case 2:86                line.amount = depositAccounting.depositDecrease;87                break;88            case 3:89                line.amount = depositAccounting.depositIncrease;90                break;91            case 4:92                line.amount = depositAccounting.principalPaid;93                break;94            case 5:95                line.amount = depositAccounting.interestPaid;96                break;97            case 6:98                line.amount = depositAccounting.collectionPaid;99                break;100            case 7:101                line.amount = depositFeePlan.fee;102                break;103            case 8:104                line.amount = depositFeePlan.fee;105                break;106        }107        if (line.side == "Debit") {108            depositPostingTotals.debit += line.amount;109        } else {110            depositPostingTotals.credit += line.amount;111        }112    }113}114115atomic check checkDepositPostings(DepositPostingTotals) {116    require(117        depositPostingTotals.debit == depositPostingTotals.credit,118        RejectionCode.DEPOSIT_POSTINGS_NOT_BALANCED119    );120}121122atomic check checkPostingRules(DepositPostingLine[], DepositFeePlan) {123    int expected = 1;124    for (DepositPostingLine line : depositPostingLines) {125        require(126            line.slot == expected && line.subject != BLANK,127            RejectionCode.INVALID_DEPOSIT_POSTING_RULES128        );129        if (line.slot == 1 || line.slot == 2 || line.slot == 7) {130            require(line.side == "Debit", RejectionCode.INVALID_DEPOSIT_POSTING_SIDE);131        } else {132            require(line.side == "Credit", RejectionCode.INVALID_DEPOSIT_POSTING_SIDE);133        }134        expected++;135    }136    require(expected == 9 && depositFeePlan.fee >= 0, RejectionCode.INVALID_DEPOSIT_POSTING_RULES);137}138139atomic calculate attachDepositPostings(CashDepositAgreement, DepositPostingLine[]) {140    for (DepositPostingLine line : depositPostingLines) {141        line.deposit = cashDepositAgreement;142    }143}144145atomic calculate preserveDepositPostingEvidence(CashDepositAgreement, DepositPostingLine[]) {146    cashDepositAgreement.postingEvidence = new DepositPostingLine[] {147    };148    for (DepositPostingLine line : depositPostingLines) {149        DepositPostingLine evidence = new DepositPostingLine();150        evidence.slot = line.slot;151        evidence.subject = line.subject;152        evidence.side = line.side;153        evidence.amount = line.amount;154        cashDepositAgreement.postingEvidence = append(cashDepositAgreement.postingEvidence, evidence);155    }156}157158readonly Scenario serial previewDepositAllocation(DepositRequest, DepositPlan, DepositAccounting) {159    classifyDepositAccounting;160    checkDepositAccounting;161}162163readonly Scenario serial previewDepositPostings(164    DepositAccounting,165    DepositFeePlan,166    DepositPostingLine[],167    DepositPostingTotals168) {169    checkDepositAccounting;170    checkPostingRules;171    calculateDepositPostings;172    checkDepositPostings;173}