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

cboddeposit-20-bank-calendar.spp

cboddeposit/accrual/cboddeposit-20-bank-calendar.spp

Download original file · Bank deposit source contents

1domain cboddeposit;23// Business interest-unit quantization, CSAPRD2 5300; dates supplied by shared calendar service.45Role InterestPeriod {6    BigDecimal(19, 2) amount;7    BigDecimal(19, 2) unit;8    int days;9}1011Role InterestProduct {12    BigDecimal(19, 2) qualifiedAmount;13    BigDecimal(19, 2) product;14}1516atomic check checkInterestPeriod(InterestPeriod) {17    require(18        InterestPeriod.amount >= 0 && InterestPeriod.unit > 0 && InterestPeriod.days >= 0,19        "INVALID_INTEREST_PERIOD"20    );21}2223atomic check checkBankDate(BankDate) {24    require(BankDate.encoded != null && BankDate.encoded != 0, "EEC28");25    require(BankDate.encoded >= 10000101 && BankDate.encoded <= 99991231, "EE374");26    require(isGregorianDate(BankDate.encoded), "EE374");27}2829atomic check checkBankDays(BankDate start, BankDate end, InterestCalendar) {30    require(start.epochDay <= end.epochDay, "E1175");31    require(32        InterestCalendar.convention == "ACT"33            || InterestCalendar.convention == "360365"34            || InterestCalendar.convention == "360360",35        "EEC28"36    );37}3839atomic calculate calculateInterestProduct(InterestPeriod, InterestProduct) {40    InterestProduct.qualifiedAmount = roundDown(41        InterestPeriod.amount / InterestPeriod.unit,42        043    ) * InterestPeriod.unit;44    InterestProduct.product = InterestProduct.qualifiedAmount * InterestPeriod.days;45}4647// CSAPRD2/CCMDAT1 function O: start included, end excluded.48// The shared Gregorian functions decode representation; business selects ACT or deposit 360-day policy.4950Role BankDate {51    int encoded;52    int year;53    int month;54    int day;55    int epochDay;56}5758Role InterestCalendar {59    String convention;60}6162atomic calculate decodeBankDate(BankDate) {63    BankDate.year = dateYear(BankDate.encoded);64    BankDate.month = dateMonth(BankDate.encoded);65    BankDate.day = dateDay(BankDate.encoded);66    BankDate.epochDay = dateEpochDay(BankDate.encoded);67}6869atomic calculate calculateBankDays(BankDate start, BankDate end, InterestCalendar, InterestPeriod) {70    if (InterestCalendar.convention == "ACT") {71        InterestPeriod.days = end.epochDay - start.epochDay;72    } else {73        InterestPeriod.days = 36074            * (end.year75            - start.year)76            + 3077            * (end.month78            - start.month)79            + min(end.day, 30)80            - min(start.day, 30);81    }82}