Search in sources :

Example 21 with IncomingInvoiceItem

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

the class IncomingDocAsInvoiceViewModel method init.

@Programmatic
public void init() {
    IncomingInvoice incomingInvoice = getDomainObject();
    setIncomingInvoiceType(incomingInvoice.getType());
    setInvoiceNumber(incomingInvoice.getInvoiceNumber());
    setBuyer(incomingInvoice.getBuyer());
    setSeller(incomingInvoice.getSeller());
    setInvoiceDate(incomingInvoice.getInvoiceDate());
    setDueDate(incomingInvoice.getDueDate());
    setPaymentMethod(incomingInvoice.getPaymentMethod());
    setDateReceived(incomingInvoice.getDateReceived());
    setBankAccount(incomingInvoice.getBankAccount());
    setCurrency(incomingInvoice.getCurrency());
    final Optional<IncomingInvoiceItem> firstItemIfAny = getFirstItemIfAny();
    if (firstItemIfAny.isPresent()) {
        IncomingInvoiceItem invoiceItem = firstItemIfAny.get();
        setCharge(invoiceItem.getCharge());
        setDescription(invoiceItem.getDescription());
        setNetAmount(invoiceItem.getNetAmount());
        setVatAmount(invoiceItem.getVatAmount());
        setGrossAmount(invoiceItem.getGrossAmount());
        setTax(invoiceItem.getTax());
        setDueDate(invoiceItem.getDueDate());
        setPeriod(periodFrom(invoiceItem.getStartDate(), invoiceItem.getEndDate()));
        setProperty((org.estatio.module.asset.dom.Property) invoiceItem.getFixedAsset());
        setProject(invoiceItem.getProject());
        setBudgetItem(invoiceItem.getBudgetItem());
        final Optional<OrderItemInvoiceItemLink> linkIfAny = orderItemInvoiceItemLinkRepository.findByInvoiceItem(invoiceItem);
        linkIfAny.ifPresent(link -> {
            final OrderItem linkOrderItem = link.getOrderItem();
            IncomingDocAsInvoiceViewModel.this.setOrderItem(linkOrderItem);
        });
    } else {
        // for the first time we edit there will be no first item,
        // so we instead get the property from the header invoice
        setProperty(incomingInvoice.getProperty());
    }
}
Also used : OrderItemInvoiceItemLink(org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink) OrderItem(org.estatio.module.capex.dom.order.OrderItem) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) IncomingInvoiceItem(org.estatio.module.capex.dom.invoice.IncomingInvoiceItem) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 22 with IncomingInvoiceItem

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

the class OrderItem_createInvoiceItemLink method choices0Act.

public List<IncomingInvoiceItem> choices0Act() {
    // the disable guard ensures this is non-null
    final Party seller = mixee.getOrdr().getSeller();
    // candidates
    final List<IncomingInvoiceItem> invoiceItems = invoiceItemRepository.findBySeller(seller);
    // exclude any invoice items already linked to this order
    invoiceItems.removeAll(orderItemInvoiceItemLinkRepository.findLinkedInvoiceItemsByOrderItem(mixee));
    // exclude those where the net amount for the invoice item has already been linked to other order items
    for (Iterator<IncomingInvoiceItem> iterator = invoiceItems.iterator(); iterator.hasNext(); ) {
        final IncomingInvoiceItem invoiceItem = iterator.next();
        final BigDecimal netAmountNotLinked = orderItemInvoiceItemLinkRepository.calculateNetAmountNotLinkedFromInvoiceItem(invoiceItem);
        if (netAmountNotLinked.compareTo(BigDecimal.ZERO) <= 0) {
            iterator.remove();
        }
    }
    return invoiceItems;
}
Also used : Party(org.estatio.module.party.dom.Party) IncomingInvoiceItem(org.estatio.module.capex.dom.invoice.IncomingInvoiceItem) BigDecimal(java.math.BigDecimal)

Example 23 with IncomingInvoiceItem

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

the class IncomingInvoiceItemRepository_IntegTest method findByInvoiceAndChargeAndSequence_works.

