Search in sources :

Example 16 with OrderItem

use of org.estatio.module.capex.dom.order.OrderItem 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 17 with OrderItem

use of org.estatio.module.capex.dom.order.OrderItem in project estatio by estatio.

the class IncomingDocAsInvoiceViewModel method autoFillIn.

private void autoFillIn() {
    if (hasOrderItem()) {
        Order order = orderRepository.findByOrderNumber(getOrderItem().getOrdr().getOrderNumber());
        OrderItem orderItem = orderItemRepository.findByOrderAndCharge(order, getOrderItem().getCharge());
        if (!(hasNetAmount() && hasGrossAmount() && hasVatAmount())) {
            setNetAmount(orderItem.getNetAmount());
            setVatAmount(orderItem.getVatAmount());
            setGrossAmount(orderItem.getGrossAmount());
        }
        if (!hasTax()) {
            setTax(orderItem.getTax());
        }
        if (!hasBuyer()) {
            setBuyer(order.getBuyer());
        }
        if (!hasSeller()) {
            setSeller(order.getSeller());
            setBankAccount(bankAccountRepository.getFirstBankAccountOfPartyOrNull(order.getSeller()));
        }
        if (!hasDescription()) {
            setDescription(orderItem.getDescription());
        }
        if (orderItem.getCharge() != null) {
            setCharge(orderItem.getCharge());
        }
        if (orderItem.getProject() != null) {
            setProject(orderItem.getProject());
        }
        if (orderItem.getProperty() != null) {
            setProperty(orderItem.getProperty());
        }
        if (!hasBudgetItem()) {
            setBudgetItem(orderItem.getBudgetItem());
        }
        if (!hasPeriod()) {
            setPeriod(orderItem.getPeriod());
        }
    }
}
Also used : Order(org.estatio.module.capex.dom.order.Order) MemberOrder(org.apache.isis.applib.annotation.MemberOrder) OrderItem(org.estatio.module.capex.dom.order.OrderItem)

Example 18 with OrderItem

use of org.estatio.module.capex.dom.order.OrderItem in project estatio by estatio.

the class IncomingInvoice_outstandingOrderItemsForSeller method $$.

@Action(semantics = SemanticsOf.SAFE)
@ActionLayout(contributed = Contributed.AS_ASSOCIATION)
public List<OrderItemPresentationViewmodel> $$() {
    List<OrderItemPresentationViewmodel> result = new ArrayList<>();
    if (invoice.getSeller() == null && invoice.getProperty() == null) {
        return result;
    }
    List<OrderItem> itemsFound = orderItemRepository.findBySeller(invoice.getSeller()).stream().filter(linkedToInvoiceOrOutstanding).collect(Collectors.toList());
    for (OrderItem item : itemsFound) {
        result.add(new OrderItemPresentationViewmodel(item));
    }
    return result;
}
Also used : OrderItem(org.estatio.module.capex.dom.order.OrderItem) ArrayList(java.util.ArrayList) Action(org.apache.isis.applib.annotation.Action) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

Example 19 with OrderItem

use of org.estatio.module.capex.dom.order.OrderItem in project estatio by estatio.

the class IncomingInvoiceItem_createOrderItemLink method choices0Act.

public List<OrderItem> choices0Act() {
    // the disable guard ensures this is non-null
    final Party seller = mixee.getInvoice().getSeller();
    final Property property = (Property) mixee.getFixedAsset();
    // candidates
    final List<OrderItem> orderItems;
    if (property == null) {
        orderItems = orderItemRepository.findBySeller(seller);
    } else {
        orderItems = orderItemRepository.findBySellerAndProperty(seller, property);
    }
    return orderItems.stream().filter(x -> x.getOrdr().getApprovalState() == null || x.getOrdr().getApprovalState() != OrderApprovalState.DISCARDED).collect(Collectors.toList());
}
Also used : Action(org.apache.isis.applib.annotation.Action) OrderApprovalState(org.estatio.module.capex.dom.order.approval.OrderApprovalState) Party(org.estatio.module.party.dom.Party) Property(org.estatio.module.asset.dom.Property) OrderItem(org.estatio.module.capex.dom.order.OrderItem) Collectors(java.util.stream.Collectors) MemberOrder(org.apache.isis.applib.annotation.MemberOrder) BigDecimal(java.math.BigDecimal) Mixin(org.apache.isis.applib.annotation.Mixin) SemanticsOf(org.apache.isis.applib.annotation.SemanticsOf) List(java.util.List) ReasonBuffer2(org.estatio.module.base.platform.applib.ReasonBuffer2) Digits(javax.validation.constraints.Digits) IncomingInvoiceItem(org.estatio.module.capex.dom.invoice.IncomingInvoiceItem) Party(org.estatio.module.party.dom.Party) OrderItem(org.estatio.module.capex.dom.order.OrderItem) Property(org.estatio.module.asset.dom.Property)

Example 20 with OrderItem

use of org.estatio.module.capex.dom.order.OrderItem in project estatio by estatio.

the class ProjectService method moveIncomingInvoiceItemToProject.

public void moveIncomingInvoiceItemToProject(final IncomingInvoiceItem incomingInvoiceItem, final Project project) {
    Optional linkToOrderItemIfAny = orderItemInvoiceItemLinkRepository.findByInvoiceItem(incomingInvoiceItem);
    if (linkToOrderItemIfAny.isPresent()) {
        OrderItemInvoiceItemLink link = (OrderItemInvoiceItemLink) linkToOrderItemIfAny.get();
        OrderItem linkedOrderItem = link.getOrderItem();
        for (OrderItemInvoiceItemLink itemLinked : orderItemInvoiceItemLinkRepository.findByOrderItem(linkedOrderItem)) {
            itemLinked.getInvoiceItem().setProjectByPassingInvalidateApproval(project);
        }
        linkedOrderItem.setProject(project);
    } else {
        incomingInvoiceItem.setProjectByPassingInvalidateApproval(project);
    }
}
Also used : Optional(java.util.Optional) OrderItemInvoiceItemLink(org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink) OrderItem(org.estatio.module.capex.dom.order.OrderItem)

Aggregations

OrderItem (org.estatio.module.capex.dom.order.OrderItem)20 IncomingInvoiceItem (org.estatio.module.capex.dom.invoice.IncomingInvoiceItem)9 Order (org.estatio.module.capex.dom.order.Order)7 OrderItemInvoiceItemLink (org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink)7 Action (org.apache.isis.applib.annotation.Action)6 MemberOrder (org.apache.isis.applib.annotation.MemberOrder)6 BigDecimal (java.math.BigDecimal)5 ArrayList (java.util.ArrayList)5 Expectations (org.jmock.Expectations)5 Test (org.junit.Test)5 IncomingInvoice (org.estatio.module.capex.dom.invoice.IncomingInvoice)4 Programmatic (org.apache.isis.applib.annotation.Programmatic)3 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 ToString (lombok.ToString)2 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)2 Mixin (org.apache.isis.applib.annotation.Mixin)2 IncomingInvoiceType (org.estatio.module.capex.dom.invoice.IncomingInvoiceType)2 Charge (org.estatio.module.charge.dom.Charge)2