Search in sources :

Example 11 with Charge

use of org.estatio.module.charge.dom.Charge in project estatio by estatio.

the class BudgetOverrideValueRepository_IntegTest method findOrCreateBudgetOverrideValueWorks.

@Test
public void findOrCreateBudgetOverrideValueWorks() {
    BudgetOverrideForFixed budgetOverrideForFixed;
    BudgetOverrideValue budgetOverrideValue;
    BigDecimal calculatedValue = new BigDecimal("1234.56");
    // given
    Lease leaseTopModel = Lease_enum.OxfTopModel001Gb.findUsing(serviceRegistry);
    Charge invoiceCharge = Charge_enum.GbServiceCharge.findUsing(serviceRegistry);
    BigDecimal overrideValue = new BigDecimal("1234.56");
    String reason = "Some reason";
    budgetOverrideForFixed = wrap(budgetOverrideRepository).newBudgetOverrideForFixed(overrideValue, leaseTopModel, null, null, invoiceCharge, null, null, reason);
    assertThat(budgetOverrideValueRepository.allBudgetOverrideValues().size()).isEqualTo(0);
    // when
    budgetOverrideValue = wrap(budgetOverrideValueRepository).findOrCreateOverrideValue(calculatedValue, budgetOverrideForFixed, BudgetCalculationType.BUDGETED);
    // then
    assertThat(budgetOverrideValueRepository.allBudgetOverrideValues().size()).isEqualTo(1);
    assertThat(budgetOverrideValue.getValue()).isEqualTo(calculatedValue);
    assertThat(budgetOverrideValue.getBudgetOverride()).isEqualTo(budgetOverrideForFixed);
    assertThat(budgetOverrideValue.getType()).isEqualTo(BudgetCalculationType.BUDGETED);
    assertThat(budgetOverrideValue.getStatus()).isEqualTo(Status.NEW);
    assertThat(budgetOverrideValue.getApplicationTenancy()).isEqualTo(budgetOverrideForFixed.getApplicationTenancy());
    // and when again
    budgetOverrideValue = wrap(budgetOverrideValueRepository).findOrCreateOverrideValue(calculatedValue, budgetOverrideForFixed, BudgetCalculationType.BUDGETED);
    // then still
    assertThat(budgetOverrideValueRepository.allBudgetOverrideValues().size()).isEqualTo(1);
}
Also used : Lease(org.estatio.module.lease.dom.Lease) Charge(org.estatio.module.charge.dom.Charge) BudgetOverrideValue(org.estatio.module.budgetassignment.dom.override.BudgetOverrideValue) BudgetOverrideForFixed(org.estatio.module.budgetassignment.dom.override.BudgetOverrideForFixed) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 12 with Charge

use of org.estatio.module.charge.dom.Charge in project estatio by estatio.

the class OrderItemRepository_Test method upsert_works.

@Test
public void upsert_works() throws Exception {
    // given
    OrderItemRepository orderItemRepository = new OrderItemRepository() {

        @Override
        public OrderItem findByOrderAndCharge(final Order order, final Charge charge) {
            return orderItem;
        }
    };
    String description = new String("some description");
    BigDecimal netAmount = BigDecimal.ZERO;
    BigDecimal vatAmount = BigDecimal.ONE;
    BigDecimal grossAmount = BigDecimal.TEN;
    Tax tax = new Tax();
    LocalDate startDate = new LocalDate(2017, 1, 1);
    LocalDate endDate = new LocalDate(2017, 1, 2);
    Property property = new Property();
    Project project = new Project();
    BudgetItem budgetItem = new BudgetItem();
    assertThat(orderItem.getOrdr()).isNull();
    assertThat(orderItem.getCharge()).isNull();
    // when
    orderItemRepository.upsert(mockOrder, mockCharge, description, netAmount, vatAmount, grossAmount, tax, startDate, endDate, property, project, budgetItem);
    // then
    assertThat(orderItem.getOrdr()).isNull();
    assertThat(orderItem.getCharge()).isNull();
    assertThat(orderItem.getDescription()).isEqualTo(description);
    assertThat(orderItem.getNetAmount()).isEqualTo(netAmount);
    assertThat(orderItem.getVatAmount()).isEqualTo(vatAmount);
    assertThat(orderItem.getGrossAmount()).isEqualTo(grossAmount);
    assertThat(orderItem.getTax()).isEqualTo(tax);
    assertThat(orderItem.getStartDate()).isEqualTo(startDate);
    assertThat(orderItem.getEndDate()).isEqualTo(endDate);
    assertThat(orderItem.getProperty()).isEqualTo(property);
    assertThat(orderItem.getProject()).isEqualTo(project);
    assertThat(orderItem.getBudgetItem()).isEqualTo(budgetItem);
}
Also used : Project(org.estatio.module.capex.dom.project.Project) BudgetItem(org.estatio.module.budget.dom.budgetitem.BudgetItem) Charge(org.estatio.module.charge.dom.Charge) Tax(org.estatio.module.tax.dom.Tax) LocalDate(org.joda.time.LocalDate) Property(org.estatio.module.asset.dom.Property) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 13 with Charge

