Search in sources :

Example 96 with Programmatic

use of org.apache.isis.applib.annotation.Programmatic in project estatio by estatio.

the class PartySubscriptionsForOrders method on.

@Programmatic
@com.google.common.eventbus.Subscribe
@org.axonframework.eventhandling.annotation.EventHandler
public void on(final Party.DeleteEvent ev) {
    Party sourceParty = (Party) ev.getSource();
    Party replacementParty = ev.getReplacement();
    switch(ev.getEventPhase()) {
        case VALIDATE:
            if (replacementParty == null && orderRepository.findBySellerParty(sourceParty).size() > 0) {
                ev.invalidate("Party is in use as seller in an order. Provide replacement");
            }
            break;
        case EXECUTING:
            if (replacementParty != null) {
                for (Order order : orderRepository.findBySellerParty(sourceParty)) {
                    order.setSeller(replacementParty);
                }
            }
            break;
        default:
            break;
    }
}
Also used : Order(org.estatio.module.capex.dom.order.Order) Party(org.estatio.module.party.dom.Party) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 97 with Programmatic

use of org.apache.isis.applib.annotation.Programmatic in project estatio by estatio.

the class RunBackgroundCommandsService method runBackgroundCommands.

@Programmatic
public void runBackgroundCommands() throws InterruptedException {
    List<CommandJdo> commands = backgroundCommandRepository.findBackgroundCommandsNotYetStarted();
    assertThat(commands).hasSize(1);
    transactionService.nextTransaction();
    BackgroundCommandExecutionFromBackgroundCommandServiceJdo backgroundExec = new BackgroundCommandExecutionFromBackgroundCommandServiceJdo();
    final SimpleSession session = new SimpleSession("scheduler_user", new String[] { "admin_role" });
    final Thread thread = new Thread(() -> backgroundExec.execute(session, null));
    thread.start();
    thread.join(5000L);
    commands = backgroundCommandRepository.findBackgroundCommandsNotYetStarted();
    assertThat(commands).isEmpty();
}
Also used : CommandJdo(org.isisaddons.module.command.dom.CommandJdo) BackgroundCommandExecutionFromBackgroundCommandServiceJdo(org.isisaddons.module.command.dom.BackgroundCommandExecutionFromBackgroundCommandServiceJdo) SimpleSession(org.apache.isis.core.runtime.authentication.standard.SimpleSession) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 98 with Programmatic

use of org.apache.isis.applib.annotation.Programmatic in project estatio by estatio.

the class IncomingDocAsInvoiceViewModel method init.

@Programmatic
public void init() {
    IncomingInvoice incomingInvoice = getDomainObject();
    setIncomingInvoiceType(incomingInvoice.getType());
    setInvoiceNumber(incomingInvoice.getInvoiceNumber());
    setBuyer(incomingInvoice.getBuyer());
    setSeller(incomingInvoice.getSeller());
    setInvoiceDate(incomingInvoice.getInvoiceDate());
    setDueDate(incomingInvoice.getDueDate());
    setPaymentMethod(incomingInvoice.getPaymentMethod());
    setDateReceived(incomingInvoice.getDateReceived());
    setBankAccount(incomingInvoice.getBankAccount());
    setCurrency(incomingInvoice.getCurrency());
    final Optional<IncomingInvoiceItem> firstItemIfAny = getFirstItemIfAny();
    if (firstItemIfAny.isPresent()) {
        IncomingInvoiceItem invoiceItem = firstItemIfAny.get();
        setCharge(invoiceItem.getCharge());
        setDescription(invoiceItem.getDescription());
        setNetAmount(invoiceItem.getNetAmount());
        setVatAmount(invoiceItem.getVatAmount());
        setGrossAmount(invoiceItem.getGrossAmount());
        setTax(invoiceItem.getTax());
        setDueDate(invoiceItem.getDueDate());
        setPeriod(periodFrom(invoiceItem.getStartDate(), invoiceItem.getEndDate()));
        setProperty((org.estatio.module.asset.dom.Property) invoiceItem.getFixedAsset());
        setProject(invoiceItem.getProject());
        setBudgetItem(invoiceItem.getBudgetItem());
        final Optional<OrderItemInvoiceItemLink> linkIfAny = orderItemInvoiceItemLinkRepository.findByInvoiceItem(invoiceItem);
        linkIfAny.ifPresent(link -> {
            final OrderItem linkOrderItem = link.getOrderItem();
            IncomingDocAsInvoiceViewModel.this.setOrderItem(linkOrderItem);
        });
    } else {
        // for the first time we edit there will be no first item,
        // so we instead get the property from the header invoice
        setProperty(incomingInvoice.getProperty());
    }
}
Also used : OrderItemInvoiceItemLink(org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink) OrderItem(org.estatio.module.capex.dom.order.OrderItem) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) IncomingInvoiceItem(org.estatio.module.capex.dom.invoice.IncomingInvoiceItem) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 99 with Programmatic

use of org.apache.isis.applib.annotation.Programmatic in project estatio by estatio.

the class DebtorBankAccountService method uniqueDebtorAccountToPay.

