Search in sources :

Example 1 with OrderItemInvoiceItemLink

use of org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink in project estatio by estatio.

the class IncomingDocAsInvoiceViewModel method save.

@Action(semantics = SemanticsOf.IDEMPOTENT)
@MemberOrder(sequence = "1")
public IncomingInvoice save() {
    IncomingInvoice incomingInvoice = getDomainObject();
    IncomingInvoiceType previousType = incomingInvoice.getType();
    incomingInvoice.setType(getIncomingInvoiceType());
    incomingInvoice.setInvoiceNumber(getInvoiceNumber());
    incomingInvoice.setBuyer(getBuyer());
    incomingInvoice.setSeller(getSeller());
    incomingInvoice.setInvoiceDate(getInvoiceDate());
    incomingInvoice.setDueDate(getDueDate());
    incomingInvoice.setPaymentMethod(getPaymentMethod());
    incomingInvoice.setCurrency(getCurrency());
    incomingInvoice.setDateReceived(getDateReceived());
    incomingInvoice.setBankAccount(getBankAccount());
    incomingInvoice.setNetAmount(getNetAmount());
    incomingInvoice.setGrossAmount(getGrossAmount());
    // if changed the type, then we need to re-evaluate the state machine
    if (previousType != getIncomingInvoiceType()) {
        stateTransitionService.trigger(incomingInvoice, IncomingInvoiceApprovalStateTransition.class, null, null, null);
    }
    // upsert invoice item
    // this will also update the parent header's property with that from the first item
    Optional<IncomingInvoiceItem> firstItemIfAny = getFirstItemIfAny();
    IncomingInvoiceItem firstItem;
    if (firstItemIfAny.isPresent()) {
        IncomingInvoiceItem item = firstItemIfAny.get();
        item.setIncomingInvoiceType(getIncomingInvoiceType());
        item.setCharge(getCharge());
        item.setDescription(getDescription());
        item.setNetAmount(getNetAmount());
        item.setVatAmount(getVatAmount());
        item.setGrossAmount(getGrossAmount());
        item.setTax(getTax());
        item.setStartDate(getStartDateFromPeriod());
        item.setEndDate(getEndDateFromPeriod());
        item.setFixedAsset(getProperty());
        item.setProject(getProject());
        item.setBudgetItem(getBudgetItem());
        firstItem = item;
    } else {
        firstItem = incomingInvoiceItemRepository.create(incomingInvoice.nextItemSequence(), incomingInvoice, incomingInvoiceType, getCharge(), getDescription(), getNetAmount(), getVatAmount(), getGrossAmount(), getTax(), getDueDate(), getStartDateFromPeriod(), getEndDateFromPeriod(), getProperty(), getProject(), getBudgetItem());
    }
    // 'switch view' will not be available subsequently because the Invoice/Item is "too complex")
    if (getOrderItem() != null) {
        Order order = getOrderItem().getOrdr();
        Charge chargeFromWrapper = getOrderItem().getCharge();
        OrderItem orderItemToLink = orderItemRepository.findByOrderAndCharge(order, chargeFromWrapper);
        orderItemInvoiceItemLinkRepository.findOrCreateLink(orderItemToLink, firstItem, firstItem.getNetAmount());
    } else {
        // remove all (or the one and only) link.
        final Optional<OrderItemInvoiceItemLink> links = orderItemInvoiceItemLinkRepository.findByInvoiceItem(firstItem);
        links.ifPresent(link -> {
            link.remove();
        });
    }
    return incomingInvoice;
}
Also used : Order(org.estatio.module.capex.dom.order.Order) MemberOrder(org.apache.isis.applib.annotation.MemberOrder) OrderItemInvoiceItemLink(org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink) IncomingInvoiceType(org.estatio.module.capex.dom.invoice.IncomingInvoiceType) OrderItem(org.estatio.module.capex.dom.order.OrderItem) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) IncomingInvoiceItem(org.estatio.module.capex.dom.invoice.IncomingInvoiceItem) Charge(org.estatio.module.charge.dom.Charge) Action(org.apache.isis.applib.annotation.Action) MemberOrder(org.apache.isis.applib.annotation.MemberOrder)