use of org.estatio.module.charge.dom.Charge in project estatio by estatio.

the class Order_Test method minimalRequiredDataToComplete.

@Test
public void minimalRequiredDataToComplete() throws Exception {
    // given
    Order order = new Order();
    OrderItem item1 = new OrderItem();
    order.getItems().add(item1);
    // when
    String result = order.reasonIncomplete();
    // then
    assertThat(result).isEqualTo("order number, buyer, seller, (on item) description, charge, start date, end date, net amount, gross amount required");
    // and when
    order.setOrderNumber("123");
    item1.setNetAmount(new BigDecimal("100"));
    result = order.reasonIncomplete();
    // then
    assertThat(result).isEqualTo("buyer, seller, (on item) description, charge, start date, end date, gross amount required");
    // and when
    order.setBuyer(new Organisation());
    order.setSeller(new Organisation());
    item1.setDescription("blah");
    item1.setGrossAmount(BigDecimal.ZERO);
    item1.setCharge(new Charge());
    item1.setStartDate(new LocalDate());
    item1.setEndDate(new LocalDate());
    result = order.reasonIncomplete();
    // then
    assertThat(result).isNull();
}
Also used : 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)

Example 14 with Charge

use of org.estatio.module.charge.dom.Charge in project estatio by estatio.

the class Project_Test method getBudgetedAmount_checks_items_on_normal_project.

@Test
public void getBudgetedAmount_checks_items_on_normal_project() throws Exception {
    // given
    Project project = new Project();
    ProjectItem projectItem1 = new ProjectItem();
    projectItem1.setBudgetedAmount(new BigDecimal("10.00"));
    project.getItems().add(projectItem1);
    ProjectItem projectItem2 = new ProjectItem();
    projectItem2.setBudgetedAmount(new BigDecimal("2.34"));
    // done for comparable for getItems returns sorted set
    projectItem2.setCharge(new Charge());
    project.getItems().add(projectItem2);
    // when
    BigDecimal budgetAmountParent = project.getBudgetedAmount();
    // then
    Assertions.assertThat(budgetAmountParent).isEqualTo(new BigDecimal("12.34"));
}
Also used : Charge(org.estatio.module.charge.dom.Charge) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 15 with Charge

use of org.estatio.module.charge.dom.Charge in project estatio by estatio.

the class IncomingDocAsInvoiceViewModel method save.

