cboddeposit-30-agreement-product.spp
cboddeposit/accrual/cboddeposit-30-agreement-product.spp
Download original file · Bank deposit source contents
1domain cboddeposit;23// CSAPRD2 5500/5555: 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 {7int slot;8BigDecimal(19, 2) threshold;9BigDecimal(19, 2) product;10}1112Role AgreementPolicy {13String mode;14String currency;15boolean enabled;16}1718Role AgreementProduct {19BigDecimal(19, 2) normalProduct;20BigDecimal(19, 2) bandProduct;21BigDecimal(19, 2) remainingAmount;22int selectedSlot;23String appliedMode;24}2526atomic calculate calculateAgreementProduct(27InterestPeriod normal,28InterestPeriod overlap,29AgreementPolicy,30AgreementBand[],31AgreementProduct32) {33AgreementProduct.normalProduct = roundDown(normal.amount / normal.unit, 0) * normal.unit * normal.days;34AgreementProduct.bandProduct = 0;35AgreementProduct.remainingAmount = normal.amount;36AgreementProduct.selectedSlot = 0;37AgreementProduct.appliedMode = AgreementPolicy.mode;38if (AgreementPolicy.mode != "1" && AgreementPolicy.mode != "2") {39if (AgreementPolicy.currency == "CNY") {40AgreementProduct.appliedMode = "2";41} else {42AgreementProduct.appliedMode = "1";43}44}45for (AgreementBand band : AgreementBand[]) {46band.product = 0;47}48if (AgreementPolicy.enabled && overlap.days > 0) {49for (AgreementBand band : AgreementBand[]) {50if (AgreementProduct.appliedMode == "2") {51if (AgreementProduct.remainingAmount > band.threshold) {52band.product = roundDown(53(AgreementProduct.remainingAmount - band.threshold) / normal.unit,54055) * normal.unit * overlap.days;56AgreementProduct.bandProduct += band.product;57AgreementProduct.remainingAmount = band.threshold;58if (band.slot == 1) {59AgreementProduct.normalProduct -= roundDown(60(normal.amount - band.threshold) / normal.unit,61062) * normal.unit * overlap.days;63}64}65} else {66if (normal.amount >= band.threshold) {67band.product = roundDown(normal.amount / normal.unit, 0) * normal.unit * overlap.days;68AgreementProduct.bandProduct = band.product;69AgreementProduct.normalProduct -= band.product;70AgreementProduct.selectedSlot = band.slot;71break;72}73}74}75}76}7778atomic check checkAgreementProductInput(InterestPeriod normal, InterestPeriod overlap, AgreementBand[]) {79require(normal.amount >= 0 && normal.unit > 0 && normal.days >= 0, "INVALID_INTEREST_PERIOD");80require(81overlap.amount == normal.amount82&& overlap.unit == normal.unit83&& overlap.days >= 084&& overlap.days <= normal.days,85"INVALID_AGREEMENT_PERIOD"86);87int expectedSlot = 5;88for (AgreementBand band : AgreementBand[]) {89require(band.slot == expectedSlot && band.threshold >= 0, "INVALID_AGREEMENT_BANDS");90expectedSlot--;91}92require(expectedSlot == 0, "INVALID_AGREEMENT_BANDS");93}