Example 2 with OrderItemInvoiceItemLink

use of org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink in project estatio by estatio.

the class IncomingInvoice_LinkedOrderItems method linkedOrderItems.

@Action(semantics = SemanticsOf.SAFE)
@ActionLayout(contributed = Contributed.AS_ASSOCIATION)
public List<LinkedOrderItemViewModel> linkedOrderItems() {
    List<LinkedOrderItemViewModel> result = new ArrayList<>();
    for (OrderItemInvoiceItemLink link : orderItemInvoiceItemLinkRepository.findByInvoice(incomingInvoice)) {
        OrderItem item = link.getOrderItem();
        BigDecimal netAmount = item.getNetAmount();
        BigDecimal netAmountInvoiced = orderItemInvoiceItemLinkRepository.calculateNetAmountLinkedToOrderItem(item);
        result.add(new LinkedOrderItemViewModel(item, netAmount, netAmountInvoiced));
    }
    return result;
}
Also used : OrderItemInvoiceItemLink(org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink) OrderItem(org.estatio.module.capex.dom.order.OrderItem) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) Action(org.apache.isis.applib.annotation.Action) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

Example 3 with OrderItemInvoiceItemLink

use of org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink in project estatio by estatio.

the class ProjectService_Test method moveOrderItemToProject_works_when_no_invoice_items_linked.

@Test
public void moveOrderItemToProject_works_when_no_invoice_items_linked() throws Exception {
    // given
    ProjectService projectService = new ProjectService();
    projectService.orderItemInvoiceItemLinkRepository = mockOrderItemInvoiceItemLinkRepository;
    Project project = new Project();
    OrderItem orderItem = new OrderItem();
    IncomingInvoiceItem incomingInvoiceItem = new IncomingInvoiceItem();
    OrderItemInvoiceItemLink link = new OrderItemInvoiceItemLink();
    link.setInvoiceItem(incomingInvoiceItem);
    link.setOrderItem(orderItem);
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockOrderItemInvoiceItemLinkRepository).findByOrderItem(orderItem);
            will(returnValue(Arrays.asList(link)));
        }
    });
    // when
    projectService.moveOrderItemToProject(orderItem, project);
    // then
    Assertions.assertThat(orderItem.getProject()).isEqualTo(project);
    Assertions.assertThat(incomingInvoiceItem.getProject()).isEqualTo(project);
}
Also used : Expectations(org.jmock.Expectations) OrderItemInvoiceItemLink(org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink) OrderItem(org.estatio.module.capex.dom.order.OrderItem) IncomingInvoiceItem(org.estatio.module.capex.dom.invoice.IncomingInvoiceItem) Test(org.junit.Test)

Example 4 with OrderItemInvoiceItemLink

use of org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink in project estatio by estatio.

the class ProjectService_Test method moveIncomingInvoiceItemToProject_works_when_invoice_item_linked_to_order_item.

@Test
public void moveIncomingInvoiceItemToProject_works_when_invoice_item_linked_to_order_item() throws Exception {
    // given
    ProjectService projectService = new ProjectService();
    projectService.orderItemInvoiceItemLinkRepository = mockOrderItemInvoiceItemLinkRepository;
    Project project = new Project();
    OrderItem orderItem = new OrderItem();
    IncomingInvoiceItem incomingInvoiceItem = new IncomingInvoiceItem();
    IncomingInvoiceItem otherLinkedItem = new IncomingInvoiceItem();
    OrderItemInvoiceItemLink link1 = new OrderItemInvoiceItemLink();
    link1.setInvoiceItem(incomingInvoiceItem);
    link1.setOrderItem(orderItem);
    OrderItemInvoiceItemLink link2 = new OrderItemInvoiceItemLink();
    link2.setInvoiceItem(otherLinkedItem);
    link2.setOrderItem(orderItem);
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockOrderItemInvoiceItemLinkRepository).findByInvoiceItem(incomingInvoiceItem);
            will(returnValue(Optional.of(link1)));
            oneOf(mockOrderItemInvoiceItemLinkRepository).findByOrderItem(orderItem);
            will(returnValue(Arrays.asList(link1, link2)));
        }
    });
    // when
    projectService.moveIncomingInvoiceItemToProject(incomingInvoiceItem, project);
    // then
    Assertions.assertThat(incomingInvoiceItem.getProject()).isEqualTo(project);
    Assertions.assertThat(otherLinkedItem.getProject()).isEqualTo(project);
    Assertions.assertThat(orderItem.getProject()).isEqualTo(project);
}
Also used : Expectations(org.jmock.Expectations) OrderItemInvoiceItemLink(org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink) OrderItem(org.estatio.module.capex.dom.order.OrderItem) IncomingInvoiceItem(org.estatio.module.capex.dom.invoice.IncomingInvoiceItem) Test(org.junit.Test)