@Action(semantics = SemanticsOf.IDEMPOTENT)
@MemberOrder(sequence = "1")
public IncomingInvoice save() {
    IncomingInvoice incomingInvoice = getDomainObject();
    IncomingInvoiceType previousType = incomingInvoice.getType();
    incomingInvoice.setType(getIncomingInvoiceType());
    incomingInvoice.setInvoiceNumber(getInvoiceNumber());
    incomingInvoice.setBuyer(getBuyer());
    incomingInvoice.setSeller(getSeller());
    incomingInvoice.setInvoiceDate(getInvoiceDate());
    incomingInvoice.setDueDate(getDueDate());
    incomingInvoice.setPaymentMethod(getPaymentMethod());
    incomingInvoice.setCurrency(getCurrency());
    incomingInvoice.setDateReceived(getDateReceived());
    incomingInvoice.setBankAccount(getBankAccount());
    incomingInvoice.setNetAmount(getNetAmount());
    incomingInvoice.setGrossAmount(getGrossAmount());
    // if changed the type, then we need to re-evaluate the state machine
    if (previousType != getIncomingInvoiceType()) {
        stateTransitionService.trigger(incomingInvoice, IncomingInvoiceApprovalStateTransition.class, null, null, null);
    }
    // upsert invoice item
    // this will also update the parent header's property with that from the first item
    Optional<IncomingInvoiceItem> firstItemIfAny = getFirstItemIfAny();
    IncomingInvoiceItem firstItem;
    if (firstItemIfAny.isPresent()) {
        IncomingInvoiceItem item = firstItemIfAny.get();
        item.setIncomingInvoiceType(getIncomingInvoiceType());
        item.setCharge(getCharge());
        item.setDescription(getDescription());
        item.setNetAmount(getNetAmount());
        item.setVatAmount(getVatAmount());
        item.setGrossAmount(getGrossAmount());
        item.setTax(getTax());
        item.setStartDate(getStartDateFromPeriod());
        item.setEndDate(getEndDateFromPeriod());
        item.setFixedAsset(getProperty());
        item.setProject(getProject());
        item.setBudgetItem(getBudgetItem());
        firstItem = item;
    } else {
        firstItem = incomingInvoiceItemRepository.create(incomingInvoice.nextItemSequence(), incomingInvoice, incomingInvoiceType, getCharge(), getDescription(), getNetAmount(), getVatAmount(), getGrossAmount(), getTax(), getDueDate(), getStartDateFromPeriod(), getEndDateFromPeriod(), getProperty(), getProject(), getBudgetItem());
    }
    // 'switch view' will not be available subsequently because the Invoice/Item is "too complex")
    if (getOrderItem() != null) {
        Order order = getOrderItem().getOrdr();
        Charge chargeFromWrapper = getOrderItem().getCharge();
        OrderItem orderItemToLink = orderItemRepository.findByOrderAndCharge(order, chargeFromWrapper);
        orderItemInvoiceItemLinkRepository.findOrCreateLink(orderItemToLink, firstItem, firstItem.getNetAmount());
    } else {
        // remove all (or the one and only) link.
        final Optional<OrderItemInvoiceItemLink> links = orderItemInvoiceItemLinkRepository.findByInvoiceItem(firstItem);
        links.ifPresent(link -> {
            link.remove();
        });
    }
    return incomingInvoice;
}
Also used : Order(org.estatio.module.capex.dom.order.Order) MemberOrder(org.apache.isis.applib.annotation.MemberOrder) OrderItemInvoiceItemLink(org.estatio.module.capex.dom.orderinvoice.OrderItemInvoiceItemLink) IncomingInvoiceType(org.estatio.module.capex.dom.invoice.IncomingInvoiceType) OrderItem(org.estatio.module.capex.dom.order.OrderItem) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) IncomingInvoiceItem(org.estatio.module.capex.dom.invoice.IncomingInvoiceItem) Charge(org.estatio.module.charge.dom.Charge) Action(org.apache.isis.applib.annotation.Action) MemberOrder(org.apache.isis.applib.annotation.MemberOrder)

Aggregations

Charge (org.estatio.module.charge.dom.Charge)41 Test (org.junit.Test)18 BigDecimal (java.math.BigDecimal)14 LocalDate (org.joda.time.LocalDate)14 Lease (org.estatio.module.lease.dom.Lease)11 Programmatic (org.apache.isis.applib.annotation.Programmatic)10 BudgetItem (org.estatio.module.budget.dom.budgetitem.BudgetItem)9 Project (org.estatio.module.capex.dom.project.Project)9 Tax (org.estatio.module.tax.dom.Tax)9 Property (org.estatio.module.asset.dom.Property)7 LeaseItem (org.estatio.module.lease.dom.LeaseItem)6 ApplicationException (org.apache.isis.applib.ApplicationException)4 BudgetCalculationResult (org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult)4 ChargeGroup (org.estatio.module.charge.dom.ChargeGroup)4 Action (org.apache.isis.applib.annotation.Action)3 LeaseItemType (org.estatio.module.lease.dom.LeaseItemType)3 Organisation (org.estatio.module.party.dom.Organisation)3 ApplicationTenancy (org.isisaddons.module.security.dom.tenancy.ApplicationTenancy)3 Expectations (org.jmock.Expectations)3 ArrayList (java.util.ArrayList)2