Search in sources :

Example 21 with IncomingInvoice

use of org.estatio.module.capex.dom.invoice.IncomingInvoice 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 22 with IncomingInvoice

use of org.estatio.module.capex.dom.invoice.IncomingInvoice in project estatio by estatio.

the class IncomingInvoiceMenu_Test method filterOrFindByGrossAmount_filter_works.

@Test
public void filterOrFindByGrossAmount_filter_works() {
    IncomingInvoiceMenu.IncomingInvoiceFinder builder;
    // given
    builder = new IncomingInvoiceMenu.IncomingInvoiceFinder(mockInvoiceRepository, mockIncomingInvoiceRepository, mockPartyRepository);
    IncomingInvoice invoice1 = new IncomingInvoice();
    invoice1.setGrossAmount(new BigDecimal("9.50"));
    IncomingInvoice invoice2 = new IncomingInvoice();
    invoice2.setGrossAmount(new BigDecimal("9.49"));
    builder.setResult(Arrays.asList(invoice1, invoice2));
    final BigDecimal amountSearchedFor = new BigDecimal("10.00");
    Assertions.assertThat(builder.getResult().size()).isEqualTo(2);
    // when
    builder.filterOrFindByGrossAmount(amountSearchedFor);
    // then
    Assertions.assertThat(builder.getResult().size()).isEqualTo(1);
    Assertions.assertThat(builder.getResult()).contains(invoice1);
}
Also used : IncomingInvoiceMenu(org.estatio.module.capex.app.IncomingInvoiceMenu) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 23 with IncomingInvoice

use of org.estatio.module.capex.dom.invoice.IncomingInvoice in project estatio by estatio.

the class IncomingInvoiceMenu_Test method filterOrFindInvoiceDate_find_works.

@Test
public void filterOrFindInvoiceDate_find_works() {
    IncomingInvoiceMenu.IncomingInvoiceFinder builder;
    // given
    builder = new IncomingInvoiceMenu.IncomingInvoiceFinder(mockInvoiceRepository, mockIncomingInvoiceRepository, mockPartyRepository);
    IncomingInvoice invoice1 = new IncomingInvoice();
    IncomingInvoice invoice2 = new IncomingInvoice();
    IncomingInvoice invoice3 = new IncomingInvoice();
    invoice1.setInvoiceDate(new LocalDate(2017, 7, 15));
    invoice2.setInvoiceDate(new LocalDate(2017, 7, 5));
    invoice3.setInvoiceDate(new LocalDate(2017, 7, 16));
    final LocalDate dateSearchedFor = new LocalDate(2017, 7, 10);
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockIncomingInvoiceRepository).listAll();
            will(returnValue(Arrays.asList(invoice1, invoice2, invoice3)));
        }
    });
    // when
    builder.filterOrFindByInvoiceDate(dateSearchedFor);
    // then
    Assertions.assertThat(builder.getResult().size()).isEqualTo(2);
    Assertions.assertThat(builder.getResult()).contains(invoice1);
    Assertions.assertThat(builder.getResult()).contains(invoice2);
}
Also used : Expectations(org.jmock.Expectations) IncomingInvoiceMenu(org.estatio.module.capex.app.IncomingInvoiceMenu) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) LocalDate(org.joda.time.LocalDate) Test(org.junit.Test)

Example 24 with IncomingInvoice

use of org.estatio.module.capex.dom.invoice.IncomingInvoice 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 25 with IncomingInvoice

use of org.estatio.module.capex.dom.invoice.IncomingInvoice in project estatio by estatio.

the class UpcomingPaymentService_Test method getUpcomingPayments_works_when_no_bankAccount_found.

@Test
public void getUpcomingPayments_works_when_no_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);
    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(null));
        }
    });
    // when
    List<UpcomingPaymentTotal> result = service.getUpcomingPayments();
    // then
    assertThat(result.size()).isEqualTo(1);
    UpcomingPaymentTotal totalWithoutBankAccount = result.get(0);
    assertThat(totalWithoutBankAccount.getDebtorBankAccount()).isNull();
    assertThat(totalWithoutBankAccount.getUpcomingAmountForCompleted()).isEqualTo(amountForCompleted);
    assertThat(totalWithoutBankAccount.getUpcomingAmountForApprovedByManager()).isEqualTo(amountForApproved);
    assertThat(totalWithoutBankAccount.getUpcomingAmountForPendingBankAccountCheck()).isEqualTo(amountForPending);
    assertThat(totalWithoutBankAccount.getTotalUpcomingAmount()).isEqualTo(new BigDecimal("4234.56"));
}
Also used : Expectations(org.jmock.Expectations) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) UpcomingPaymentTotal(org.estatio.module.capex.app.invoice.UpcomingPaymentTotal) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

IncomingInvoice (org.estatio.module.capex.dom.invoice.IncomingInvoice)57 Test (org.junit.Test)27 Expectations (org.jmock.Expectations)20 BankAccount (org.estatio.module.financial.dom.BankAccount)14 Action (org.apache.isis.applib.annotation.Action)11 BigDecimal (java.math.BigDecimal)9 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)9 Organisation (org.estatio.module.party.dom.Organisation)9 Party (org.estatio.module.party.dom.Party)9 IncomingInvoiceMenu (org.estatio.module.capex.app.IncomingInvoiceMenu)8 IncomingInvoiceItem (org.estatio.module.capex.dom.invoice.IncomingInvoiceItem)7 Document (org.incode.module.document.dom.impl.docs.Document)7 LocalDate (org.joda.time.LocalDate)7 ArrayList (java.util.ArrayList)5 Programmatic (org.apache.isis.applib.annotation.Programmatic)5 Property (org.estatio.module.asset.dom.Property)3 UpcomingPaymentTotal (org.estatio.module.capex.app.invoice.UpcomingPaymentTotal)3 BuyerFinder (org.estatio.module.capex.dom.documents.BuyerFinder)3 IncomingInvoiceApprovalStateTransition (org.estatio.module.capex.dom.invoice.approval.IncomingInvoiceApprovalStateTransition)3 OrderItem (org.estatio.module.capex.dom.order.OrderItem)3