Search in sources :

Example 1 with CreditTransfer

use of org.estatio.module.capex.dom.payment.CreditTransfer in project estatio by estatio.

the class PaymentBatchManager method removeNegativeTransfers.

/**
 * Removes (deletes) all {@link PaymentLine line}s that correspond to a transfer which is a net negative.
 */
private void removeNegativeTransfers(PaymentBatch paymentBatch) {
    final List<PaymentLine> paymentLines = paymentBatch.getTransfers().stream().filter(x -> x.getAmount().compareTo(BigDecimal.ZERO) <= 0).map(CreditTransfer::getLines).flatMap(Collection::stream).collect(Collectors.toList());
    // seems to be necessary to flush everything through both before and after, presumably to deal with the
    // dependent collection (else get DN error about having added a deleted object to the batch's lines collection)
    flushTransaction();
    // this is sufficient, because PaymentBatch#lines is a dependent collection
    for (PaymentLine paymentLine : paymentLines) {
        paymentBatch.getLines().remove(paymentLine);
    }
    // see discussion above.
    flushTransaction();
    if (paymentBatch.getLines().isEmpty()) {
        paymentBatch.remove();
    }
}
Also used : Clob(org.apache.isis.applib.value.Clob) Nature(org.apache.isis.applib.annotation.Nature) PaymentBatch_complete(org.estatio.module.capex.dom.payment.approval.triggers.PaymentBatch_complete) Setter(lombok.Setter) Getter(lombok.Getter) WrapperFactory(org.apache.isis.applib.services.wrapper.WrapperFactory) BankAccountRepository(org.estatio.module.financial.dom.BankAccountRepository) PaymentMethod(org.estatio.module.invoice.dom.PaymentMethod) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) BigDecimal(java.math.BigDecimal) CreditTransfer(org.estatio.module.capex.dom.payment.CreditTransfer) Lists(com.google.common.collect.Lists) AccessLevel(lombok.AccessLevel) BankAccount(org.estatio.module.financial.dom.BankAccount) FactoryService(org.apache.isis.applib.services.factory.FactoryService) Nullable(javax.annotation.Nullable) Blob(org.apache.isis.applib.value.Blob) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) Action(org.apache.isis.applib.annotation.Action) PaymentBatchRepository(org.estatio.module.capex.dom.payment.PaymentBatchRepository) IsisJdoSupport(org.apache.isis.applib.services.jdosupport.IsisJdoSupport) IncomingInvoiceRepository(org.estatio.module.capex.dom.invoice.IncomingInvoiceRepository) DebtorBankAccountService(org.estatio.module.capex.app.DebtorBankAccountService) ServiceRegistry2(org.apache.isis.applib.services.registry.ServiceRegistry2) Collection(java.util.Collection) DateTime(org.joda.time.DateTime) PaymentBatch(org.estatio.module.capex.dom.payment.PaymentBatch) IncomingInvoiceApprovalState(org.estatio.module.capex.dom.invoice.approval.IncomingInvoiceApprovalState) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) MemberOrder(org.apache.isis.applib.annotation.MemberOrder) LocalDate(org.joda.time.LocalDate) SemanticsOf(org.apache.isis.applib.annotation.SemanticsOf) PaymentLine(org.estatio.module.capex.dom.payment.PaymentLine) List(java.util.List) DomainObject(org.apache.isis.applib.annotation.DomainObject) CommandPersistence(org.apache.isis.applib.annotation.CommandPersistence) TransactionService(org.apache.isis.applib.services.xactn.TransactionService) ParameterLayout(org.apache.isis.applib.annotation.ParameterLayout) PaymentLineForExcelExportV1(org.estatio.module.capex.app.paymentline.PaymentLineForExcelExportV1) InvoicePageRange(org.estatio.module.capex.dom.util.InvoicePageRange) Collections(java.util.Collections) Publishing(org.apache.isis.applib.annotation.Publishing) ExcelService(org.isisaddons.module.excel.dom.ExcelService) CreditTransfer(org.estatio.module.capex.dom.payment.CreditTransfer) PaymentLine(org.estatio.module.capex.dom.payment.PaymentLine)

Example 2 with CreditTransfer

use of org.estatio.module.capex.dom.payment.CreditTransfer in project estatio by estatio.

the class CreditTransferExportService_Test method isFirstUseBankAccount_works_when_no_incoming_invoices_found_for_bank_account.