@Programmatic
public BankAccount uniqueDebtorAccountToPay(final IncomingInvoice invoice) {
    final Party buyer = invoice.getBuyer();
    List<BankAccount> bankAccountsForBuyer = bankAccountRepository.findBankAccountsByOwner(buyer);
    final Property propertyIfAny = invoice.getProperty();
    if (propertyIfAny != null) {
        List<FixedAssetFinancialAccount> fafrList = fixedAssetFinancialAccountRepository.findByFixedAsset(propertyIfAny);
        List<FinancialAccount> bankAccountsForProperty = fafrList.stream().map(FixedAssetFinancialAccount::getFinancialAccount).filter(BankAccount.class::isInstance).map(BankAccount.class::cast).collect(Collectors.toList());
        bankAccountsForBuyer.retainAll(bankAccountsForProperty);
    }
    // original implementation ... see if we already have a unique bank account
    int numBankAccounts = bankAccountsForBuyer.size();
    switch(numBankAccounts) {
        case 0:
            return null;
        case 1:
            return bankAccountsForBuyer.get(0);
        default:
    }
    // see if removing non-preferred helps
    bankAccountsForBuyer.removeIf(x -> (x.getPreferred() == null || !x.getPreferred()));
    numBankAccounts = bankAccountsForBuyer.size();
    switch(numBankAccounts) {
        case 0:
            return null;
        case 1:
            return bankAccountsForBuyer.get(0);
        default:
            // give up, still non-duplicate
            return null;
    }
}
Also used : FixedAssetFinancialAccount(org.estatio.module.assetfinancial.dom.FixedAssetFinancialAccount) Party(org.estatio.module.party.dom.Party) FinancialAccount(org.estatio.module.financial.dom.FinancialAccount) FixedAssetFinancialAccount(org.estatio.module.assetfinancial.dom.FixedAssetFinancialAccount) BankAccount(org.estatio.module.financial.dom.BankAccount) Property(org.estatio.module.asset.dom.Property) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 100 with Programmatic

use of org.apache.isis.applib.annotation.Programmatic in project estatio by estatio.

the class UpcomingPaymentService method getUpcomingPayments.

@Programmatic
public List<UpcomingPaymentTotal> getUpcomingPayments() {
    List<IncomingInvoice> invoiceSelectionForUpcomingPayments = new ArrayList<>();
    invoiceSelectionForUpcomingPayments.addAll(incomingInvoiceRepository.findByApprovalStateAndPaymentMethod(IncomingInvoiceApprovalState.COMPLETED, PaymentMethod.BANK_TRANSFER));
    invoiceSelectionForUpcomingPayments.addAll(incomingInvoiceRepository.findByApprovalStateAndPaymentMethod(IncomingInvoiceApprovalState.APPROVED, PaymentMethod.BANK_TRANSFER));
    invoiceSelectionForUpcomingPayments.addAll(incomingInvoiceRepository.findByApprovalStateAndPaymentMethod(IncomingInvoiceApprovalState.PENDING_BANK_ACCOUNT_CHECK, PaymentMethod.BANK_TRANSFER));
    List<UpcomingPaymentTotal> upcomingPayments = new ArrayList<>();
    for (IncomingInvoice invoice : invoiceSelectionForUpcomingPayments) {
        UpcomingPaymentTotal upcomingPaymentTotal;
        if (paymentTotalForBankAccount(upcomingPayments, invoice).isEmpty()) {
            upcomingPaymentTotal = new UpcomingPaymentTotal(debtorBankAccountService.uniqueDebtorAccountToPay(invoice));
            upcomingPaymentTotal.addValue(invoice);
            upcomingPayments.add(upcomingPaymentTotal);
        } else {
            upcomingPaymentTotal = paymentTotalForBankAccount(upcomingPayments, invoice).get(0);
            upcomingPaymentTotal.addValue(invoice);
        }
    }
    return upcomingPayments;
}
Also used : IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) ArrayList(java.util.ArrayList) UpcomingPaymentTotal(org.estatio.module.capex.app.invoice.UpcomingPaymentTotal) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Aggregations

Programmatic (org.apache.isis.applib.annotation.Programmatic)162 Party (org.estatio.module.party.dom.Party)21 Lease (org.estatio.module.lease.dom.Lease)16 DomainObject (org.apache.isis.applib.annotation.DomainObject)11 BankAccount (org.estatio.module.financial.dom.BankAccount)11 Charge (org.estatio.module.charge.dom.Charge)10 ApplicationTenancy (org.isisaddons.module.security.dom.tenancy.ApplicationTenancy)10 LocalDate (org.joda.time.LocalDate)10 BigDecimal (java.math.BigDecimal)9 Bookmark (org.apache.isis.applib.services.bookmark.Bookmark)9 ApplicationException (org.apache.isis.applib.ApplicationException)8 Property (org.estatio.module.asset.dom.Property)8 CommunicationChannel (org.incode.module.communications.dom.impl.commchannel.CommunicationChannel)8 ArrayList (java.util.ArrayList)7 TranslatableString (org.apache.isis.applib.services.i18n.TranslatableString)7 InvoiceItem (org.estatio.module.invoice.dom.InvoiceItem)7 LeaseItem (org.estatio.module.lease.dom.LeaseItem)7 Inject (javax.inject.Inject)6 Unit (org.estatio.module.asset.dom.Unit)6 Document (org.incode.module.document.dom.impl.docs.Document)6