Search in sources :

Example 16 with BankAccount

use of org.estatio.module.financial.dom.BankAccount in project estatio by estatio.

the class BankMandate_Test method changeBankAccount.

@Test
public void changeBankAccount() throws Exception {
    // given
    final BankMandate bankMandate = new BankMandate();
    final BankAccount bankAccount = new BankAccount();
    bankMandate.setBankAccount(bankAccount);
    // when
    final BankAccount newBankAccount = new BankAccount();
    bankMandate.changeBankAccount(newBankAccount);
    // then
    assertThat(bankMandate.getBankAccount()).isSameAs(newBankAccount);
}
Also used : BankAccount(org.estatio.module.financial.dom.BankAccount) Test(org.junit.Test)

Example 17 with BankAccount

use of org.estatio.module.financial.dom.BankAccount in project estatio by estatio.

the class TaskIncomingDocumentPdfService method doLookupPdfFor.

private Blob doLookupPdfFor(final Task task) {
    StateTransition<?, ?, ?, ?> stateTransition = stateTransitionService.findFor(task);
    if (stateTransition == null) {
        return null;
    }
    if (stateTransition instanceof IncomingDocumentCategorisationStateTransition) {
        IncomingDocumentCategorisationStateTransition idcst = (IncomingDocumentCategorisationStateTransition) stateTransition;
        final Document document = idcst.getDocument();
        if (document == null) {
            return null;
        }
        if (!Objects.equals(document.getMimeType(), "application/pdf")) {
            return null;
        }
        return document.getBlob();
    }
    if (stateTransition instanceof OrderApprovalStateTransition) {
        final OrderApprovalStateTransition oast = (OrderApprovalStateTransition) stateTransition;
        final Order order = oast.getOrdr();
        final Optional<Document> documentIfAny = lookupAttachedPdfService.lookupOrderPdfFrom(order);
        return documentIfAny.map(DocumentAbstract::getBlob).orElse(null);
    }
    if (stateTransition instanceof IncomingInvoiceApprovalStateTransition) {
        final IncomingInvoiceApprovalStateTransition iiast = (IncomingInvoiceApprovalStateTransition) stateTransition;
        final IncomingInvoice invoice = iiast.getInvoice();
        final Optional<Document> documentIfAny = lookupAttachedPdfService.lookupIncomingInvoicePdfFrom(invoice);
        return documentIfAny.map(DocumentAbstract::getBlob).orElse(null);
    }
    if (stateTransition instanceof BankAccountVerificationStateTransition) {
        final BankAccountVerificationStateTransition bavst = (BankAccountVerificationStateTransition) stateTransition;
        final BankAccount bankAccount = bavst.getBankAccount();
        final Optional<Document> documentIfAny = lookupAttachedPdfService.lookupIbanProofPdfFrom(bankAccount);
        return documentIfAny.map(DocumentAbstract::getBlob).orElse(null);
    }
    return null;
}
Also used : Order(org.estatio.module.capex.dom.order.Order) IncomingInvoiceApprovalStateTransition(org.estatio.module.capex.dom.invoice.approval.IncomingInvoiceApprovalStateTransition) IncomingDocumentCategorisationStateTransition(org.estatio.module.capex.dom.documents.categorisation.IncomingDocumentCategorisationStateTransition) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) BankAccount(org.estatio.module.financial.dom.BankAccount) Document(org.incode.module.document.dom.impl.docs.Document) OrderApprovalStateTransition(org.estatio.module.capex.dom.order.approval.OrderApprovalStateTransition) BankAccountVerificationStateTransition(org.estatio.module.capex.dom.bankaccount.verification.BankAccountVerificationStateTransition)

Example 18 with BankAccount

use of org.estatio.module.financial.dom.BankAccount in project estatio by estatio.

the class UpcomingPaymentService_Test method getUpcomingPayments_works_when_bankAccount_found.

