Search in sources :

Example 1 with PaymentLine

use of org.estatio.module.capex.dom.payment.PaymentLine 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 PaymentLine

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

the class EstatioAppHomePage method findIncomingInvoicesWithin.

private List<IncomingInvoice> findIncomingInvoicesWithin(final List<PaymentBatch> batches) {
    final List<IncomingInvoice> invoices = Lists.newArrayList();
    for (PaymentBatch completedBatch : batches) {
        invoices.addAll(Lists.newArrayList(completedBatch.getLines()).stream().map(PaymentLine::getInvoice).collect(Collectors.toList()));
    }
    invoices.sort(Ordering.natural().nullsLast().onResultOf(IncomingInvoice::getInvoiceDate));
    return invoices;
}
Also used : IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) PaymentBatch(org.estatio.module.capex.dom.payment.PaymentBatch) PaymentLine(org.estatio.module.capex.dom.payment.PaymentLine)

Example 3 with PaymentLine

use of org.estatio.module.capex.dom.payment.PaymentLine 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 PaymentLine

use of org.estatio.module.capex.dom.payment.PaymentLine 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)

Example 5 with PaymentLine

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

the class IncomingInvoice_reject method act.

@Action(domainEvent = IncomingInvoice_next.ActionDomainEvent.class, semantics = SemanticsOf.IDEMPOTENT)
@ActionLayout(cssClassFa = "fa-thumbs-o-down", cssClass = "btn-warning")
public Object act(final String role, @Nullable final Person personToAssignNextTo, final String reason) {
    final List<PaymentLine> paymentLines = paymentLineRepository.findByInvoice(incomingInvoice);
    // because of the disableXxx guard, this should return either 0 or 1 lines.
    for (PaymentLine paymentLine : paymentLines) {
        final PaymentBatch paymentBatch = paymentLine.getBatch();
        paymentBatch.removeLineFor(incomingInvoice);
    }
    trigger(personToAssignNextTo, reason, reason);
    return objectToReturn();
}
Also used : PaymentLine(org.estatio.module.capex.dom.payment.PaymentLine) PaymentBatch(org.estatio.module.capex.dom.payment.PaymentBatch) Action(org.apache.isis.applib.annotation.Action) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

Aggregations

PaymentLine (org.estatio.module.capex.dom.payment.PaymentLine)6 IncomingInvoice (org.estatio.module.capex.dom.invoice.IncomingInvoice)4 PaymentBatch (org.estatio.module.capex.dom.payment.PaymentBatch)4 CreditTransfer (org.estatio.module.capex.dom.payment.CreditTransfer)3 Action (org.apache.isis.applib.annotation.Action)2 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