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));
}
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;
}
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;
}
Aggregations