@Test
public void getUpcomingPayments_works_when_bankAccount_found() throws Exception {
    // given
    UpcomingPaymentService service = new UpcomingPaymentService();
    service.incomingInvoiceRepository = mockIncomingInvoiceRepository;
    service.debtorBankAccountService = mockDebtorBankAccountService;
    IncomingInvoice completedInvoice = new IncomingInvoice();
    completedInvoice.setApprovalState(IncomingInvoiceApprovalState.COMPLETED);
    final BigDecimal amountForCompleted = new BigDecimal("1234.56");
    completedInvoice.setGrossAmount(amountForCompleted);
    IncomingInvoice approvedInvoice = new IncomingInvoice();
    approvedInvoice.setApprovalState(IncomingInvoiceApprovalState.APPROVED);
    final BigDecimal amountForApproved = new BigDecimal("1000.00");
    approvedInvoice.setGrossAmount(amountForApproved);
    BankAccount bankAccountForPending = new BankAccount();
    IncomingInvoice pendingInvoice = new IncomingInvoice();
    pendingInvoice.setApprovalState(IncomingInvoiceApprovalState.PENDING_BANK_ACCOUNT_CHECK);
    final BigDecimal amountForPending = new BigDecimal("2000.00");
    pendingInvoice.setGrossAmount(amountForPending);
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockIncomingInvoiceRepository).findByApprovalStateAndPaymentMethod(IncomingInvoiceApprovalState.COMPLETED, PaymentMethod.BANK_TRANSFER);
            will(returnValue(Arrays.asList(completedInvoice)));
            oneOf(mockIncomingInvoiceRepository).findByApprovalStateAndPaymentMethod(IncomingInvoiceApprovalState.APPROVED, PaymentMethod.BANK_TRANSFER);
            will(returnValue(Arrays.asList(approvedInvoice)));
            oneOf(mockIncomingInvoiceRepository).findByApprovalStateAndPaymentMethod(IncomingInvoiceApprovalState.PENDING_BANK_ACCOUNT_CHECK, PaymentMethod.BANK_TRANSFER);
            will(returnValue(Arrays.asList(pendingInvoice)));
            allowing(mockDebtorBankAccountService).uniqueDebtorAccountToPay(completedInvoice);
            will(returnValue(null));
            allowing(mockDebtorBankAccountService).uniqueDebtorAccountToPay(approvedInvoice);
            will(returnValue(null));
            allowing(mockDebtorBankAccountService).uniqueDebtorAccountToPay(pendingInvoice);
            will(returnValue(bankAccountForPending));
        }
    });
    // when
    List<UpcomingPaymentTotal> result = service.getUpcomingPayments();
    // then
    assertThat(result.size()).isEqualTo(2);
    UpcomingPaymentTotal totalWithoutBankAccount = result.get(0);
    assertThat(totalWithoutBankAccount.getDebtorBankAccount()).isNull();
    assertThat(totalWithoutBankAccount.getUpcomingAmountForCompleted()).isEqualTo(amountForCompleted);
    assertThat(totalWithoutBankAccount.getUpcomingAmountForApprovedByManager()).isEqualTo(amountForApproved);
    assertThat(totalWithoutBankAccount.getUpcomingAmountForPendingBankAccountCheck()).isNull();
    assertThat(totalWithoutBankAccount.getTotalUpcomingAmount()).isEqualTo(new BigDecimal("2234.56"));
    UpcomingPaymentTotal totalWithBankAccount = result.get(1);
    assertThat(totalWithBankAccount.getDebtorBankAccount()).isEqualTo(bankAccountForPending);
    assertThat(totalWithBankAccount.getUpcomingAmountForCompleted()).isNull();
    assertThat(totalWithBankAccount.getUpcomingAmountForApprovedByManager()).isNull();
    assertThat(totalWithBankAccount.getUpcomingAmountForPendingBankAccountCheck()).isEqualTo(amountForPending);
    assertThat(totalWithBankAccount.getTotalUpcomingAmount()).isEqualTo(amountForPending);
}
Also used : Expectations(org.jmock.Expectations) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) BankAccount(org.estatio.module.financial.dom.BankAccount) UpcomingPaymentTotal(org.estatio.module.capex.app.invoice.UpcomingPaymentTotal) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 19 with BankAccount

use of org.estatio.module.financial.dom.BankAccount in project estatio by estatio.

the class IncomingDocAsInvoiceViewModel_Test method bankaccount_is_set_when_creating_seller.

