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

bankdeposit-20-internal-accounts.spp

bankdeposit/account/bankdeposit-20-internal-accounts.spp

Download original file · Bank deposit source contents

1domain bankdeposit;23Role InterestIncomeAccount;45Role CollectionInterestIncomeAccount;67Role PrincipalRecoveryAccount;89take InterestSubject as InterestIncomeAccount {10    takeall;11    quantum BigDecimal(19, 2) balance;12}1314take CollectionSubject as CollectionInterestIncomeAccount {15    takeall;16    quantum BigDecimal(19, 2) balance;17}1819take PrincipalSubject as PrincipalRecoveryAccount {20    takeall;21    quantum BigDecimal(19, 2) balance;22}2324// The three internal accounts are opened together, so each subject is its own role with its own table.2526Role InterestSubject short interestSubject {27    String accountNumber;28}2930Role CollectionSubject short collectionSubject {31    String accountNumber;32}3334Role PrincipalSubject short principalSubject {35    String accountNumber;36}3738Contract InternalAccountOpeningAgreement {39    InterestIncomeAccount interestIncome;40    CollectionInterestIncomeAccount collectionIncome;41    PrincipalRecoveryAccount principalRecovery;42}4344atomic check checkInternalAccountNumbers( InterestSubject, CollectionSubject, PrincipalSubject ) {45    require(46        interestSubject.accountNumber != BLANK47            && collectionSubject.accountNumber != BLANK48            && principalSubject.accountNumber != BLANK,49        RejectionCode.INTERNAL_ACCOUNT_NUMBER_REQUIRED50    );51    require(52        interestSubject.accountNumber != collectionSubject.accountNumber53            && interestSubject.accountNumber != principalSubject.accountNumber54            && collectionSubject.accountNumber != principalSubject.accountNumber,55        RejectionCode.INTERNAL_ACCOUNTS_MUST_DIFFER56    );57}5859atomic calculate prepareInternalAccounts(60    InterestSubject,61    CollectionSubject,62    PrincipalSubject,63    InterestIncomeAccount,64    CollectionInterestIncomeAccount,65    PrincipalRecoveryAccount,66    InternalAccountOpeningAgreement67) {68    interestIncomeAccount.accountNumber = interestSubject.accountNumber;69    collectionInterestIncomeAccount.accountNumber = collectionSubject.accountNumber;70    principalRecoveryAccount.accountNumber = principalSubject.accountNumber;71    internalAccountOpeningAgreement.interestIncome = interestIncomeAccount;72    internalAccountOpeningAgreement.collectionIncome = collectionInterestIncomeAccount;73    internalAccountOpeningAgreement.principalRecovery = principalRecoveryAccount;74}