Search in sources :

Example 1 with BudgetItem

use of org.estatio.module.budget.dom.budgetitem.BudgetItem in project estatio by estatio.

the class BudgetItemValueRepository_IntegTest method findUniqueTest.

@Test
public void findUniqueTest() {
    // given
    Property property = Property_enum.OxfGb.findUsing(serviceRegistry);
    Budget budget = budgetRepository.findByPropertyAndStartDate(property, new LocalDate(2015, 01, 01));
    BudgetItem budgetItem = budget.getItems().first();
    // when
    BudgetItemValue result = budgetItemValueRepository.findUnique(budgetItem, new LocalDate(2015, 01, 01), BudgetCalculationType.BUDGETED);
    // then
    assertThat(result.getDate()).isEqualTo(new LocalDate(2015, 01, 01));
    // and when
    result = budgetItemValueRepository.findUnique(budgetItem, new LocalDate(2015, 01, 02), BudgetCalculationType.BUDGETED);
    // then
    assertThat(result).isNull();
}
Also used : BudgetItem(org.estatio.module.budget.dom.budgetitem.BudgetItem) Budget(org.estatio.module.budget.dom.budget.Budget) BudgetItemValue(org.estatio.module.budget.dom.budgetitem.BudgetItemValue) Property(org.estatio.module.asset.dom.Property) LocalDate(org.joda.time.LocalDate) Test(org.junit.Test)

Example 2 with BudgetItem

use of org.estatio.module.budget.dom.budgetitem.BudgetItem in project estatio by estatio.

the class BudgetItemValueRepository_IntegTest method updateOrCreateTest_Update.

@Test
public void updateOrCreateTest_Update() {
    // given
    LocalDate budgetStart = new LocalDate(2015, 01, 01);
    Property property = Property_enum.OxfGb.findUsing(serviceRegistry);
    Budget budget = budgetRepository.findByPropertyAndStartDate(property, budgetStart);
    BudgetItem budgetItem = budget.getItems().first();
    assertThat(budgetItem.getValues().size()).isEqualTo(1);
    assertThat(budgetItem.getValues().first().getType()).isEqualTo(BudgetCalculationType.BUDGETED);
    assertThat(budgetItem.getValues().first().getValue()).isEqualTo(new BigDecimal("30000.55"));
    // when
    BudgetItemValue result = wrap(budgetItemValueRepository).updateOrCreateBudgetItemValue(new BigDecimal("33333.00"), budgetItem, budgetStart, BudgetCalculationType.BUDGETED);
    // then
    assertThat(budgetItem.getValues().size()).isEqualTo(1);
    assertThat(result.getValue()).isEqualTo(new BigDecimal("33333.00"));
}
Also used : BudgetItem(org.estatio.module.budget.dom.budgetitem.BudgetItem) Budget(org.estatio.module.budget.dom.budget.Budget) BudgetItemValue(org.estatio.module.budget.dom.budgetitem.BudgetItemValue) LocalDate(org.joda.time.LocalDate) Property(org.estatio.module.asset.dom.Property) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 3 with BudgetItem

use of org.estatio.module.budget.dom.budgetitem.BudgetItem in project estatio by estatio.

the class BudgetImportExport method removeExistingBudgetItemsIfNotLinked.

private void removeExistingBudgetItemsIfNotLinked() {
    Property property = propertyRepository.findPropertyByReference(getPropertyReference());
    Budget budget = budgetRepository.findOrCreateBudget(property, getBudgetStartDate(), getBudgetEndDate());
    for (BudgetItem item : budget.getItems()) {
        if (orderItemRepository.findByBudgetItem(item).size() == 0 && incomingInvoiceItemRepository.findByBudgetItem(item).size() == 0) {
            for (PartitionItem pItem : item.getPartitionItems()) {
                pItem.remove();
            }
            repositoryService.removeAndFlush(item);
        }
    }
}
Also used : BudgetItem(org.estatio.module.budget.dom.budgetitem.BudgetItem) Budget(org.estatio.module.budget.dom.budget.Budget) Property(org.estatio.module.asset.dom.Property) PartitionItem(org.estatio.module.budget.dom.partioning.PartitionItem)

Example 4 with BudgetItem

use of org.estatio.module.budget.dom.budgetitem.BudgetItem in project estatio by estatio.

the class BudgetImportExport method findOrCreateBudgetAndBudgetItem.

private BudgetItem findOrCreateBudgetAndBudgetItem(final Charge incomingCharge) {
    Property property = propertyRepository.findPropertyByReference(getPropertyReference());
    if (property == null)
        throw new ApplicationException(String.format("Property with reference [%s] not found.", getPropertyReference()));
    Budget budget = budgetRepository.findOrCreateBudget(property, getBudgetStartDate(), getBudgetEndDate());
    BudgetItem budgetItem = budget.findOrCreateBudgetItem(incomingCharge).updateOrCreateBudgetItemValue(getBudgetedValue(), getBudgetStartDate(), BudgetCalculationType.BUDGETED).updateOrCreateBudgetItemValue(getAuditedValue(), getBudgetEndDate(), BudgetCalculationType.ACTUAL);
    return budgetItem;
}
Also used : ApplicationException(org.apache.isis.applib.ApplicationException) BudgetItem(org.estatio.module.budget.dom.budgetitem.BudgetItem) Budget(org.estatio.module.budget.dom.budget.Budget) Property(org.estatio.module.asset.dom.Property)

