Search in sources :

Example 6 with BudgetItem

use of org.estatio.module.budget.dom.budgetitem.BudgetItem 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 7 with BudgetItem

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

the class PartitioningBuilder method execute.

@Override
protected void execute(final ExecutionContext executionContext) {
    checkParam("budget", executionContext, Budget.class);
    defaultParam("startDate", executionContext, budget.getStartDate());
    defaultParam("endDate", executionContext, budget.getEndDate());
    defaultParam("budgetCalculationType", executionContext, BudgetCalculationType.BUDGETED);
    Partitioning partitioning = partitioningRepository.newPartitioning(budget, startDate, endDate, budgetCalculationType);
    executionContext.addResult(this, partitioning);
    for (ItemSpec spec : itemSpec) {
        final Charge itemCharge = spec.itemCharge;
        final BudgetItem budgetItem = budget.findByCharge(itemCharge);
        PartitionItem partitionItem = partitionItemRepository.newPartitionItem(partitioning, spec.charge, spec.keyTable, budgetItem, spec.percentage);
        executionContext.addResult(this, partitionItem);
    }
    object = partitioning;
}
Also used : Partitioning(org.estatio.module.budget.dom.partioning.Partitioning) BudgetItem(org.estatio.module.budget.dom.budgetitem.BudgetItem) Charge(org.estatio.module.charge.dom.Charge) PartitionItem(org.estatio.module.budget.dom.partioning.PartitionItem)

Example 8 with BudgetItem

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

the class PartitionItemImport method importData.

@Programmatic
@Override
public List<Object> importData(final Object previousRow) {
    Property property = propertyRepository.findPropertyByReference(propertyReference);
    if (property == null)
        throw new ApplicationException(String.format("Property with reference [%s] not found.", propertyReference));
    final Budget budget = budgetRepository.findOrCreateBudget(property, startDate, endDate);
    final KeyTable keyTable = keyTableRepository.findOrCreateBudgetKeyTable(budget, keyTableName, FoundationValueType.MANUAL, KeyValueMethod.PERCENT, 6);
    findOrCreateBudgetKeyItem(keyTable, unitRepository.findUnitByReference(unitReference), keyValue, sourceValue);
    final Charge charge = fetchCharge(budgetChargeReference);
    final BudgetItem butgetItem = findOrCreateBudgetItem(budget, charge, budgetValue);
    final Charge scheduleCharge = fetchCharge(invoiceChargeReference);
    final Partitioning partitioning = findOrCreatePartitioning(budget);
    findOrCreatePartitionItem(partitioning, scheduleCharge, butgetItem, keyTable, percentage);
    return Lists.newArrayList();
}
Also used : ApplicationException(org.apache.isis.applib.ApplicationException) BudgetItem(org.estatio.module.budget.dom.budgetitem.BudgetItem) Partitioning(org.estatio.module.budget.dom.partioning.Partitioning) Charge(org.estatio.module.charge.dom.Charge) Budget(org.estatio.module.budget.dom.budget.Budget) KeyTable(org.estatio.module.budget.dom.keytable.KeyTable) Property(org.estatio.module.asset.dom.Property) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 9 with BudgetItem

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

the class PartitionItemImport method findOrCreateBudgetItem.

private BudgetItem findOrCreateBudgetItem(final Budget budget, final Charge charge, final BigDecimal value) {
    BudgetItem budgetItem = budgetItemRepository.findByBudgetAndCharge(budget, charge);
    if (budgetItem == null) {
        budgetItem = budgetItemRepository.newBudgetItem(budget, charge);
        budgetItem.newValue(value, budget.getStartDate(), BudgetCalculationType.BUDGETED);
        return budgetItem;
    }
    return budgetItem;
}
Also used : BudgetItem(org.estatio.module.budget.dom.budgetitem.BudgetItem)

Example 10 with BudgetItem

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

the class Budget_Remove method removeBudget.

