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

bankdeposit-40-deposit-fee.spp

bankdeposit/fee/bankdeposit-40-deposit-fee.spp

Download original file · Bank deposit source contents

1domain bankdeposit;23Role DepositFeeParty {4    String accountKind;5    String customerNumber;6    String branchNumber;7    String regionCode;8}910Role DepositFeeContext {11    String channel;12    String branchNumber;13    String regionCode;14}1516Role DepositFeeRate {17    String customerNumber;18    String tariff;19    BigDecimal(19, 6) rate;20    BigDecimal(19, 6) discount;21    BigDecimal(19, 2) fixedAmount;22    BigDecimal(19, 2) minimum;23    BigDecimal(19, 2) maximum;24}2526Role DepositFeePlan {27    int range;28    String tariff;29    boolean applicable;30    BigDecimal(19, 2) variableAmount;31    BigDecimal(19, 2) fee;32}3334atomic check checkFeeAccount(DepositFeeParty, DepositFeeContext) {35    require(36        depositFeeContext.channel != "Teller" || depositFeeParty.accountKind == "NormalSavings",37        RejectionCode.UNSUPPORTED_DEPOSIT_FEE_ACCOUNT38    );39}4041atomic calculate classifyDepositFee(DepositFeeParty, DepositFeeContext, DepositFeePlan) {42    depositFeePlan.range = 0;43    depositFeePlan.tariff = BLANK;44    depositFeePlan.applicable = false;45    depositFeePlan.variableAmount = 0;46    depositFeePlan.fee = 0;47    if (depositFeeContext.channel == "Teller") {48        if (depositFeeParty.regionCode != depositFeeContext.regionCode) {49            depositFeePlan.range = 2;50            depositFeePlan.tariff = "TRF00002";51        } else {52            if (depositFeeParty.branchNumber != depositFeeContext.branchNumber) {53                depositFeePlan.range = 1;54                depositFeePlan.tariff = "TRF00001";55            }56        }57        depositFeePlan.applicable = depositFeePlan.range > 0;58    }59}6061atomic calculate prepareFeeLookup(DepositFeeParty, DepositFeePlan, DepositFeeRate) {62    depositFeeRate.customerNumber = depositFeeParty.customerNumber;63    depositFeeRate.tariff = depositFeePlan.tariff;64}6566atomic check checkFeeRate(DepositFeePlan, DepositFeeRate) {67    require(68        !depositFeePlan.applicable || depositFeeRate.tariff == depositFeePlan.tariff,69        RejectionCode.DEPOSIT_FEE_TARIFF_MISMATCH70    );71    require(72        !depositFeePlan.applicable73            || (depositFeeRate.rate >= 074            && depositFeeRate.discount >= 075            && depositFeeRate.minimum >= 076            && depositFeeRate.maximum >= depositFeeRate.minimum),77        RejectionCode.INVALID_DEPOSIT_FEE_RATE78    );79}8081atomic calculate calculateDepositFee(DepositRequest, DepositFeeRate, DepositFeePlan) {82    if (depositFeePlan.applicable) {83        depositFeePlan.variableAmount = roundHalfUp(84            depositRequest.amount * depositFeeRate.rate * depositFeeRate.discount,85            286        );87        depositFeePlan.fee = depositFeePlan.variableAmount + depositFeeRate.fixedAmount;88        if (depositFeePlan.fee > depositFeeRate.maximum) {89            depositFeePlan.fee = depositFeeRate.maximum;90        } else {91            if (depositFeePlan.fee < depositFeeRate.minimum) {92                depositFeePlan.fee = depositFeeRate.minimum;93            }94        }95    }96}9798atomic check checkRequiredFeeIdentified(DepositFeePlan, DepositFeeRate) {99    require(!depositFeePlan.applicable || depositFeeRate, RejectionCode.DEPOSIT_FEE_RATE_NOT_FOUND);100}