Search in sources :

Example 1 with BankMandate

use of org.estatio.dom.bankmandate.BankMandate in project estatio by estatio.

the class Api method putBankMandate.

@ActionSemantics(Of.IDEMPOTENT)
public void putBankMandate(@Named("reference") final String reference, @Named("sepaMandateIdentifier") @Optional final String sepaMandateIdentifier, @Named("name") @Optional final String name, @Named("leaseReference") final String leaseReference, @Named("debtorReference") final String debtorReference, @Named("creditorReference") final String creditorReference, @Named("bankAccountReference") final String bankAccountReference, @Named("startDate") final LocalDate startDate, @Named("endDate") @Optional final LocalDate endDate) {
    BankMandate bankMandate = (BankMandate) agreements.findAgreementByReference(reference);
    final BankAccount bankAccount = (BankAccount) financialAccounts.findAccountByReference(bankAccountReference);
    if (bankAccount == null)
        throw new ApplicationException(String.format("BankAccount with reference %1$s not found", bankAccountReference));
    final Lease lease = fetchLease(leaseReference);
    final Party debtor = fetchParty(debtorReference);
    final Party creditor = fetchParty(creditorReference);
    if (bankMandate == null) {
        lease.newMandate(bankAccount, reference, startDate, endDate);
        bankMandate = lease.getPaidBy();
        bankMandate.setName(name);
    // EST-467, previously was:
    // bankMandate = bankMandates.newBankMandate(reference, name,
    // startDate, endDate, debtor, creditor, bankAccount);
    }
    // upsert
    bankMandate.setBankAccount(bankAccount);
    bankMandate.setName(name);
    bankMandate.setStartDate(startDate);
    bankMandate.setEndDate(endDate);
    bankMandate.setSepaMandateIdentifier(sepaMandateIdentifier);
    lease.paidBy(bankMandate);
}
Also used : ApplicationException(org.apache.isis.applib.ApplicationException) BankAccount(org.estatio.dom.financial.bankaccount.BankAccount) BankMandate(org.estatio.dom.bankmandate.BankMandate)

Aggregations

ApplicationException (org.apache.isis.applib.ApplicationException)1 BankMandate (org.estatio.dom.bankmandate.BankMandate)1 BankAccount (org.estatio.dom.financial.bankaccount.BankAccount)1