@Action(semantics = SemanticsOf.NON_IDEMPOTENT_ARE_YOU_SURE)
@ActionLayout(contributed = Contributed.AS_ACTION)
public void removeBudget(@ParameterLayout(named = "This will delete the budget and all associated data including keytables, calculations, runs, results and lease terms. (You may consider downloading the budget and the keytables beforehand.) Are you sure?") final boolean areYouSure) {
    // delete results and runs
    for (BudgetCalculationRun run : budgetCalculationRunRepository.allBudgetCalculationRuns().stream().filter(x -> x.getBudget().equals(budget)).collect(Collectors.toList())) {
        for (BudgetCalculationResult result : run.getBudgetCalculationResults()) {
            // delete links and lease terms
            for (BudgetCalculationResultLink link : budgetCalculationResultLinkRepository.findByCalculationResult(result)) {
                LeaseTermForServiceCharge leaseTermToRemove = null;
                if (link.getLeaseTermForServiceCharge() != null) {
                    leaseTermToRemove = link.getLeaseTermForServiceCharge();
                }
                link.remove();
                if (leaseTermToRemove != null) {
                    leaseTermToRemove.remove();
                }
            }
        }
        run.remove();
    }
    // delete overrides and values
    for (Lease lease : leaseRepository.findByAssetAndActiveOnDate(budget.getProperty(), budget.getStartDate())) {
        for (BudgetOverride override : budgetOverrideRepository.findByLease(lease)) {
            override.remove();
        }
    }
    // delete partition items
    for (BudgetItem budgetItem : budget.getItems()) {
        for (PartitionItem item : partitionItemRepository.findByBudgetItem(budgetItem)) {
            item.remove();
        }
    }
    budget.remove();
}
Also used : BudgetOverrideRepository(org.estatio.module.budgetassignment.dom.override.BudgetOverrideRepository) BudgetCalculationRepository(org.estatio.module.budget.dom.budgetcalculation.BudgetCalculationRepository) EstatioRole(org.estatio.module.base.dom.EstatioRole) Lease(org.estatio.module.lease.dom.Lease) Inject(javax.inject.Inject) ActionLayout(org.apache.isis.applib.annotation.ActionLayout) BudgetCalculationRun(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationRun) Budget(org.estatio.module.budget.dom.budget.Budget) UserService(org.apache.isis.applib.services.user.UserService) Action(org.apache.isis.applib.annotation.Action) LeaseTermForServiceCharge(org.estatio.module.lease.dom.LeaseTermForServiceCharge) BudgetOverride(org.estatio.module.budgetassignment.dom.override.BudgetOverride) PartitionItem(org.estatio.module.budget.dom.partioning.PartitionItem) BudgetCalculationType(org.estatio.module.budget.dom.budgetcalculation.BudgetCalculationType) BudgetCalculationResultLinkRepository(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResultLinkRepository) BudgetCalculationResult(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult) BudgetCalculationResultLink(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResultLink) Collectors(java.util.stream.Collectors) PartitionItemRepository(org.estatio.module.budget.dom.partioning.PartitionItemRepository) LeaseRepository(org.estatio.module.lease.dom.LeaseRepository) Mixin(org.apache.isis.applib.annotation.Mixin) SemanticsOf(org.apache.isis.applib.annotation.SemanticsOf) ParameterLayout(org.apache.isis.applib.annotation.ParameterLayout) Contributed(org.apache.isis.applib.annotation.Contributed) BudgetCalculationRunRepository(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationRunRepository) BudgetItem(org.estatio.module.budget.dom.budgetitem.BudgetItem) BudgetCalculationResultLink(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResultLink) Lease(org.estatio.module.lease.dom.Lease) BudgetOverride(org.estatio.module.budgetassignment.dom.override.BudgetOverride) BudgetItem(org.estatio.module.budget.dom.budgetitem.BudgetItem) LeaseTermForServiceCharge(org.estatio.module.lease.dom.LeaseTermForServiceCharge) BudgetCalculationRun(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationRun) PartitionItem(org.estatio.module.budget.dom.partioning.PartitionItem) BudgetCalculationResult(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult) Action(org.apache.isis.applib.annotation.Action) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

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