Search in sources :

Example 1 with BudgetOverrideValue

use of org.estatio.module.budgetassignment.dom.override.BudgetOverrideValue 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 2 with BudgetOverrideValue

use of org.estatio.module.budgetassignment.dom.override.BudgetOverrideValue in project estatio by estatio.

the class BudgetCalculationResult method calculate.

@Programmatic
public void calculate() throws IllegalArgumentException {
    validateOverrides();
    BigDecimal valueCalculatedByBudget = valueAsCalculatedByBudget();
    BigDecimal annualOverrideValue = BigDecimal.ZERO;
    List<Charge> incomingChargesOnOverrides = new ArrayList<>();
    if (overrideValueForInvoiceCharge() != null) {
        // SCENARIO: one override for all
        annualOverrideValue = annualOverrideValue.add(overrideValueForInvoiceCharge().getValue());
    } else {
        // SCENARIO: overrides on incoming charge level
        BigDecimal valueToSubtract = BigDecimal.ZERO;
        for (BudgetOverrideValue value : getOverrideValues()) {
            incomingChargesOnOverrides.add(value.getBudgetOverride().getIncomingCharge());
            annualOverrideValue = annualOverrideValue.add(value.getValue());
        }
        for (Charge charge : incomingChargesOnOverrides) {
            for (BudgetCalculation calculation : getBudgetCalculations().stream().filter(x -> x.getIncomingCharge().equals(charge)).collect(Collectors.toList())) {
                valueToSubtract = valueToSubtract.add(calculation.getValue());
            }
        }
        annualOverrideValue = annualOverrideValue.add(valueCalculatedByBudget).subtract(valueToSubtract);
    }
    BigDecimal overrideValue = annualOverrideValue.multiply(getFractionOfYear());
    setValue(overrideValue.setScale(2, BigDecimal.ROUND_HALF_UP));
    setShortfall(valueCalculatedByBudget.subtract(overrideValue).setScale(2, BigDecimal.ROUND_HALF_UP));
}
Also used : IdGeneratorStrategy(javax.jdo.annotations.IdGeneratorStrategy) BudgetOverrideValue(org.estatio.module.budgetassignment.dom.override.BudgetOverrideValue) BudgetOverrideRepository(org.estatio.module.budgetassignment.dom.override.BudgetOverrideRepository) Setter(lombok.Setter) Getter(lombok.Getter) BudgetCalculationRepository(org.estatio.module.budget.dom.budgetcalculation.BudgetCalculationRepository) Column(javax.jdo.annotations.Column) RepositoryService(org.apache.isis.applib.services.repository.RepositoryService) VersionStrategy(javax.jdo.annotations.VersionStrategy) Unique(javax.jdo.annotations.Unique) Programmatic(org.apache.isis.applib.annotation.Programmatic) ArrayList(java.util.ArrayList) PropertyLayout(org.apache.isis.applib.annotation.PropertyLayout) Inject(javax.inject.Inject) ActionLayout(org.apache.isis.applib.annotation.ActionLayout) BigDecimal(java.math.BigDecimal) IdentityType(javax.jdo.annotations.IdentityType) Action(org.apache.isis.applib.annotation.Action) Occupancy(org.estatio.module.lease.dom.occupancy.Occupancy) BudgetOverride(org.estatio.module.budgetassignment.dom.override.BudgetOverride) Charge(org.estatio.module.charge.dom.Charge) BudgetCalculation(org.estatio.module.budget.dom.budgetcalculation.BudgetCalculation) Where(org.apache.isis.applib.annotation.Where) Collectors(java.util.stream.Collectors) Query(javax.jdo.annotations.Query) Auditing(org.apache.isis.applib.annotation.Auditing) ApplicationTenancy(org.isisaddons.module.security.dom.tenancy.ApplicationTenancy) SemanticsOf(org.apache.isis.applib.annotation.SemanticsOf) List(java.util.List) DomainObject(org.apache.isis.applib.annotation.DomainObject) UdoDomainObject2(org.estatio.module.base.dom.UdoDomainObject2) TitleBuilder(org.incode.module.base.dom.utils.TitleBuilder) Contributed(org.apache.isis.applib.annotation.Contributed) Publishing(org.apache.isis.applib.annotation.Publishing) Charge(org.estatio.module.charge.dom.Charge) ArrayList(java.util.ArrayList) BudgetOverrideValue(org.estatio.module.budgetassignment.dom.override.BudgetOverrideValue) BigDecimal(java.math.BigDecimal) BudgetCalculation(org.estatio.module.budget.dom.budgetcalculation.BudgetCalculation) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 3 with BudgetOverrideValue

