Search in sources :

Example 1 with FixedAssetFinancialAccount

use of org.estatio.module.assetfinancial.dom.FixedAssetFinancialAccount in project estatio by estatio.

the class BankAccountSubscriptions method on.

@Programmatic
@com.google.common.eventbus.Subscribe
@org.axonframework.eventhandling.annotation.EventHandler
public void on(final BankAccount.RemoveEvent ev) {
    BankAccount sourceBankAccount = ev.getSource();
    List<FixedAssetFinancialAccount> results;
    switch(ev.getEventPhase()) {
        case VALIDATE:
            results = fixedAssetFinancialAccountRepository.findByFinancialAccount(sourceBankAccount);
            if (results.size() > 0) {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append("This bank account is assigned to a fixed asset: remove the bank account from the fixed asset. In use by the following fixed assets: ");
                for (FixedAssetFinancialAccount fixedAssetFinancialAccount : results) {
                    stringBuilder.append(fixedAssetFinancialAccount.getFixedAsset().getName() + "\n");
                }
                ev.invalidate(stringBuilder.toString());
            }
            break;
        default:
            break;
    }
}
Also used : FixedAssetFinancialAccount(org.estatio.module.assetfinancial.dom.FixedAssetFinancialAccount) BankAccount(org.estatio.module.financial.dom.BankAccount) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 2 with FixedAssetFinancialAccount

use of org.estatio.module.assetfinancial.dom.FixedAssetFinancialAccount in project estatio by estatio.

the class DebtorBankAccountService_Test method unique_Debtor_Account_To_Pay_works_when_bankaccounts_and_one_for_property.

@Test
public void unique_Debtor_Account_To_Pay_works_when_bankaccounts_and_one_for_property() throws Exception {
    // given
    DebtorBankAccountService service = new DebtorBankAccountService();
    service.bankAccountRepository = mockBankAccountRepository;
    service.fixedAssetFinancialAccountRepository = mockFixedAssetFinancialAccountRepository;
    BankAccount bankAccount = new BankAccount();
    BankAccount bankAccountForProperty = new BankAccount();
    FixedAssetFinancialAccount fixedAssetFinancialAccount = new FixedAssetFinancialAccount();
    fixedAssetFinancialAccount.setFinancialAccount(bankAccountForProperty);
    List<BankAccount> bankAccounts = new ArrayList<>();
    bankAccounts.add(bankAccount);
    bankAccounts.add(bankAccountForProperty);
    IncomingInvoice invoice = new IncomingInvoice();
    Party debtor = new Organisation();
    invoice.setBuyer(debtor);
    Property property = new Property();
    invoice.setProperty(property);
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockBankAccountRepository).findBankAccountsByOwner(debtor);
            will(returnValue(bankAccounts));
            oneOf(mockFixedAssetFinancialAccountRepository).findByFixedAsset(property);
            will(returnValue(Arrays.asList(fixedAssetFinancialAccount)));
        }
    });
    // when, then
    assertThat(service.uniqueDebtorAccountToPay(invoice)).isEqualTo(bankAccountForProperty);
}
Also used : Expectations(org.jmock.Expectations) FixedAssetFinancialAccount(org.estatio.module.assetfinancial.dom.FixedAssetFinancialAccount) Party(org.estatio.module.party.dom.Party) Organisation(org.estatio.module.party.dom.Organisation) ArrayList(java.util.ArrayList) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) BankAccount(org.estatio.module.financial.dom.BankAccount) Property(org.estatio.module.asset.dom.Property) Test(org.junit.Test)

Example 3 with FixedAssetFinancialAccount

use of org.estatio.module.assetfinancial.dom.FixedAssetFinancialAccount in project estatio by estatio.

the class DebtorBankAccountService method uniqueDebtorAccountToPay.

@Programmatic
public BankAccount uniqueDebtorAccountToPay(final IncomingInvoice invoice) {
    final Party buyer = invoice.getBuyer();
    List<BankAccount> bankAccountsForBuyer = bankAccountRepository.findBankAccountsByOwner(buyer);
    final Property propertyIfAny = invoice.getProperty();
    if (propertyIfAny != null) {
        List<FixedAssetFinancialAccount> fafrList = fixedAssetFinancialAccountRepository.findByFixedAsset(propertyIfAny);
        List<FinancialAccount> bankAccountsForProperty = fafrList.stream().map(FixedAssetFinancialAccount::getFinancialAccount).filter(BankAccount.class::isInstance).map(BankAccount.class::cast).collect(Collectors.toList());
        bankAccountsForBuyer.retainAll(bankAccountsForProperty);
    }
    // original implementation ... see if we already have a unique bank account
    int numBankAccounts = bankAccountsForBuyer.size();
    switch(numBankAccounts) {
        case 0:
            return null;
        case 1:
            return bankAccountsForBuyer.get(0);
        default:
    }
    // see if removing non-preferred helps
    bankAccountsForBuyer.removeIf(x -> (x.getPreferred() == null || !x.getPreferred()));
    numBankAccounts = bankAccountsForBuyer.size();
    switch(numBankAccounts) {
        case 0:
            return null;
        case 1:
            return bankAccountsForBuyer.get(0);
        default:
            // give up, still non-duplicate
            return null;
    }
}
Also used : FixedAssetFinancialAccount(org.estatio.module.assetfinancial.dom.FixedAssetFinancialAccount) Party(org.estatio.module.party.dom.Party) FinancialAccount(org.estatio.module.financial.dom.FinancialAccount) FixedAssetFinancialAccount(org.estatio.module.assetfinancial.dom.FixedAssetFinancialAccount) BankAccount(org.estatio.module.financial.dom.BankAccount) Property(org.estatio.module.asset.dom.Property) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Aggregations

FixedAssetFinancialAccount (org.estatio.module.assetfinancial.dom.FixedAssetFinancialAccount)3 BankAccount (org.estatio.module.financial.dom.BankAccount)3 Programmatic (org.apache.isis.applib.annotation.Programmatic)2 Property (org.estatio.module.asset.dom.Property)2 Party (org.estatio.module.party.dom.Party)2 ArrayList (java.util.ArrayList)1 IncomingInvoice (org.estatio.module.capex.dom.invoice.IncomingInvoice)1 FinancialAccount (org.estatio.module.financial.dom.FinancialAccount)1 Organisation (org.estatio.module.party.dom.Organisation)1 Expectations (org.jmock.Expectations)1 Test (org.junit.Test)1