Search in sources :

Example 36 with IncomingInvoice

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

the class IncomingInvoiceMenu_Test method filterOrFindByGrossAmount_negative_amounts_filter_works.

@Test
public void filterOrFindByGrossAmount_negative_amounts_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 37 with IncomingInvoice

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

the class IncomingInvoiceMenu_Test method filterOrFindBySeller_filter_works.

@Test
public void filterOrFindBySeller_filter_works() {
    IncomingInvoiceMenu.IncomingInvoiceFinder builder;
    // given
    builder = new IncomingInvoiceMenu.IncomingInvoiceFinder(mockInvoiceRepository, mockIncomingInvoiceRepository, mockPartyRepository);
    IncomingInvoice invoice1 = new IncomingInvoice();
    Person personToBeFiltered = new Person();
    Organisation seller = new Organisation();
    invoice1.setSeller(seller);
    IncomingInvoice invoice2 = new IncomingInvoice();
    builder.setResult(Arrays.asList(invoice1, invoice2));
    Assertions.assertThat(builder.getResult().size()).isEqualTo(2);
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockPartyRepository).findParties("*abc*");
            will(returnValue(Arrays.asList(seller, personToBeFiltered)));
        }
    });
    // when
    builder.filterOrFindBySeller("abc");
    // then
    Assertions.assertThat(builder.getResult().size()).isEqualTo(1);
}
Also used : Expectations(org.jmock.Expectations) IncomingInvoiceMenu(org.estatio.module.capex.app.IncomingInvoiceMenu) Organisation(org.estatio.module.party.dom.Organisation) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) Person(org.estatio.module.party.dom.Person) Test(org.junit.Test)

Example 38 with IncomingInvoice

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

the class PaymentBatch_Test method newInvoice.

IncomingInvoice newInvoice(final LocalDate invoiceDate, final Party seller, final BankAccount sellerBankAccount, final String currencyRef, final String grossAmount, final String invoiceNumber) {
    final IncomingInvoice invoice = new IncomingInvoice();
    invoice.setInvoiceDate(invoiceDate);
    invoice.setSeller(seller);
    invoice.setBankAccount(sellerBankAccount);
    invoice.setGrossAmount(new BigDecimal(grossAmount));
    invoice.setInvoiceNumber(invoiceNumber);
    final Currency currency = new Currency();
    currency.setReference(currencyRef);
    invoice.setCurrency(currency);
    return invoice;
}
Also used : Currency(org.estatio.module.currency.dom.Currency) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) BigDecimal(java.math.BigDecimal)

Example 39 with IncomingInvoice

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

the class PaymentBatch_Test method aggregates_transfers_ok.

