Search in sources :

Example 6 with Project

use of org.estatio.module.capex.dom.project.Project 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 7 with Project

use of org.estatio.module.capex.dom.project.Project in project estatio by estatio.

the class ProjectImport method importData.

@Programmatic
@Override
public List<Object> importData(final Object previousRow) {
    if (previousRow != null) {
    // TODO: support sparse sheets ?
    }
    Project parent = null;
    if (getParentReference() != null) {
        parent = projectRepository.findByReference(getParentReference());
        if (parent == null) {
            throw new ApplicationException(String.format("Parent with reference %s not found.", getParentReference()));
        }
        if (!parent.getAtPath().equals(getAtPath())) {
            throw new ApplicationException(String.format("AtPath parent %s does not match %s.", getParentReference(), getAtPath()));
        }
        if (!parent.getItems().isEmpty()) {
            // TODO: (ECP-438) until we find out more about the process, prevent a the choice of a project having items
            throw new ApplicationException(String.format("Parent with reference %s has items and cannot be a parent therefore.", getAtPath()));
        }
    }
    Project project = findOrCreateProjectAndUpdateParent(getReference(), getName(), getStartDate(), getEndDate(), getAtPath(), parent);
    if (getItemChargeReference() != null) {
        Charge charge = chargeRepository.findByReference(getItemChargeReference());
        Property property = propertyRepository.findPropertyByReference(getItemPropertyReference());
        Tax tax = taxRepository.findByReference(getItemTaxReference());
        wrapperFactory.wrap(project).addItem(charge, getItemDescription(), getItemBudgetedAmount(), getItemStartDate(), getItemEndDate(), property, tax);
    }
    return Lists.newArrayList(project);
}
Also used : Project(org.estatio.module.capex.dom.project.Project) ApplicationException(org.apache.isis.applib.ApplicationException) Charge(org.estatio.module.charge.dom.Charge) Tax(org.estatio.module.tax.dom.Tax) Property(org.estatio.module.asset.dom.Property) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 8 with Project

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

Example 9 with Project

use of org.estatio.module.capex.dom.project.Project in project estatio by estatio.

the class OrderItemRepository_Test method orderItemsWithoutProjectItem_works.

@Test
public void orderItemsWithoutProjectItem_works() throws Exception {
    // given
    Project project = new Project();
    ProjectItem item1 = new ProjectItem();
    Charge chargeOnProjectItem = new Charge();
    item1.setCharge(chargeOnProjectItem);
    project.getItems().add(item1);
    Charge chargeNOTOnProjectItem = new Charge();
    OrderItem orderItemToBeFound = new OrderItem();
    orderItemToBeFound.setCharge(chargeNOTOnProjectItem);
    OrderItem orderItemNOTToBeFound = new OrderItem();
    orderItemNOTToBeFound.setCharge(chargeOnProjectItem);
    OrderItemRepository orderItemRepository = new OrderItemRepository() {

        @Override
        public List<OrderItem> findByProject(final Project project) {
            return Arrays.asList(orderItemNOTToBeFound, orderItemToBeFound);
        }
    };
    // when
    List<OrderItem> result = orderItemRepository.orderItemsNotOnProjectItem(project);
    // then
    Assertions.assertThat(result.size()).isEqualTo(1);
    Assertions.assertThat(result.get(0)).isEqualTo(orderItemToBeFound);
    Assertions.assertThat(result.get(0).getCharge()).isEqualTo(chargeNOTOnProjectItem);
}
Also used : Project(org.estatio.module.capex.dom.project.Project) ProjectItem(org.estatio.module.capex.dom.project.ProjectItem) Charge(org.estatio.module.charge.dom.Charge) Test(org.junit.Test)

Example 10 with Project

use of org.estatio.module.capex.dom.project.Project in project estatio by estatio.

the class Order_Test method minimalRequiredDataToComplete_consitent_dimensions_for_property_project.

@Test
public void minimalRequiredDataToComplete_consitent_dimensions_for_property_project() throws Exception {
    // given
    Order order = new Order();
    OrderItem item1 = new OrderItem();
    order.getItems().add(item1);
    order.setOrderNumber("123");
    order.setBuyer(new Organisation());
    order.setSeller(new Organisation());
    item1.setNetAmount(new BigDecimal("100"));
    item1.setDescription("blah");
    item1.setGrossAmount(BigDecimal.ZERO);
    item1.setCharge(new Charge());
    item1.setStartDate(new LocalDate());
    item1.setEndDate(new LocalDate());
    // when
    item1.setProject(new Project());
    String result = order.reasonIncomplete();
    // then
    assertThat(result).isEqualTo("(on item) when project filled in then property required");
}
Also used : Project(org.estatio.module.capex.dom.project.Project) Organisation(org.estatio.module.party.dom.Organisation) Charge(org.estatio.module.charge.dom.Charge) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

Project (org.estatio.module.capex.dom.project.Project)18 Test (org.junit.Test)11 Charge (org.estatio.module.charge.dom.Charge)9 BigDecimal (java.math.BigDecimal)6 Property (org.estatio.module.asset.dom.Property)6 BudgetItem (org.estatio.module.budget.dom.budgetitem.BudgetItem)5 Tax (org.estatio.module.tax.dom.Tax)5 LocalDate (org.joda.time.LocalDate)5 ArrayList (java.util.ArrayList)3 Programmatic (org.apache.isis.applib.annotation.Programmatic)2 IncomingInvoiceItem (org.estatio.module.capex.dom.invoice.IncomingInvoiceItem)2 OrderItemInvoiceItemLink (org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink)2 Organisation (org.estatio.module.party.dom.Organisation)2 Expectations (org.jmock.Expectations)2 BigInteger (java.math.BigInteger)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 ApplicationException (org.apache.isis.applib.ApplicationException)1 Action (org.apache.isis.applib.annotation.Action)1