cboddeposit-10-postings.spp
cboddeposit/reversal/cboddeposit-10-postings.spp
Download original file · Bank deposit source contents
1domain cboddeposit;23Role CashReversalPostingLine {4CashReversalAgreement reversal;5int slot;6String subject;7String side;8BigDecimal(19, 2) amount;9}1011atomic query listDepositPostings(key CashDepositAgreement, DepositPostingLine[]);1213atomic check checkOriginalDepositPostings(CashDepositAgreement, DepositPostingLine[]) {14int count = 0;15for (DepositPostingLine line : DepositPostingLine[]) {16count++;17require(18line.deposit.depositNumber == CashDepositAgreement.depositNumber,19"ORIGINAL_DEPOSIT_POSTING_OWNER_MISMATCH"20);21require(22line.slot >= 123&& line.slot <= 824&& line.subject != null25&& line.subject != ""26&& line.amount >= 0,27"INVALID_ORIGINAL_DEPOSIT_POSTINGS"28);29int matching = 0;30for (DepositPostingLine other : DepositPostingLine[]) {31if (other.slot == line.slot) {32matching++;33}34}35require(matching == 1, "INVALID_ORIGINAL_DEPOSIT_POSTINGS");36if (line.slot == 1 || line.slot == 2 || line.slot == 7) {37require(line.side == "Debit", "INVALID_ORIGINAL_DEPOSIT_POSTINGS");38} else {39require(line.side == "Credit", "INVALID_ORIGINAL_DEPOSIT_POSTINGS");40}41int evidenceMatches = 0;42for (DepositPostingLine evidence : CashDepositAgreement.postingEvidence) {43if (evidence.slot == line.slot) {44require(45evidence.subject == line.subject46&& evidence.side == line.side47&& evidence.amount == line.amount,48"ORIGINAL_DEPOSIT_LEDGER_EVIDENCE_MISMATCH"49);50evidenceMatches++;51}52}53require(evidenceMatches == 1, "ORIGINAL_DEPOSIT_LEDGER_EVIDENCE_MISMATCH");54switch (line.slot) {55case 1:56require(57line.amount == CashDepositAgreement.amount,58"ORIGINAL_DEPOSIT_POSTING_AMOUNT_MISMATCH"59);60break;61case 2:62require(63line.amount == max(0, -CashDepositAgreement.interestBaseDelta),64"ORIGINAL_DEPOSIT_POSTING_AMOUNT_MISMATCH"65);66break;67case 3:68require(69line.amount == max(0, CashDepositAgreement.interestBaseDelta),70"ORIGINAL_DEPOSIT_POSTING_AMOUNT_MISMATCH"71);72break;73case 4:74require(75line.amount == CashDepositAgreement.principalPaid,76"ORIGINAL_DEPOSIT_POSTING_AMOUNT_MISMATCH"77);78break;79case 5:80require(81line.amount == CashDepositAgreement.interestPaid,82"ORIGINAL_DEPOSIT_POSTING_AMOUNT_MISMATCH"83);84break;85case 6:86require(87line.amount == CashDepositAgreement.collectionPaid,88"ORIGINAL_DEPOSIT_POSTING_AMOUNT_MISMATCH"89);90break;91case 7:92require(line.amount == CashDepositAgreement.fee, "ORIGINAL_DEPOSIT_POSTING_AMOUNT_MISMATCH");93break;94case 8:95require(line.amount == CashDepositAgreement.fee, "ORIGINAL_DEPOSIT_POSTING_AMOUNT_MISMATCH");96break;97}98}99require(count == 8, "INVALID_ORIGINAL_DEPOSIT_POSTINGS");100}101102atomic calculate prepareCashReversalPostings(103DepositPostingLine[],104CashReversalAgreement,105CashReversalPostingLine[],106DepositPostingTotals107) {108CashReversalPostingLine[] = new CashReversalPostingLine[] {109};110DepositPostingTotals.debit = 0;111DepositPostingTotals.credit = 0;112DepositPostingTotals.fee = CashReversalAgreement.refundAmount;113for (DepositPostingLine original : DepositPostingLine[]) {114CashReversalPostingLine line = new CashReversalPostingLine();115line.slot = original.slot;116line.subject = original.subject;117if (original.side == "Debit") {118line.side = "Credit";119} else {120line.side = "Debit";121}122line.amount = original.amount;123if (original.slot == 7 || original.slot == 8) {124line.amount = CashReversalAgreement.refundAmount;125}126if (line.side == "Debit") {127DepositPostingTotals.debit += line.amount;128} else {129DepositPostingTotals.credit += line.amount;130}131CashReversalPostingLine[] = append(CashReversalPostingLine[], line);132}133}134135atomic calculate attachCashReversalPostings(CashReversalAgreement, CashReversalPostingLine[]) {136for (CashReversalPostingLine line : CashReversalPostingLine[]) {137line.reversal = CashReversalAgreement;138}139}140141atomic query listCashReversalPostings(key CashReversalAgreement, CashReversalPostingLine[]);