@Test
public void aggregates_transfers_ok() throws Exception {
    // given
    final IncomingInvoice invoice1 = newInvoice(new LocalDate(2017, 7, 7), seller1, seller1BankAccount, "EUR", "361754.46", "AF3T2017");
    final IncomingInvoice invoice2 = newInvoice(new LocalDate(2017, 6, 30), seller2, seller2BankAccount, "EUR", "15251.76", "DGD 11420 - 170522");
    final IncomingInvoice invoice3 = newInvoice(new LocalDate(2017, 6, 5), seller1, seller1BankAccount, "EUR", "-172805.79", "REDD2016VT");
    // sequence = 1
    paymentBatch.addLineIfRequired(invoice1);
    // sequence = 2
    paymentBatch.addLineIfRequired(invoice2);
    // sequence = 3
    paymentBatch.addLineIfRequired(invoice3);
    // then
    List<CreditTransfer> transfers = paymentBatch.getTransfers();
    assertThat(transfers).hasSize(2);
    final CreditTransfer transfer1 = transfers.get(0);
    final CreditTransfer transfer2 = transfers.get(1);
    assertThat(transfer1.getBatch()).isEqualTo(paymentBatch);
    assertThat(transfer1.getSellerName()).isEqualTo(seller1.getName());
    assertThat(transfer1.getAmount()).isEqualTo(invoice1.getGrossAmount().add(invoice3.getGrossAmount()));
    // the "1-3" suffix indicates payment lines with sequence 1 and 3 together
    assertThat(transfer1.getEndToEndId()).isEqualTo("97834-1-3");
    assertThat(transfer1.getRemittanceInformation()).isEqualTo("AF3T2017;REDD2016VT");
    assertThat(transfer1.getSellerBankAccount()).isEqualTo(seller1BankAccount);
    assertThat(transfer1.getSellerBic()).isEqualTo(seller1BankAccount.getBic());
    assertThat(transfer1.getSellerIban()).isEqualTo(seller1BankAccount.getIban());
    assertThat(transfer1.getSellerPostalAddressCountry()).isEqualTo("FR");
    assertThat(transfer2.getBatch()).isEqualTo(paymentBatch);
    assertThat(transfer2.getSellerName()).isEqualTo(seller2.getName());
    assertThat(transfer2.getAmount()).isEqualTo(invoice2.getGrossAmount());
    assertThat(transfer2.getEndToEndId()).isEqualTo("97834-2");
    assertThat(transfer2.getRemittanceInformation()).isEqualTo("DGD 11420 - 170522");
    assertThat(transfer2.getSellerBankAccount()).isEqualTo(seller2BankAccount);
    assertThat(transfer2.getSellerBic()).isEqualTo(seller2BankAccount.getBic());
    assertThat(transfer2.getSellerIban()).isEqualTo(seller2BankAccount.getIban());
    assertThat(transfer2.getSellerPostalAddressCountry()).isEqualTo("FR");
    // and also
    final CreditTransferTransactionInformation10 cdtTrf1 = transfer1.asXml();
    assertThat(cdtTrf1.getCdtr().getNm()).isEqualTo(transfer1.getSellerName());
    assertThat(cdtTrf1.getAmt().getInstdAmt().getValue()).isEqualTo(transfer1.getAmount());
    assertThat(cdtTrf1.getAmt().getInstdAmt().getCcy()).isEqualTo("EUR");
    assertThat(cdtTrf1.getPmtId().getEndToEndId()).isEqualTo(transfer1.getEndToEndId());
    assertThat(cdtTrf1.getRmtInf().getUstrds().get(0)).isEqualTo(transfer1.getRemittanceInformation());
    assertThat(cdtTrf1.getCdtrAgt().getFinInstnId().getBIC()).isEqualTo(transfer1.getSellerBic());
    assertThat(cdtTrf1.getCdtrAcct().getId().getIBAN()).isEqualTo(transfer1.getSellerIban());
    assertThat(cdtTrf1.getCdtr().getPstlAdr().getCtry()).isEqualTo(transfer1.getSellerPostalAddressCountry());
}
Also used : CreditTransferTransactionInformation10(iso.std.iso._20022.tech.xsd.pain_001_001.CreditTransferTransactionInformation10) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) LocalDate(org.joda.time.LocalDate) Test(org.junit.Test)

Example 40 with IncomingInvoice

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

the class PaymentLine_Test method getUpstreamCreditNoteFound_works.

@Test
public void getUpstreamCreditNoteFound_works() throws Exception {
    // given
    PaymentLine paymentLine = new PaymentLine();
    paymentLine.incomingInvoiceRepository = mockIncomingInvoiceRepository;
    BankAccount creditorBankAccount = new BankAccount();
    paymentLine.setCreditorBankAccount(creditorBankAccount);
    IncomingInvoice invoice = new IncomingInvoice();
    // expect
    context.checking(new Expectations() {

        {
            allowing(mockIncomingInvoiceRepository).findByBankAccount(creditorBankAccount);
            will(returnValue(Arrays.asList(invoice)));
        }
    });
    // when
    invoice.setApprovalState(IncomingInvoiceApprovalState.COMPLETED);
    invoice.setNetAmount(new BigDecimal("-0.01"));
    // then
    Assertions.assertThat(paymentLine.getUpstreamCreditNoteFound()).isTrue();
    // when approval state gets checked
    invoice.setApprovalState(IncomingInvoiceApprovalState.NEW);
    invoice.setNetAmount(new BigDecimal("-0.01"));
    // then
    Assertions.assertThat(paymentLine.getUpstreamCreditNoteFound()).isFalse();
    // when approval state is null
    invoice.setApprovalState(null);
    invoice.setNetAmount(new BigDecimal("-0.01"));
    // then
    Assertions.assertThat(paymentLine.getUpstreamCreditNoteFound()).isFalse();
    // and when net amount gets checked
    invoice.setApprovalState(IncomingInvoiceApprovalState.COMPLETED);
    invoice.setNetAmount(new BigDecimal("0.01"));
    // then
    Assertions.assertThat(paymentLine.getUpstreamCreditNoteFound()).isFalse();
    // and when net amount is null
    invoice.setApprovalState(IncomingInvoiceApprovalState.COMPLETED);
    invoice.setNetAmount(null);
    // then
    Assertions.assertThat(paymentLine.getUpstreamCreditNoteFound()).isFalse();
}
Also used : Expectations(org.jmock.Expectations) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) BankAccount(org.estatio.module.financial.dom.BankAccount) 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