Example 5 with BudgetItem

use of org.estatio.module.budget.dom.budgetitem.BudgetItem in project estatio by estatio.

the class IncomingInvoiceItemRepository_Test method upsert_works.

@Test
public void upsert_works() throws Exception {
    // given
    IncomingInvoiceItemRepository incomingInvoiceItemRepository = new IncomingInvoiceItemRepository() {

        @Override
        public IncomingInvoiceItem findByInvoiceAndChargeAndSequence(final IncomingInvoice invoice, final Charge charge, final BigInteger sequence) {
            return invoiceItem;
        }
    };
    BigInteger sequence = new BigInteger("1");
    String description = "";
    Tax tax = new Tax();
    LocalDate dueDate = new LocalDate(2017, 1, 1);
    LocalDate startDate = new LocalDate(2017, 1, 2);
    LocalDate endDate = new LocalDate(2017, 1, 3);
    Property property = new Property();
    Project project = new Project();
    BudgetItem budgetItem = new BudgetItem();
    IncomingInvoiceType type = IncomingInvoiceType.CORPORATE_EXPENSES;
    invoiceItem.setInvoice(mockInvoice);
    assertThat(invoiceItem.getInvoice()).isEqualTo(mockInvoice);
    assertThat(invoiceItem.getIncomingInvoiceType()).isNull();
    assertThat(invoiceItem.getCharge()).isNull();
    assertThat(invoiceItem.getSequence()).isNull();
    assertThat(invoiceItem.getDescription()).isNull();
    assertThat(invoiceItem.getNetAmount()).isNull();
    assertThat(invoiceItem.getVatAmount()).isNull();
    assertThat(invoiceItem.getGrossAmount()).isNull();
    assertThat(invoiceItem.getTax()).isNull();
    assertThat(invoiceItem.getDueDate()).isNull();
    assertThat(invoiceItem.getStartDate()).isNull();
    assertThat(invoiceItem.getEndDate()).isNull();
    assertThat(invoiceItem.getFixedAsset()).isNull();
    assertThat(invoiceItem.getProject()).isNull();
    // when
    incomingInvoiceItemRepository.upsert(sequence, mockInvoice, type, mockCharge, description, BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.TEN, tax, dueDate, startDate, endDate, property, project, budgetItem);
    // then
    // should not updated
    assertThat(invoiceItem.getInvoice()).isEqualTo(mockInvoice);
    // should not updated
    assertThat(invoiceItem.getCharge()).isNull();
    // should not be updated
    assertThat(invoiceItem.getIncomingInvoiceType()).isNull();
    assertThat(invoiceItem.getSequence()).isEqualTo(sequence);
    assertThat(invoiceItem.getDescription()).isEqualTo(description);
    assertThat(invoiceItem.getNetAmount()).isEqualTo(BigDecimal.ZERO);
    assertThat(invoiceItem.getVatAmount()).isEqualTo(BigDecimal.ONE);
    assertThat(invoiceItem.getGrossAmount()).isEqualTo(BigDecimal.TEN);
    assertThat(invoiceItem.getTax()).isEqualTo(tax);
    assertThat(invoiceItem.getDueDate()).isEqualTo(dueDate);
    assertThat(invoiceItem.getStartDate()).isEqualTo(startDate);
    assertThat(invoiceItem.getEndDate()).isEqualTo(endDate);
    assertThat(invoiceItem.getFixedAsset()).isEqualTo(property);
    assertThat(invoiceItem.getProject()).isEqualTo(project);
}
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) BigInteger(java.math.BigInteger) Tax(org.estatio.module.tax.dom.Tax) LocalDate(org.joda.time.LocalDate) Property(org.estatio.module.asset.dom.Property) Test(org.junit.Test)

Aggregations

BudgetItem (org.estatio.module.budget.dom.budgetitem.BudgetItem)22 Property (org.estatio.module.asset.dom.Property)11 Charge (org.estatio.module.charge.dom.Charge)9 LocalDate (org.joda.time.LocalDate)9 Test (org.junit.Test)9 BigDecimal (java.math.BigDecimal)8 Budget (org.estatio.module.budget.dom.budget.Budget)8 PartitionItem (org.estatio.module.budget.dom.partioning.PartitionItem)5 Project (org.estatio.module.capex.dom.project.Project)5 BudgetItemValue (org.estatio.module.budget.dom.budgetitem.BudgetItemValue)4 Tax (org.estatio.module.tax.dom.Tax)4 ArrayList (java.util.ArrayList)3 Programmatic (org.apache.isis.applib.annotation.Programmatic)3 ApplicationException (org.apache.isis.applib.ApplicationException)2 Action (org.apache.isis.applib.annotation.Action)2 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)2 Partitioning (org.estatio.module.budget.dom.partioning.Partitioning)2 BudgetCalculationResult (org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult)2 BudgetCalculationRun (org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationRun)2 Organisation (org.estatio.module.party.dom.Organisation)2