Search in sources :

Example 6 with PartitionItem

use of org.estatio.module.budget.dom.partioning.PartitionItem 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)

Example 7 with PartitionItem

use of org.estatio.module.budget.dom.partioning.PartitionItem in project estatio by estatio.

the class BudgetImportExportService method createLines.

private List<BudgetImportExport> createLines(final BudgetItem item, final BudgetImportExportManager manager) {
    List<BudgetImportExport> lines = new ArrayList<>();
    String propertyReference = manager.getBudget().getProperty().getReference();
    LocalDate budgetStartDate = manager.getBudget().getStartDate();
    LocalDate budgetEndDate = manager.getBudget().getEndDate();
    String budgetChargeReference = item.getCharge().getReference();
    BigDecimal budgetedValue = item.getBudgetedValue();
    BigDecimal auditedValue = item.getAuditedValue();
    if (item.getPartitionItems().size() == 0) {
        // create 1 line
        lines.add(new BudgetImportExport(propertyReference, budgetStartDate, budgetEndDate, budgetChargeReference, budgetedValue, auditedValue, null, null, null, null, null));
    } else {
        // create a line for each partion item
        for (PartitionItem partitionItem : item.getPartitionItems()) {
            String keyTableName = partitionItem.getKeyTable().getName();
            String foundationValueType = partitionItem.getKeyTable().getFoundationValueType().toString();
            String keyValueMethod = partitionItem.getKeyTable().getKeyValueMethod().toString();
            String allocationChargeReference = partitionItem.getCharge().getReference();
            BigDecimal percentage = partitionItem.getPercentage();
            lines.add(new BudgetImportExport(propertyReference, budgetStartDate, budgetEndDate, budgetChargeReference, budgetedValue, auditedValue, keyTableName, foundationValueType, keyValueMethod, allocationChargeReference, percentage));
        }
    }
    return lines;
}
Also used : ArrayList(java.util.ArrayList) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) PartitionItem(org.estatio.module.budget.dom.partioning.PartitionItem)

Aggregations

PartitionItem (org.estatio.module.budget.dom.partioning.PartitionItem)7 BudgetItem (org.estatio.module.budget.dom.budgetitem.BudgetItem)5 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 Action (org.apache.isis.applib.annotation.Action)2 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)2 Budget (org.estatio.module.budget.dom.budget.Budget)2 BudgetCalculationResult (org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult)2 BudgetCalculationRun (org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationRun)2 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Contributed (org.apache.isis.applib.annotation.Contributed)1 Mixin (org.apache.isis.applib.annotation.Mixin)1 ParameterLayout (org.apache.isis.applib.annotation.ParameterLayout)1 Programmatic (org.apache.isis.applib.annotation.Programmatic)1 SemanticsOf (org.apache.isis.applib.annotation.SemanticsOf)1 UserService (org.apache.isis.applib.services.user.UserService)1 Property (org.estatio.module.asset.dom.Property)1 EstatioRole (org.estatio.module.base.dom.EstatioRole)1 BudgetCalculation (org.estatio.module.budget.dom.budgetcalculation.BudgetCalculation)1