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

bankdeposit-30-agreement-product.spp

bankdeposit/accrual/bankdeposit-30-agreement-product.spp

Download original file · Bank deposit source contents

1domain bankdeposit;23// the legacy product module A: retain the five source slots, traversed 5 down to 1.4// Normal and agreement periods have already been clipped/decoded by calendar services.56Role AgreementBand {7    int slot;8    BigDecimal(19, 2) threshold;9    BigDecimal(19, 2) product;10}1112Role AgreementPolicy {13    String mode;14    String currency;15    boolean enabled;16}1718Role AgreementProduct {19    BigDecimal(19, 2) normalProduct;20    BigDecimal(19, 2) bandProduct;21    BigDecimal(19, 2) remainingAmount;22    int selectedSlot;23    String appliedMode;24}2526atomic calculate calculateAgreementProduct(27    InterestPeriod,28    OverlapPeriod,29    AgreementPolicy,30    AgreementBand[],31    AgreementProduct32) {33    agreementProduct.normalProduct = roundDown(normal.amount / normal.unit, 0) * normal.unit * normal.days;34    agreementProduct.bandProduct = 0;35    agreementProduct.remainingAmount = normal.amount;36    agreementProduct.selectedSlot = 0;37    agreementProduct.appliedMode = agreementPolicy.mode;38    if (agreementPolicy.mode != "1" && agreementPolicy.mode != "2") {39        if (agreementPolicy.currency == "CNY") {40            agreementProduct.appliedMode = "2";41        } else {42            agreementProduct.appliedMode = "1";43        }44    }45    for (AgreementBand band : agreementBands) {46        band.product = 0;47    }48    if (agreementPolicy.enabled && overlap.days > 0) {49        for (AgreementBand band : agreementBands) {50            if (agreementProduct.appliedMode == "2") {51                if (agreementProduct.remainingAmount > band.threshold) {52                    band.product = roundDown(53                        (agreementProduct.remainingAmount - band.threshold) / normal.unit,54                        055                    ) * normal.unit * overlap.days;56                    agreementProduct.bandProduct += band.product;57                    agreementProduct.remainingAmount = band.threshold;58                    if (band.slot == 1) {59                        agreementProduct.normalProduct -= roundDown(60                            (normal.amount - band.threshold) / normal.unit,61                            062                        ) * normal.unit * overlap.days;63                    }64                }65            } else {66                if (normal.amount >= band.threshold) {67                    band.product = roundDown(normal.amount / normal.unit, 0) * normal.unit * overlap.days;68                    agreementProduct.bandProduct = band.product;69                    agreementProduct.normalProduct -= band.product;70                    agreementProduct.selectedSlot = band.slot;71                    break;72                }73            }74        }75    }76}7778atomic check checkAgreementProductInput(InterestPeriod, OverlapPeriod, AgreementBand[]) {79    require(normal.amount >= 0 && normal.unit > 0 && normal.days >= 0, RejectionCode.INVALID_INTEREST_PERIOD);80    require(81        overlap.amount == normal.amount82            && overlap.unit == normal.unit83            && overlap.days >= 084            && overlap.days <= normal.days,85        RejectionCode.INVALID_AGREEMENT_PERIOD86    );87    int expectedSlot = 5;88    for (AgreementBand band : agreementBands) {89        require(band.slot == expectedSlot && band.threshold >= 0, RejectionCode.INVALID_AGREEMENT_BANDS);90        expectedSlot--;91    }92    require(expectedSlot == 0, RejectionCode.INVALID_AGREEMENT_BANDS);93}9495readonly Scenario serial previewAgreementWindow(96    BankDate,97    PeriodEnd,98    AgreementTerm,99    OverlapStart,100    OverlapEnd,101    InterestPeriod,102    OverlapPeriod,103    AgreementPolicy104) {105    prepareAgreementWindow(106        start,107        end,108        agreementTerm,109        clippedStart,110        clippedEnd,111        normal,112        overlap,113        agreementPolicy114    );115}