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