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

bankdeposit-45-agreement-window.spp

bankdeposit/accrual/bankdeposit-45-agreement-window.spp

Download original file · Bank deposit source contents

1domain bankdeposit;23// Zero date encodes absent agreement dates; clipping is business policy, not APP routing.45Role AgreementTerm {6    int effectiveDate;7    int cancelDate;8}910// The clipped window and the overlap period are second participants of the BankDate and11// InterestPeriod types, so each is a distinct role over its base type.1213Role OverlapStart short clippedStart;1415take BankDate as OverlapStart;1617Role OverlapEnd short clippedEnd;1819take BankDate as OverlapEnd;2021Role OverlapPeriod short overlap;2223take InterestPeriod as OverlapPeriod;2425atomic calculate prepareAgreementWindow(26    BankDate,27    PeriodEnd,28    AgreementTerm,29    OverlapStart,30    OverlapEnd,31    InterestPeriod,32    OverlapPeriod,33    AgreementPolicy34) {35    clippedStart.encoded = start.encoded;36    clippedEnd.encoded = start.encoded;37    overlap.amount = normal.amount;38    overlap.unit = normal.unit;39    overlap.days = 0;40    agreementPolicy.enabled = agreementPolicy.enabled && agreementTerm.effectiveDate > 0;41    if (agreementPolicy.enabled) {42        clippedStart.encoded = max(start.encoded, agreementTerm.effectiveDate);43        clippedEnd.encoded = end.encoded;44        if (agreementTerm.cancelDate > 0) {45            clippedEnd.encoded = min(end.encoded, agreementTerm.cancelDate);46        }47        if (clippedStart.encoded >= clippedEnd.encoded) {48            agreementPolicy.enabled = false;49            clippedStart.encoded = start.encoded;50            clippedEnd.encoded = start.encoded;51        }52    }53}