@Test
public void isFirstUseBankAccount_works_when_no_incoming_invoices_found_for_bank_account() throws Exception {
    // given
    CreditTransferExportService service = new CreditTransferExportService();
    service.incomingInvoiceRepository = mockIncomingInvoiceRepository;
    CreditTransfer transfer = new CreditTransfer();
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockIncomingInvoiceRepository).findByBankAccount(transfer.getSellerBankAccount());
            // when
            will(returnValue(Arrays.asList()));
        }
    });
    // then
    Assertions.assertThat(service.isFirstUseBankAccount(transfer)).isTrue();
}
Also used : Expectations(org.jmock.Expectations) CreditTransfer(org.estatio.module.capex.dom.payment.CreditTransfer) Test(org.junit.Test)

Example 3 with CreditTransfer

use of org.estatio.module.capex.dom.payment.CreditTransfer in project estatio by estatio.

the class CreditTransferExportService_Test method isFirstUseBankAccount_works_when_just_invoices_in_transfer_found.

@Test
public void isFirstUseBankAccount_works_when_just_invoices_in_transfer_found() throws Exception {
    // given
    CreditTransferExportService service = new CreditTransferExportService();
    service.incomingInvoiceRepository = mockIncomingInvoiceRepository;
    CreditTransfer transfer = new CreditTransfer();
    // when
    IncomingInvoice invoiceInPaymentLine1 = new IncomingInvoice();
    IncomingInvoice invoiceInPaymentLine2 = new IncomingInvoice();
    PaymentLine line1 = new PaymentLine();
    line1.setInvoice(invoiceInPaymentLine1);
    PaymentLine line2 = new PaymentLine();
    line2.setInvoice(invoiceInPaymentLine2);
    transfer.setLines(Arrays.asList(line1, line2));
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockIncomingInvoiceRepository).findByBankAccount(transfer.getSellerBankAccount());
            // when ..
            will(returnValue(Arrays.asList(invoiceInPaymentLine1, invoiceInPaymentLine2)));
        }
    });
    // then
    Assertions.assertThat(service.isFirstUseBankAccount(transfer)).isTrue();
}
Also used : Expectations(org.jmock.Expectations) CreditTransfer(org.estatio.module.capex.dom.payment.CreditTransfer) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) PaymentLine(org.estatio.module.capex.dom.payment.PaymentLine) Test(org.junit.Test)

Example 4 with CreditTransfer

use of org.estatio.module.capex.dom.payment.CreditTransfer in project estatio by estatio.

the class CreditTransferExportService_Test method isFirstUseBankAccount_works_when_other_invoices_than_in_transfer_found.

@Test
public void isFirstUseBankAccount_works_when_other_invoices_than_in_transfer_found() throws Exception {
    // given
    CreditTransferExportService service = new CreditTransferExportService();
    service.incomingInvoiceRepository = mockIncomingInvoiceRepository;
    CreditTransfer transfer = new CreditTransfer();
    // when
    IncomingInvoice invoiceInPaymentLine1 = new IncomingInvoice();
    IncomingInvoice invoiceInPaymentLine2 = new IncomingInvoice();
    PaymentLine line1 = new PaymentLine();
    line1.setInvoice(invoiceInPaymentLine1);
    PaymentLine line2 = new PaymentLine();
    line2.setInvoice(invoiceInPaymentLine2);
    transfer.setLines(Arrays.asList(line1, line2));
    IncomingInvoice otherInvoice = new IncomingInvoice();
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockIncomingInvoiceRepository).findByBankAccount(transfer.getSellerBankAccount());
            // when ..
            will(returnValue(Arrays.asList(invoiceInPaymentLine1, invoiceInPaymentLine2, otherInvoice)));
        }
    });
    // then
    Assertions.assertThat(service.isFirstUseBankAccount(transfer)).isFalse();
}
Also used : Expectations(org.jmock.Expectations) CreditTransfer(org.estatio.module.capex.dom.payment.CreditTransfer) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) PaymentLine(org.estatio.module.capex.dom.payment.PaymentLine) Test(org.junit.Test)

Aggregations

CreditTransfer (org.estatio.module.capex.dom.payment.CreditTransfer)4 IncomingInvoice (org.estatio.module.capex.dom.invoice.IncomingInvoice)3 PaymentLine (org.estatio.module.capex.dom.payment.PaymentLine)3 Expectations (org.jmock.Expectations)2 Test (org.junit.Test)2 Lists (com.google.common.collect.Lists)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 Inject (javax.inject.Inject)1 AccessLevel (lombok.AccessLevel)1 Getter (lombok.Getter)1 Setter (lombok.Setter)1 Action (org.apache.isis.applib.annotation.Action)1 CommandPersistence (org.apache.isis.applib.annotation.CommandPersistence)1