Example 5 with OrderItemInvoiceItemLink

use of org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink in project estatio by estatio.

the class ProjectInvoiceItemTransferManager_Test method getInvoiceItemsHavingNoOrder_works.

@Test
public void getInvoiceItemsHavingNoOrder_works() throws Exception {
    // given
    Project source = new Project();
    ProjectInvoiceItemTransferManager manager = new ProjectInvoiceItemTransferManager(null, source);
    manager.incomingInvoiceItemRepository = mockIncomingInvoiceItemRepository;
    manager.orderItemInvoiceItemLinkRepository = mockOrderItemInvoiceItemLinkRepository;
    IncomingInvoiceItem itemLinked = new IncomingInvoiceItem();
    IncomingInvoiceItem itemNotLinked = new IncomingInvoiceItem();
    OrderItemInvoiceItemLink link = new OrderItemInvoiceItemLink();
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockIncomingInvoiceItemRepository).findByProject(source);
            will(returnValue(Arrays.asList(itemLinked, itemNotLinked)));
            oneOf(mockOrderItemInvoiceItemLinkRepository).findByInvoiceItem(itemLinked);
            will(returnValue(Optional.of(link)));
            oneOf(mockOrderItemInvoiceItemLinkRepository).findByInvoiceItem(itemNotLinked);
            will(returnValue(Optional.empty()));
        }
    });
    // when
    List<IncomingInvoiceItem> items = manager.getInvoiceItemsHavingNoOrder();
    // then
    Assertions.assertThat(items).contains(itemNotLinked);
    Assertions.assertThat(items).doesNotContain(itemLinked);
}
Also used : Expectations(org.jmock.Expectations) Project(org.estatio.module.capex.dom.project.Project) OrderItemInvoiceItemLink(org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink) IncomingInvoiceItem(org.estatio.module.capex.dom.invoice.IncomingInvoiceItem) Test(org.junit.Test)

Aggregations

OrderItemInvoiceItemLink (org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink)9 OrderItem (org.estatio.module.capex.dom.order.OrderItem)6 IncomingInvoiceItem (org.estatio.module.capex.dom.invoice.IncomingInvoiceItem)5 Expectations (org.jmock.Expectations)3 Test (org.junit.Test)3 BigDecimal (java.math.BigDecimal)2 Action (org.apache.isis.applib.annotation.Action)2 IncomingInvoice (org.estatio.module.capex.dom.invoice.IncomingInvoice)2 Project (org.estatio.module.capex.dom.project.Project)2 Charge (org.estatio.module.charge.dom.Charge)2 ArrayList (java.util.ArrayList)1 Optional (java.util.Optional)1 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)1 MemberOrder (org.apache.isis.applib.annotation.MemberOrder)1 Programmatic (org.apache.isis.applib.annotation.Programmatic)1 FixedAsset (org.estatio.module.asset.dom.FixedAsset)1 BudgetItem (org.estatio.module.budget.dom.budgetitem.BudgetItem)1 IncomingInvoiceType (org.estatio.module.capex.dom.invoice.IncomingInvoiceType)1 Order (org.estatio.module.capex.dom.order.Order)1 OrderItemInvoiceItemLinkRepository (org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLinkRepository)1