Search in sources :

Example 11 with IncomingInvoiceItem

use of org.estatio.module.capex.dom.invoice.IncomingInvoiceItem in project estatio by estatio.

the class IncomingInvoice_IntegTest method when_discarded_reported_items_are_reversed_while_no_correction_item_is_added.

@Test
public void when_discarded_reported_items_are_reversed_while_no_correction_item_is_added() {
    // given
    incomingInvoiceSetup();
    incomingInvoiceIsCompleted();
    IncomingInvoiceItem reportedItem = firstItemIsReported();
    // when
    invoiceIsDiscarded();
    // then
    assertThat(incomingInvoice.getItems().size()).isEqualTo(3);
    IncomingInvoiceItem reversal = (IncomingInvoiceItem) incomingInvoice.getItems().first();
    assertThat(reversal.getReversalOf()).isEqualTo(reportedItem);
    assertThat(reversal.getNetAmount()).isEqualTo(reportedItem.getNetAmount().negate());
    assertThat(reversal.getReportedDate()).isNull();
}
Also used : IncomingInvoiceItem(org.estatio.module.capex.dom.invoice.IncomingInvoiceItem) Test(org.junit.Test)

Example 12 with IncomingInvoiceItem

use of org.estatio.module.capex.dom.invoice.IncomingInvoiceItem 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 13 with IncomingInvoiceItem

use of org.estatio.module.capex.dom.invoice.IncomingInvoiceItem 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 14 with IncomingInvoiceItem

use of org.estatio.module.capex.dom.invoice.IncomingInvoiceItem in project estatio by estatio.

the class OrderInvoiceImportReport method getLines.

public List<OrderInvoiceImportReportLine> getLines() {
    List<OrderInvoiceImportReportLine> result = new ArrayList<>();
    Integer numberOfOrderlines;
    Integer numberOfinvoicelines;
    BigDecimal orderNetTotal;
    BigDecimal orderVatTotal;
    BigDecimal orderGrossTotal;
    BigDecimal invoiceNetTotal;
    BigDecimal invoiceVatTotal;
    BigDecimal invoiceGrossTotal;
    for (Project project : projectRepository.listAll()) {
        for (String period : periodsPresent(project)) {
            numberOfOrderlines = 0;
            numberOfinvoicelines = 0;
            orderNetTotal = BigDecimal.ZERO;
            orderVatTotal = BigDecimal.ZERO;
            orderGrossTotal = BigDecimal.ZERO;
            invoiceNetTotal = BigDecimal.ZERO;
            invoiceVatTotal = BigDecimal.ZERO;
            invoiceGrossTotal = BigDecimal.ZERO;
            for (OrderItem orderItem : orderItemRepository.findByProject(project)) {
                if (orderItem.getPeriod().equals(period)) {
                    numberOfOrderlines = numberOfOrderlines + 1;
                    orderNetTotal = orderNetTotal.add(orderItem.getNetAmount());
                    orderVatTotal = orderItem.getVatAmount() == null ? orderVatTotal : orderVatTotal.add(orderItem.getVatAmount());
                    orderGrossTotal = orderGrossTotal.add(orderItem.getGrossAmount());
                }
            }
            for (IncomingInvoiceItem invoiceItem : incomingInvoiceItemRepository.findByProject(project)) {
                if (invoiceItem.getPeriod().equals(period)) {
                    numberOfinvoicelines = numberOfinvoicelines + 1;
                    invoiceNetTotal = invoiceNetTotal.add(invoiceItem.getNetAmount());
                    invoiceVatTotal = invoiceItem.getVatAmount() == null ? invoiceVatTotal : invoiceVatTotal.add(invoiceItem.getVatAmount());
                    invoiceGrossTotal = invoiceGrossTotal.add(invoiceItem.getGrossAmount());
                }
            }
            result.add(new OrderInvoiceImportReportLine(project.getReference(), period, numberOfOrderlines, orderNetTotal, orderVatTotal, orderGrossTotal, numberOfinvoicelines, invoiceNetTotal, invoiceVatTotal, invoiceGrossTotal));
        }
    }
    return result;
}
Also used : Project(org.estatio.module.capex.dom.project.Project) OrderItem(org.estatio.module.capex.dom.order.OrderItem) ArrayList(java.util.ArrayList) IncomingInvoiceItem(org.estatio.module.capex.dom.invoice.IncomingInvoiceItem) BigDecimal(java.math.BigDecimal)

Example 15 with IncomingInvoiceItem

use of org.estatio.module.capex.dom.invoice.IncomingInvoiceItem in project estatio by estatio.

the class OrderInvoiceImportReport method periodsPresent.

private List<String> periodsPresent(final Project project) {
    List<String> result = new ArrayList<>();
    for (OrderItem item : orderItemRepository.findByProject(project)) {
        if (!result.contains(item.getPeriod())) {
            result.add(item.getPeriod());
        }
    }
    for (IncomingInvoiceItem item : incomingInvoiceItemRepository.findByProject(project)) {
        if (!result.contains(item.getPeriod())) {
            result.add(item.getPeriod());
        }
    }
    Collections.sort(result);
    return result;
}
Also used : OrderItem(org.estatio.module.capex.dom.order.OrderItem) ArrayList(java.util.ArrayList) IncomingInvoiceItem(org.estatio.module.capex.dom.invoice.IncomingInvoiceItem)

Aggregations

IncomingInvoiceItem (org.estatio.module.capex.dom.invoice.IncomingInvoiceItem)25 Test (org.junit.Test)14 BigDecimal (java.math.BigDecimal)8 OrderItem (org.estatio.module.capex.dom.order.OrderItem)7 IncomingInvoice (org.estatio.module.capex.dom.invoice.IncomingInvoice)6 OrderItemInvoiceItemLink (org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink)5 Expectations (org.jmock.Expectations)5 Action (org.apache.isis.applib.annotation.Action)3 ArrayList (java.util.ArrayList)2 Project (org.estatio.module.capex.dom.project.Project)2 Charge (org.estatio.module.charge.dom.Charge)2 ToString (lombok.ToString)1 MemberOrder (org.apache.isis.applib.annotation.MemberOrder)1 Programmatic (org.apache.isis.applib.annotation.Programmatic)1 IncomingInvoiceType (org.estatio.module.capex.dom.invoice.IncomingInvoiceType)1 ProjectItem_InvoicedAmount (org.estatio.module.capex.dom.invoice.contributions.ProjectItem_InvoicedAmount)1 Order (org.estatio.module.capex.dom.order.Order)1 IncomingInvoiceItem_createOrderItemLink (org.estatio.module.capex.dom.orderinvoice.IncomingInvoiceItem_createOrderItemLink)1 ProjectItem (org.estatio.module.capex.dom.project.ProjectItem)1 Party (org.estatio.module.party.dom.Party)1