Search in sources :

Example 1 with PaymentBatch

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

the class PaymentBatchManager method addInvoiceToPayByBankAccount.

@Action(semantics = SemanticsOf.IDEMPOTENT, publishing = Publishing.DISABLED)
public PaymentBatchManager addInvoiceToPayByBankAccount(final IncomingInvoice incomingInvoice, final BankAccount debtorBankAccount) {
    PaymentBatch paymentBatch = paymentBatchRepository.findOrCreateNewByDebtorBankAccount(debtorBankAccount);
    paymentBatch.addLineIfRequired(incomingInvoice);
    return new PaymentBatchManager();
}
Also used : PaymentBatch(org.estatio.module.capex.dom.payment.PaymentBatch) Action(org.apache.isis.applib.annotation.Action)

Example 2 with PaymentBatch

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

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

the class PaymentBatchManager method downloadExcelExportForCompletedBatches.

@Action(semantics = SemanticsOf.SAFE, commandPersistence = CommandPersistence.NOT_PERSISTED, publishing = Publishing.DISABLED)
public Blob downloadExcelExportForCompletedBatches(@Nullable final String documentName, final LocalDate startExecutionDate, final LocalDate endExecutionDate) {
    List<PaymentLineForExcelExportV1> lineVms = new ArrayList<>();
    List<PaymentBatch> batchesToExport = getCompletedBatches().stream().filter(x -> x.getRequestedExecutionDate().toLocalDate().isAfter(startExecutionDate.minusDays(1)) && x.getRequestedExecutionDate().toLocalDate().isBefore(endExecutionDate.plusDays(1))).collect(Collectors.toList());
    for (PaymentBatch batch : batchesToExport) {
        lineVms.addAll(batch.paymentLinesForExcelExport());
    }
    String name = documentName != null ? documentName.concat(".xlsx") : "export.xlsx";
    return excelService.toExcel(lineVms, PaymentLineForExcelExportV1.class, "export", name);
}
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) ArrayList(java.util.ArrayList) PaymentLineForExcelExportV1(org.estatio.module.capex.app.paymentline.PaymentLineForExcelExportV1) PaymentBatch(org.estatio.module.capex.dom.payment.PaymentBatch) Action(org.apache.isis.applib.annotation.Action)

Example 4 with PaymentBatch

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

the class PaymentBatchApprovalStateSubscriber method on.

@Programmatic
@com.google.common.eventbus.Subscribe
@org.axonframework.eventhandling.annotation.EventHandler
public void on(PaymentBatch.ObjectPersistedEvent ev) {
    // nb: note that the batch at this stage has no lines attached to it,
    // so there is a limit as to what we can safely do.
    // however, it *is* ok to just create the state chart for the domain object.
    final PaymentBatch paymentBatch = ev.getSource();
    PaymentBatchApprovalState approvalState = paymentBatch.getApprovalState();
    if (approvalState == PaymentBatchApprovalStateTransitionType.INSTANTIATE.getToState()) {
        // ie was set in the persisting callback
        stateTransitionService.trigger(paymentBatch, PaymentBatchApprovalStateTransitionType.INSTANTIATE, null, null);
    }
}
Also used : PaymentBatch(org.estatio.module.capex.dom.payment.PaymentBatch) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 5 with PaymentBatch

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

Aggregations

PaymentBatch (org.estatio.module.capex.dom.payment.PaymentBatch)10 Action (org.apache.isis.applib.annotation.Action)6 PaymentLine (org.estatio.module.capex.dom.payment.PaymentLine)5 IncomingInvoice (org.estatio.module.capex.dom.invoice.IncomingInvoice)4 ArrayList (java.util.ArrayList)3 MemberOrder (org.apache.isis.applib.annotation.MemberOrder)3 PaymentLineForExcelExportV1 (org.estatio.module.capex.app.paymentline.PaymentLineForExcelExportV1)3 BankAccount (org.estatio.module.financial.dom.BankAccount)3 Lists (com.google.common.collect.Lists)2 IOException (java.io.IOException)2 BigDecimal (java.math.BigDecimal)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Nullable (javax.annotation.Nullable)2 Inject (javax.inject.Inject)2 AccessLevel (lombok.AccessLevel)2 Getter (lombok.Getter)2 Setter (lombok.Setter)2