@Test
public void bankaccount_is_set_when_creating_seller() {
    // given
    IncomingDocAsInvoiceViewModel viewModel = new IncomingDocAsInvoiceViewModel();
    viewModel.organisationRepository = mockOrganisationRepo;
    viewModel.bankAccountRepository = mockBankAccountRepository;
    Country country = new Country();
    Organisation seller = new Organisation();
    BankAccount bankAccount = new BankAccount();
    String sellerName = "some name";
    OrganisationNameNumberViewModel candidate = new OrganisationNameNumberViewModel(sellerName, null);
    String iban = "NL02RABO0313246581";
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockOrganisationRepo).newOrganisation(null, true, sellerName, country);
            will(returnValue(seller));
            oneOf(mockBankAccountRepository).newBankAccount(seller, iban, null);
            will(returnValue(bankAccount));
            oneOf(mockBankAccountRepository).getFirstBankAccountOfPartyOrNull(seller);
            will(returnValue(bankAccount));
        }
    });
    // when
    viewModel.createSeller(candidate, country, iban);
    // then
    Assertions.assertThat(viewModel.getSeller()).isEqualTo(seller);
    Assertions.assertThat(viewModel.getBankAccount()).isEqualTo(bankAccount);
}
Also used : OrganisationNameNumberViewModel(org.estatio.module.party.app.services.OrganisationNameNumberViewModel) Expectations(org.jmock.Expectations) Organisation(org.estatio.module.party.dom.Organisation) Country(org.incode.module.country.dom.impl.Country) BankAccount(org.estatio.module.financial.dom.BankAccount) Test(org.junit.Test)

Example 20 with BankAccount

use of org.estatio.module.financial.dom.BankAccount in project estatio by estatio.

the class IncomingDocAsInvoiceViewModel_autoCompleteBankAccount_Test method autoCompleteBankAccount_works.

@Test
public void autoCompleteBankAccount_works() throws Exception {
    List<BankAccount> result;
    // given
    IncomingDocAsInvoiceViewModel vm = new IncomingDocAsInvoiceViewModel() {

        IncomingDocAsInvoiceViewModel setBankAccountRepository(BankAccountRepository bankAccountRepository) {
            this.bankAccountRepository = bankAccountRepository;
            return this;
        }
    }.setBankAccountRepository(mockBankAccountRepository);
    BankAccount acc1 = new BankAccount();
    BankAccount acc2 = new BankAccount();
    Party owner = new Organisation();
    acc2.setOwner(owner);
    // expect
    context.checking(new Expectations() {

        {
            allowing(mockBankAccountRepository).autoComplete(with(any(String.class)));
            will(returnValue(Arrays.asList(acc1, acc2)));
            oneOf(mockBankAccountRepository).findBankAccountsByOwner(owner);
            will(returnValue(Arrays.asList(acc2)));
        }
    });
    // when
    result = vm.autoCompleteBankAccount("some searchstring");
    // then
    assertThat(result.size()).isEqualTo(2);
    // and when seller is set
    vm.setSeller(owner);
    result = vm.autoCompleteBankAccount("3");
    // then
    assertThat(result.size()).isEqualTo(1);
    assertThat(result.get(0)).isEqualTo(acc2);
}
Also used : Expectations(org.jmock.Expectations) Party(org.estatio.module.party.dom.Party) Organisation(org.estatio.module.party.dom.Organisation) BankAccount(org.estatio.module.financial.dom.BankAccount) BankAccountRepository(org.estatio.module.financial.dom.BankAccountRepository) Test(org.junit.Test)

Aggregations

BankAccount (org.estatio.module.financial.dom.BankAccount)37 IncomingInvoice (org.estatio.module.capex.dom.invoice.IncomingInvoice)14 Test (org.junit.Test)13 Party (org.estatio.module.party.dom.Party)12 Programmatic (org.apache.isis.applib.annotation.Programmatic)11 Expectations (org.jmock.Expectations)9 Organisation (org.estatio.module.party.dom.Organisation)7 ArrayList (java.util.ArrayList)5 Action (org.apache.isis.applib.annotation.Action)4 Property (org.estatio.module.asset.dom.Property)4 BankAccountVerificationStateTransition (org.estatio.module.capex.dom.bankaccount.verification.BankAccountVerificationStateTransition)4 FinancialAccount (org.estatio.module.financial.dom.FinancialAccount)4 BigDecimal (java.math.BigDecimal)3 List (java.util.List)3 IncomingInvoiceApprovalStateTransition (org.estatio.module.capex.dom.invoice.approval.IncomingInvoiceApprovalStateTransition)3 Inject (javax.inject.Inject)2 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)2 Blob (org.apache.isis.applib.value.Blob)2 FixedAssetFinancialAccount (org.estatio.module.assetfinancial.dom.FixedAssetFinancialAccount)2 BankMandate (org.estatio.module.bankmandate.dom.BankMandate)2