Search in sources :

Example 1 with BudgetCalculation

use of org.estatio.module.budget.dom.budgetcalculation.BudgetCalculation 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 2 with BudgetCalculation

use of org.estatio.module.budget.dom.budgetcalculation.BudgetCalculation in project estatio by estatio.

the class BudgetOverride method getCalculatedValueByBudget.

@Programmatic
BigDecimal getCalculatedValueByBudget(final LocalDate budgetStartDate, final BudgetCalculationType type) {
    BigDecimal value = BigDecimal.ZERO;
    List<Unit> unitsForLease = new ArrayList<>();
    List<BudgetCalculation> calculationsForLeaseAndCharges = new ArrayList<>();
    for (Occupancy occupancy : getLease().getOccupancies()) {
        unitsForLease.add(occupancy.getUnit());
    }
    Budget budget = budgetRepository.findByPropertyAndDate(getLease().getProperty(), budgetStartDate);
    if (getIncomingCharge() == null) {
        for (Unit unit : unitsForLease) {
            calculationsForLeaseAndCharges.addAll(budgetCalculationRepository.findByBudgetAndUnitAndInvoiceChargeAndType(budget, unit, getInvoiceCharge(), type));
        }
    } else {
        for (Unit unit : unitsForLease) {
            calculationsForLeaseAndCharges.addAll(budgetCalculationRepository.findByBudgetAndUnitAndInvoiceChargeAndIncomingChargeAndType(budget, unit, getInvoiceCharge(), getIncomingCharge(), type));
        }
    }
    for (BudgetCalculation calculation : calculationsForLeaseAndCharges) {
        value = value.add(calculation.getEffectiveValue());
    }
    return value;
}
Also used : Occupancy(org.estatio.module.lease.dom.occupancy.Occupancy) ArrayList(java.util.ArrayList) Budget(org.estatio.module.budget.dom.budget.Budget) Unit(org.estatio.module.asset.dom.Unit) BigDecimal(java.math.BigDecimal) BudgetCalculation(org.estatio.module.budget.dom.budgetcalculation.BudgetCalculation) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 3 with BudgetCalculation

use of org.estatio.module.budget.dom.budgetcalculation.BudgetCalculation 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 ArrayList (java.util.ArrayList)3 BudgetCalculation (org.estatio.module.budget.dom.budgetcalculation.BudgetCalculation)3 Programmatic (org.apache.isis.applib.annotation.Programmatic)2 BudgetOverrideValue (org.estatio.module.budgetassignment.dom.override.BudgetOverrideValue)2 Occupancy (org.estatio.module.lease.dom.occupancy.Occupancy)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