Search in sources :

Example 1 with OrderItem

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

the class IncomingInvoiceBuilder 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("sellerBankAccount", ec, BankAccount.class);
    checkParam("property", ec, Property.class);
    checkParam("dueDate", ec, LocalDate.class);
    checkParam("invoiceDate", ec, LocalDate.class);
    checkParam("dateReceived", ec, LocalDate.class);
    checkParam("itemTax", ec, Tax.class);
    checkParam("item1InvoiceType", ec, IncomingInvoiceType.class);
    // checkParam("item1Project", ec, Project.class); // optional
    checkParam("item1Charge", ec, Charge.class);
    checkParam("item1Description", ec, String.class);
    checkParam("item1NetAmount", ec, BigDecimal.class);
    checkParam("item1VatAmount", ec, BigDecimal.class);
    checkParam("item1GrossAmount", ec, BigDecimal.class);
    checkParam("item1Period", ec, String.class);
    if (getItem2InvoiceType() != null) {
        checkParam("item2InvoiceType", ec, IncomingInvoiceType.class);
        // checkParam("item2Project", ec, Project.class); // optional
        checkParam("item2Charge", ec, Charge.class);
        checkParam("item2Description", ec, String.class);
        checkParam("item2NetAmount", ec, BigDecimal.class);
        checkParam("item2VatAmount", ec, BigDecimal.class);
        checkParam("item2GrossAmount", ec, BigDecimal.class);
        checkParam("item2Period", ec, String.class);
    }
    // checkParam("orderDocument", ec, Document.class); // optional
    if (order != null) {
        checkParam("orderItemLinkAmount", ec, BigDecimal.class);
    }
    if (propertyManager != null) {
        checkParam("propertyManager", ec, Person.class);
        checkParam("assetManager", ec, Person.class);
        checkParam("countryDirector", ec, Person.class);
        checkParam("treasurer", ec, Person.class);
    }
    sudoService.sudo(officeAdministrator.getUsername(), (Runnable) () -> wrap(mixin(Document_categoriseAsPropertyInvoice.class, document)).act(property, ""));
    final String documentName = document.getName();
    IncomingInvoice invoice = incomingInvoiceRepository.findIncomingInvoiceByDocumentName(documentName).get(0);
    invoice.setDateReceived(dateReceived);
    invoice.setSeller(seller);
    invoice.setBankAccount(sellerBankAccount);
    invoice.setBuyer(buyer);
    invoice.setType(invoiceType);
    invoice.setDueDate(dueDate);
    invoice.setInvoiceNumber(invoiceNumber);
    invoice.setPaymentMethod(paymentMethod);
    invoice.setInvoiceDate(invoiceDate);
    invoice.setNetAmount(netAmount);
    invoice.setGrossAmount(grossAmount);
    invoice.addItem(item1InvoiceType, item1Charge, item1Description, item1NetAmount, item1VatAmount, item1GrossAmount, itemTax, dueDate, item1Period, property, item1Project, null);
    if (order != null) {
        IncomingInvoiceItem invoiceItemToLink = (IncomingInvoiceItem) invoice.getItems().first();
        OrderItem orderItemToLink = order.getItems().first();
        mixin(IncomingInvoiceItem_createOrderItemLink.class, invoiceItemToLink).act(orderItemToLink, orderItemLinkAmount);
    }
    if (item2InvoiceType != null) {
        invoice.addItem(item2InvoiceType, item2Charge, item2Description, item2NetAmount, item2VatAmount, item2GrossAmount, itemTax, dueDate, item2Period, property, item2Project, null);
    }
    if (propertyManager != null) {
        // complete and approve invoice and verify bankaccount
        sudoService.sudo(propertyManager.getUsername(), (Runnable) () -> wrap(mixin(IncomingInvoice_complete.class, invoice)).act("PROPERTY_MANAGER", null, null));
        sudoService.sudo(assetManager.getUsername(), (Runnable) () -> wrap(mixin(IncomingInvoice_approve.class, invoice)).act("ASSET_MANAGER", null, null, false));
        sudoService.sudo(countryDirector.getUsername(), (Runnable) () -> wrap(mixin(IncomingInvoice_approveAsCountryDirector.class, invoice)).act(null, false));
        sudoService.sudo(treasurer.getUsername(), (Runnable) () -> wrap(mixin(BankAccount_verify.class, sellerBankAccount)).act(null));
    }
}
Also used : IncomingInvoiceItem_createOrderItemLink(org.estatio.module.capex.dom.orderinvoice.IncomingInvoiceItem_createOrderItemLink) OrderItem(org.estatio.module.capex.dom.order.OrderItem) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) IncomingInvoiceItem(org.estatio.module.capex.dom.invoice.IncomingInvoiceItem) ToString(lombok.ToString)

Example 2 with OrderItem

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

the class IncomingInvoiceItem_updateOrderItemLink method validateAct.

public String validateAct(final BigDecimal proposedNetAmount) {
    final OrderItem orderItem = linkedOrderItem();
    final OrderItemInvoiceItemLink link = orderItemInvoiceItemLinkRepository.findUnique(orderItem, mixee);
    // should be there.
    final BigDecimal currentNetAmount = link != null ? link.getNetAmount() : BigDecimal.ZERO;
    return validateLinkAmount(currentNetAmount, proposedNetAmount);
}
Also used : OrderItem(org.estatio.module.capex.dom.order.OrderItem) BigDecimal(java.math.BigDecimal)

Example 3 with OrderItem

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

the class ProjectItem_OrderedAmount_Test method orderedAmount_works.

@Test
public void orderedAmount_works() throws Exception {
    // given
    BigDecimal expectedTotalNetAmountOnItems = new BigDecimal("100.00");
    BigDecimal netAmountOnItem1 = new BigDecimal("55.00");
    BigDecimal netAmountOnItem2 = new BigDecimal("45.00");
    BigDecimal netAmountOnItem3 = null;
    ProjectItem projectItem = new ProjectItem();
    ProjectItem_OrderedAmount mixin = new ProjectItem_OrderedAmount(projectItem);
    mixin.orderItemRepository = mockOrderItemRepository;
    OrderItem orderItem1 = new OrderItem();
    orderItem1.setNetAmount(netAmountOnItem1);
    OrderItem orderItem2 = new OrderItem();
    orderItem2.setNetAmount(netAmountOnItem2);
    OrderItem orderItem3 = new OrderItem();
    orderItem3.setNetAmount(netAmountOnItem3);
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockOrderItemRepository).findByProjectAndCharge(null, null);
            will(returnValue(Arrays.asList(orderItem1, orderItem2, orderItem3)));
        }
    });
    // when
    BigDecimal orderedAmount = mixin.orderedAmount();
    // then
    Assertions.assertThat(orderedAmount).isEqualTo(expectedTotalNetAmountOnItems);
}
Also used : Expectations(org.jmock.Expectations) ProjectItem(org.estatio.module.capex.dom.project.ProjectItem) OrderItem(org.estatio.module.capex.dom.order.OrderItem) ProjectItem_OrderedAmount(org.estatio.module.capex.dom.order.contributions.ProjectItem_OrderedAmount) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 4 with OrderItem

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

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

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