bankdeposit-10-postings.spp
bankdeposit/reversal/bankdeposit-10-postings.spp
Download original file · Bank deposit source contents
1domain bankdeposit;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 : depositPostingLines) {16count++;17require(18line.deposit.depositNumber == cashDepositAgreement.depositNumber,19RejectionCode.ORIGINAL_DEPOSIT_POSTING_OWNER_MISMATCH20);21require(22line.slot >= 123&& line.slot <= 824&& line.subject != null25&& line.subject != ""26&& line.amount >= 0,27RejectionCode.INVALID_ORIGINAL_DEPOSIT_POSTINGS28);29int matching = 0;30for (DepositPostingLine candidate : depositPostingLines) {31if (candidate.slot == line.slot) {32matching++;33}34}35require(matching == 1, RejectionCode.INVALID_ORIGINAL_DEPOSIT_POSTINGS);36if (line.slot == 1 || line.slot == 2 || line.slot == 7) {37require(line.side == "Debit", RejectionCode.INVALID_ORIGINAL_DEPOSIT_POSTINGS);38} else {39require(line.side == "Credit", RejectionCode.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,48RejectionCode.ORIGINAL_DEPOSIT_LEDGER_EVIDENCE_MISMATCH49);50evidenceMatches++;51}52}53require(evidenceMatches == 1, RejectionCode.ORIGINAL_DEPOSIT_LEDGER_EVIDENCE_MISMATCH);54switch (line.slot) {55case 1:56require(57line.amount == cashDepositAgreement.amount,58RejectionCode.ORIGINAL_DEPOSIT_POSTING_AMOUNT_MISMATCH59);60break;61case 2:62require(63line.amount == max(0, -cashDepositAgreement.interestBaseDelta),64RejectionCode.ORIGINAL_DEPOSIT_POSTING_AMOUNT_MISMATCH65);66break;67case 3:68require(69line.amount == max(0, cashDepositAgreement.interestBaseDelta),70RejectionCode.ORIGINAL_DEPOSIT_POSTING_AMOUNT_MISMATCH71);72break;73case 4:74require(75line.amount == cashDepositAgreement.principalPaid,76RejectionCode.ORIGINAL_DEPOSIT_POSTING_AMOUNT_MISMATCH77);78break;79case 5:80require(81line.amount == cashDepositAgreement.interestPaid,82RejectionCode.ORIGINAL_DEPOSIT_POSTING_AMOUNT_MISMATCH83);84break;85case 6:86require(87line.amount == cashDepositAgreement.collectionPaid,88RejectionCode.ORIGINAL_DEPOSIT_POSTING_AMOUNT_MISMATCH89);90break;91case 7:92require(93line.amount == cashDepositAgreement.fee,94RejectionCode.ORIGINAL_DEPOSIT_POSTING_AMOUNT_MISMATCH95);96break;97case 8:98require(99line.amount == cashDepositAgreement.fee,100RejectionCode.ORIGINAL_DEPOSIT_POSTING_AMOUNT_MISMATCH101);102break;103}104}105require(count == 8, RejectionCode.INVALID_ORIGINAL_DEPOSIT_POSTINGS);106}107108atomic calculate prepareCashReversalPostings(109DepositPostingLine[],110CashReversalAgreement,111CashReversalPostingLine[],112DepositPostingTotals113) {114cashReversalPostingLines = new CashReversalPostingLine[] {115};116depositPostingTotals.debit = 0;117depositPostingTotals.credit = 0;118depositPostingTotals.fee = cashReversalAgreement.refundAmount;119for (DepositPostingLine original : depositPostingLines) {120CashReversalPostingLine line = new CashReversalPostingLine();121line.slot = original.slot;122line.subject = original.subject;123if (original.side == "Debit") {124line.side = "Credit";125} else {126line.side = "Debit";127}128line.amount = original.amount;129if (original.slot == 7 || original.slot == 8) {130line.amount = cashReversalAgreement.refundAmount;131}132if (line.side == "Debit") {133depositPostingTotals.debit += line.amount;134} else {135depositPostingTotals.credit += line.amount;136}137cashReversalPostingLines = append(cashReversalPostingLines, line);138}139}140141atomic calculate attachCashReversalPostings(CashReversalAgreement, CashReversalPostingLine[]) {142for (CashReversalPostingLine line : cashReversalPostingLines) {143line.reversal = cashReversalAgreement;144}145}146147atomic query listCashReversalPostings(key CashReversalAgreement, CashReversalPostingLine[]);