use of org.estatio.module.budgetassignment.dom.override.BudgetOverrideValue in project estatio by estatio.

the class BudgetAssignmentService method getDetailedCalculationResults.

public List<DetailedCalculationResultViewmodel> getDetailedCalculationResults(final Lease lease, final Budget budget, final BudgetCalculationType type) {
    List<DetailedCalculationResultViewmodel> results = new ArrayList<>();
    BudgetCalculationRun runForLease = budgetCalculationRunRepository.findUnique(lease, budget, type);
    if (runForLease == null) {
        return results;
    }
    for (BudgetCalculationResult result : runForLease.getBudgetCalculationResults()) {
        // scenario: one override for incoming charge
        if (result.overrideValueForInvoiceCharge() != null) {
            results.add(new DetailedCalculationResultViewmodel(lease.primaryOccupancy().get().getUnit(), "Override for total " + result.getInvoiceCharge().getDescription(), result.getValue().add(result.getShortfall()), result.getValue(), result.getShortfall(), null, result.getInvoiceCharge()));
        } else {
            for (BudgetCalculation calculation : result.getBudgetCalculations()) {
                BigDecimal effectiveValueForIncomingCharge = calculation.getEffectiveValue();
                BigDecimal shortFallForIncomingCharge = BigDecimal.ZERO;
                BigDecimal valueInBudget = BigDecimal.ZERO;
                DetailedCalculationResultViewmodel vm = new DetailedCalculationResultViewmodel(calculation.getUnit(), calculation.getIncomingCharge().getDescription(), calculation.getEffectiveValue(), valueInBudget, effectiveValueForIncomingCharge, shortFallForIncomingCharge, calculation.getInvoiceCharge());
                // set value in Budget
                PartitionItem partitionItem = calculation.getPartitionItem();
                BudgetItem budgetItem = calculation.getBudgetItem();
                BigDecimal valueForBudgetItem = type == BudgetCalculationType.BUDGETED ? budgetItem.getBudgetedValue() : budgetItem.getAuditedValue();
                valueInBudget = valueForBudgetItem;
                vm.setTotalValueInBudget(valueInBudget);
                // set possible overrides for incoming charge
                for (BudgetOverrideValue overrideValue : result.getOverrideValues()) {
                    if (overrideValue.getBudgetOverride().getIncomingCharge() == calculation.getIncomingCharge() && overrideValue.getType() == type) {
                        effectiveValueForIncomingCharge = overrideValue.getValue().multiply(calculation.getPartitionItem().getPartitioning().getFractionOfYear());
                        shortFallForIncomingCharge = calculation.getEffectiveValue().subtract(effectiveValueForIncomingCharge);
                    }
                }
                if (effectiveValueForIncomingCharge != BigDecimal.ZERO) {
                    vm.setEffectiveValueForLease(effectiveValueForIncomingCharge);
                    vm.setShortfall(shortFallForIncomingCharge);
                }
                results.add(vm);
            }
        }
    }
    return results;
}
Also used : BudgetItem(org.estatio.module.budget.dom.budgetitem.BudgetItem) ArrayList(java.util.ArrayList) BudgetOverrideValue(org.estatio.module.budgetassignment.dom.override.BudgetOverrideValue) BudgetCalculationRun(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationRun) BigDecimal(java.math.BigDecimal) PartitionItem(org.estatio.module.budget.dom.partioning.PartitionItem) BudgetCalculationResult(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult) BudgetCalculation(org.estatio.module.budget.dom.budgetcalculation.BudgetCalculation)

Aggregations

BigDecimal (java.math.BigDecimal)3 BudgetOverrideValue (org.estatio.module.budgetassignment.dom.override.BudgetOverrideValue)3 ArrayList (java.util.ArrayList)2 BudgetCalculation (org.estatio.module.budget.dom.budgetcalculation.BudgetCalculation)2 Charge (org.estatio.module.charge.dom.Charge)2 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Column (javax.jdo.annotations.Column)1 IdGeneratorStrategy (javax.jdo.annotations.IdGeneratorStrategy)1 IdentityType (javax.jdo.annotations.IdentityType)1 Query (javax.jdo.annotations.Query)1 Unique (javax.jdo.annotations.Unique)1 VersionStrategy (javax.jdo.annotations.VersionStrategy)1 Getter (lombok.Getter)1 Setter (lombok.Setter)1 Action (org.apache.isis.applib.annotation.Action)1 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)1 Auditing (org.apache.isis.applib.annotation.Auditing)1 Contributed (org.apache.isis.applib.annotation.Contributed)1