@Test
public void findByInvoiceAndChargeAndSequence_works() throws Exception {
    // given
    IncomingInvoice invoice = createIncomingInvoiceAndTwoItemsWithSameCharge();
    // when
    Charge chargeToFindOnItem = charge;
    IncomingInvoiceItem item1 = incomingInvoiceItemRepository.findByInvoiceAndChargeAndSequence(invoice, chargeToFindOnItem, BigInteger.valueOf(1L));
    IncomingInvoiceItem item2 = incomingInvoiceItemRepository.findByInvoiceAndChargeAndSequence(invoice, chargeToFindOnItem, BigInteger.valueOf(2L));
    // then
    assertThat(item1.getInvoice()).isEqualTo(invoice);
    assertThat(item1.getCharge()).isEqualTo(charge);
    assertThat(item1.getSequence()).isEqualTo(BigInteger.valueOf(1L));
    assertThat(item2.getInvoice()).isEqualTo(invoice);
    assertThat(item2.getCharge()).isEqualTo(charge);
    assertThat(item2.getSequence()).isEqualTo(BigInteger.valueOf(2L));
    // and when
    Charge chargeNotToBeFoundOnItem = chargeRepository.findByReference("OTHER");
    IncomingInvoiceItem itemNotToBeFound = incomingInvoiceItemRepository.findByInvoiceAndChargeAndSequence(invoice, chargeNotToBeFoundOnItem, BigInteger.valueOf(1L));
    // then
    assertThat(itemNotToBeFound).isNull();
}
Also used : IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) Charge(org.estatio.module.charge.dom.Charge) IncomingInvoiceItem(org.estatio.module.capex.dom.invoice.IncomingInvoiceItem) Test(org.junit.Test)

Example 24 with IncomingInvoiceItem

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

the class IncomingInvoice_IntegTest method firstItemIsReported.

private IncomingInvoiceItem firstItemIsReported() {
    IncomingInvoiceItem reportedItem = (IncomingInvoiceItem) incomingInvoice.getItems().first();
    reportedItem.setReportedDate(LocalDate.now());
    return reportedItem;
}
Also used : IncomingInvoiceItem(org.estatio.module.capex.dom.invoice.IncomingInvoiceItem)

Example 25 with IncomingInvoiceItem

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

the class IncomingInvoice_IntegTest method when_incoming_invoice_type_is_changed_reported_items_are_reversed.

@Test
public void when_incoming_invoice_type_is_changed_reported_items_are_reversed() {
    // given
    incomingInvoiceSetup();
    incomingInvoiceIsCompleted();
    IncomingInvoiceItem reportedItem = firstItemIsReported();
    assertThat(reportedItem.getCharge()).isEqualTo(charge_for_marketing);
    IncomingInvoiceItem unreportedItem = (IncomingInvoiceItem) incomingInvoice.getItems().last();
    assertThat(unreportedItem.getCharge()).isEqualTo(charge_for_other);
    assertThat(incomingInvoice.getType()).isEqualTo(IncomingInvoiceType.CAPEX);
    assertThat(reportedItem.getIncomingInvoiceType()).isEqualTo(IncomingInvoiceType.CAPEX);
    assertThat(unreportedItem.getIncomingInvoiceType()).isEqualTo(IncomingInvoiceType.PROPERTY_EXPENSES);
    // when
    incomingInvoice.editType(IncomingInvoiceType.SERVICE_CHARGES, true);
    // then
    assertThat(incomingInvoice.getType()).isEqualTo(IncomingInvoiceType.SERVICE_CHARGES);
    assertThat(incomingInvoice.getItems().size()).isEqualTo(4);
    assertThat(unreportedItem.getIncomingInvoiceType()).isEqualTo(IncomingInvoiceType.SERVICE_CHARGES);
    assertThat(reportedItem.getIncomingInvoiceType()).isEqualTo(IncomingInvoiceType.CAPEX);
    IncomingInvoiceItem reversalOfReportedItem = incomingInvoiceItemRepository.findByInvoiceAndChargeAndSequence(incomingInvoice, charge_for_marketing, BigInteger.valueOf(3));
    assertThat(reversalOfReportedItem.getCharge()).isEqualTo(charge_for_marketing);
    assertThat(reversalOfReportedItem.getIncomingInvoiceType()).isEqualTo(IncomingInvoiceType.CAPEX);
    IncomingInvoiceItem correctionOfReportedItem = incomingInvoiceItemRepository.findByInvoiceAndChargeAndSequence(incomingInvoice, charge_for_marketing, BigInteger.valueOf(4));
    assertThat(reversalOfReportedItem.getCharge()).isEqualTo(charge_for_marketing);
    assertThat(correctionOfReportedItem.getIncomingInvoiceType()).isEqualTo(IncomingInvoiceType.SERVICE_CHARGES);
    // and when changing type again
    incomingInvoice.editType(IncomingInvoiceType.PROPERTY_EXPENSES, true);
    // then still
    assertThat(incomingInvoice.getItems().size()).isEqualTo(4);
    assertThat(incomingInvoice.getType()).isEqualTo(IncomingInvoiceType.PROPERTY_EXPENSES);
}
Also used : IncomingInvoiceItem(org.estatio.module.capex.dom.invoice.IncomingInvoiceItem) Test(org.junit.Test)

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