use of org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationRun in project estatio by estatio.
the class BudgetAssignmentService method calculateResultsForLeases.
public List<BudgetCalculationRun> calculateResultsForLeases(final Budget budget, final BudgetCalculationType type) {
List<BudgetCalculationRun> results = new ArrayList<>();
for (Lease lease : leasesWithActiveOccupations(budget)) {
removeNewOverrideValues(lease);
calculateOverrideValues(lease, budget);
results.add(executeCalculationRun(lease, budget, type));
}
return results;
}
use of org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationRun in project estatio by estatio.
the class BudgetAssignmentService method assign.
public void assign(final Budget budget) {
for (BudgetCalculationRun run : budgetCalculationRunRepository.findByBudgetAndTypeAndStatus(budget, BudgetCalculationType.BUDGETED, Status.NEW)) {
for (BudgetCalculationResult resultForLease : run.getBudgetCalculationResults()) {
LocalDate termStartDate = run.getLease().getStartDate().isAfter(budget.getStartDate()) ? run.getLease().getStartDate() : budget.getStartDate();
LeaseItem leaseItem = findOrCreateLeaseItemForServiceChargeBudgeted(run.getLease(), resultForLease, termStartDate);
LeaseTermForServiceCharge leaseTerm = (LeaseTermForServiceCharge) leaseTermRepository.findOrCreateWithStartDate(leaseItem, new LocalDateInterval(termStartDate, budget.getEndDate()));
budgetCalculationResultLinkRepository.findOrCreateLink(resultForLease, leaseTerm);
leaseTerm.setBudgetedValue(resultForLease.getValue());
}
run.finalizeRun();
}
}
use of org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationRun in project estatio by estatio.
the class BudgetAssignmentService method getCalculationResults.
public List<CalculationResultViewModel> getCalculationResults(final Budget budget) {
List<CalculationResultViewModel> results = new ArrayList<>();
for (BudgetCalculationRun run : budgetCalculationRunRepository.findByBudgetAndType(budget, BudgetCalculationType.BUDGETED)) {
for (BudgetCalculationResult result : run.getBudgetCalculationResults()) {
CalculationResultViewModel vm = new CalculationResultViewModel(run.getLease(), result.getInvoiceCharge(), run.getType() == BudgetCalculationType.BUDGETED ? result.getValue().add(result.getShortfall()) : BigDecimal.ZERO, run.getType() == BudgetCalculationType.BUDGETED ? result.getValue() : BigDecimal.ZERO, run.getType() == BudgetCalculationType.BUDGETED ? result.getShortfall() : BigDecimal.ZERO, run.getType() == BudgetCalculationType.ACTUAL ? result.getValue().add(result.getShortfall()) : BigDecimal.ZERO, run.getType() == BudgetCalculationType.ACTUAL ? result.getValue() : BigDecimal.ZERO, run.getType() == BudgetCalculationType.ACTUAL ? result.getShortfall() : BigDecimal.ZERO);
String unitString = run.getLease().getOccupancies().first().getUnit().getReference();
if (run.getLease().getOccupancies().size() > 1) {
boolean skip = true;
for (Occupancy occupancy : run.getLease().getOccupancies()) {
if (skip) {
skip = false;
} else {
unitString = unitString.concat(" | ").concat(occupancy.getUnit().getReference());
}
}
}
vm.setUnit(unitString);
results.add(vm);
}
}
return results;
}
use of org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationRun in project estatio by estatio.
the class Budget_Remove method removeBudget.
@Action(semantics = SemanticsOf.NON_IDEMPOTENT_ARE_YOU_SURE)
@ActionLayout(contributed = Contributed.AS_ACTION)
public void removeBudget(@ParameterLayout(named = "This will delete the budget and all associated data including keytables, calculations, runs, results and lease terms. (You may consider downloading the budget and the keytables beforehand.) Are you sure?") final boolean areYouSure) {
// delete results and runs
for (BudgetCalculationRun run : budgetCalculationRunRepository.allBudgetCalculationRuns().stream().filter(x -> x.getBudget().equals(budget)).collect(Collectors.toList())) {
for (BudgetCalculationResult result : run.getBudgetCalculationResults()) {
// delete links and lease terms
for (BudgetCalculationResultLink link : budgetCalculationResultLinkRepository.findByCalculationResult(result)) {
LeaseTermForServiceCharge leaseTermToRemove = null;
if (link.getLeaseTermForServiceCharge() != null) {
leaseTermToRemove = link.getLeaseTermForServiceCharge();
}
link.remove();
if (leaseTermToRemove != null) {
leaseTermToRemove.remove();
}
}
}
run.remove();
}
// delete overrides and values
for (Lease lease : leaseRepository.findByAssetAndActiveOnDate(budget.getProperty(), budget.getStartDate())) {
for (BudgetOverride override : budgetOverrideRepository.findByLease(lease)) {
override.remove();
}
}
// delete partition items
for (BudgetItem budgetItem : budget.getItems()) {
for (PartitionItem item : partitionItemRepository.findByBudgetItem(budgetItem)) {
item.remove();
}
}
budget.remove();
}
use of org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationRun 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