S++Business systems language
DEMO SOURCE · SPP / APP / PHYRead the book

cboddeposit-40-deposit-fee.spp

cboddeposit/fee/cboddeposit-40-deposit-fee.spp

Download original file · Bank deposit source contents

1domain cboddeposit;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        "UNSUPPORTED_DEPOSIT_FEE_ACCOUNT"38    );39}4041atomic calculate classifyDepositFee(DepositFeeParty, DepositFeeContext, DepositFeePlan) {42    DepositFeePlan.range = 0;43    DepositFeePlan.tariff = "";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 = "SAP00001";51        } else {52            if (DepositFeeParty.branchNumber != DepositFeeContext.branchNumber) {53                DepositFeePlan.range = 1;54                DepositFeePlan.tariff = "SAC00001";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        "DEPOSIT_FEE_TARIFF_MISMATCH"70    );71    require(72        !DepositFeePlan.applicable73            || (DepositFeeRate.rate >= 074            && DepositFeeRate.discount >= 075            && DepositFeeRate.minimum >= 076            && DepositFeeRate.maximum >= DepositFeeRate.minimum),77        "INVALID_DEPOSIT_FEE_RATE"78    );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, "DEPOSIT_FEE_RATE_NOT_FOUND");100}