Search in sources :

Example 11 with OrderItem

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

the class OrderBuilder method execute.

@Override
protected void execute(final ExecutionContext ec) {
    checkParam("officeAdministrator", ec, Person.class);
    checkParam("document", ec, Document.class);
    checkParam("buyer", ec, Organisation.class);
    checkParam("seller", ec, Organisation.class);
    checkParam("property", ec, Property.class);
    checkParam("project", ec, Project.class);
    checkParam("entryDate", ec, LocalDate.class);
    checkParam("itemTax", ec, Tax.class);
    checkParam("item1Description", ec, String.class);
    checkParam("item1NetAmount", ec, BigDecimal.class);
    checkParam("item1VatAmount", ec, BigDecimal.class);
    checkParam("item1GrossAmount", ec, BigDecimal.class);
    checkParam("item1Charge", ec, Charge.class);
    checkParam("item1Period", ec, String.class);
    checkParam("item2Description", ec, String.class);
    checkParam("item2NetAmount", ec, BigDecimal.class);
    checkParam("item2VatAmount", ec, BigDecimal.class);
    checkParam("item2GrossAmount", ec, BigDecimal.class);
    checkParam("item2Charge", ec, Charge.class);
    checkParam("item2Period", ec, String.class);
    // given we categorise for a property
    // workaround: clear MeService#me cache
    queryResultsCache.resetForNextTransaction();
    sudoService.sudo(officeAdministrator.getUsername(), () -> {
        final String comment = "";
        wrap(mixin(Document_categoriseAsOrder.class, document)).act(property, comment);
        // given most/all of the info has been completed  (not using our view model here).
        final String documentName = document.getName();
        Order order = orderRepository.findOrderByDocumentName(documentName).get(0);
        // only way to create a first order item "legally" is through the view model
        final IncomingDocAsOrderViewModel viewModel = mixin(Order_switchView.class, order).act();
        final IncomingDocAsOrderViewModel.changeOrderDetails changeOrderDetails = mixin(IncomingDocAsOrderViewModel.changeOrderDetails.class, viewModel);
        wrap(changeOrderDetails).act(changeOrderDetails.default0Act(), buyer, seller, changeOrderDetails.default3Act(), changeOrderDetails.default4Act());
        wrap(viewModel).setTax(itemTax);
        wrap(viewModel).setProperty(property);
        wrap(viewModel).setProject(project);
        wrap(viewModel).editCharge(item1Charge);
        wrap(viewModel).setDescription(item1Description);
        wrap(viewModel).setNetAmount(item1NetAmount);
        wrap(viewModel).setVatAmount(item1VatAmount);
        wrap(viewModel).setGrossAmount(item1GrossAmount);
        wrap(viewModel).setPeriod(item1Period);
        wrap(viewModel).setBudgetItem(null);
        wrap(viewModel).save();
        wrap(order).changeDates(order.default0ChangeDates(), entryDate);
        // this does an upsert base on the charge, so we still end up with only one item
        wrap(order).addItem(item1Charge, item1Description, item1NetAmount, item1VatAmount, item1GrossAmount, itemTax, // not a typo, but presumably the original fixture was wrong... guessing the upsert doesn't actually update this field
        item2Period, property, project, null);
        // add a different charge; this creates a second item
        wrap(order).addItem(item2Charge, item2Description, item2NetAmount, item2VatAmount, item2GrossAmount, itemTax, item2Period, property, project, null);
        this.object = order;
    });
    final List<OrderItem> items = Lists.newArrayList(this.object.getItems());
    firstItem = items.get(0);
    secondItem = items.get(1);
}
Also used : Order(org.estatio.module.capex.dom.order.Order) Document_categoriseAsOrder(org.estatio.module.capex.dom.documents.categorisation.triggers.Document_categoriseAsOrder) OrderItem(org.estatio.module.capex.dom.order.OrderItem) ToString(lombok.ToString) IncomingDocAsOrderViewModel(org.estatio.module.capex.app.order.IncomingDocAsOrderViewModel) Order_switchView(org.estatio.module.capex.app.order.Order_switchView)

Example 12 with OrderItem

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

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

Example 14 with OrderItem

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

the class IncomingDocAsInvoiceViewModel_Test method choices_orderItem_filters_discarded.

@Test
public void choices_orderItem_filters_discarded() {
    // given
    IncomingDocAsInvoiceViewModel viewModel = new IncomingDocAsInvoiceViewModel();
    viewModel.orderItemRepository = mockOrderItemRepo;
    Organisation seller = new Organisation();
    viewModel.setSeller(seller);
    Order order = new Order();
    order.setApprovalState(OrderApprovalState.DISCARDED);
    OrderItem item = new OrderItem();
    item.setOrdr(order);
    // expect
    context.checking(new Expectations() {

        {
            allowing(mockOrderItemRepo).findBySeller(seller);
            will(returnValue(Arrays.asList(item)));
        }
    });
    // when discarded
    List<OrderItem> orderItemChoices = viewModel.choicesOrderItem();
    // then
    Assertions.assertThat(orderItemChoices).isEmpty();
    // and when not discarded
    order.setApprovalState(OrderApprovalState.APPROVED);
    orderItemChoices = viewModel.choicesOrderItem();
    // then
    Assertions.assertThat(orderItemChoices).contains(item);
    // and when order has no approval state
    order.setApprovalState(null);
    orderItemChoices = viewModel.choicesOrderItem();
    // then
    Assertions.assertThat(orderItemChoices).contains(item);
}
Also used : Order(org.estatio.module.capex.dom.order.Order) Expectations(org.jmock.Expectations) Organisation(org.estatio.module.party.dom.Organisation) OrderItem(org.estatio.module.capex.dom.order.OrderItem) Test(org.junit.Test)

Example 15 with OrderItem

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

the class ProjectService_Test method moveOrderItemToProject_works_when_having_invoice_items_linked.

@Test
public void moveOrderItemToProject_works_when_having_invoice_items_linked() throws Exception {
    // given
    ProjectService projectService = new ProjectService();
    projectService.orderItemInvoiceItemLinkRepository = mockOrderItemInvoiceItemLinkRepository;
    Project project = new Project();
    OrderItem orderItem = new OrderItem();
    // expect
    context.checking(new Expectations() {

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

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