use of org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult 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.BudgetCalculationResult 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.BudgetCalculationResult in project estatio by estatio.
the class BudgetAssignmentService method createBudgetCalculationResults.
public void createBudgetCalculationResults(final BudgetCalculationRun run) {
run.removeCalculationResults();
for (Partitioning partitioning : run.getBudget().getPartitionings()) {
for (Charge invoiceCharge : partitioning.getDistinctInvoiceCharges()) {
BudgetCalculationResult result = run.createCalculationResult(invoiceCharge);
result.calculate();
}
}
}
use of org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult in project estatio by estatio.
the class BudgetAssignmentService_Test method findOrCreateLeaseItemForServiceChargeBudgeted_returns_active_item_when_found.
@Test
public void findOrCreateLeaseItemForServiceChargeBudgeted_returns_active_item_when_found() throws Exception {
// given
LeaseItem itemToBeFound = new LeaseItem();
Lease lease = new Lease() {
@Override
public LeaseItem findFirstActiveItemOfTypeAndChargeOnDate(final LeaseItemType leaseItemType, final Charge charge, final LocalDate date) {
return itemToBeFound;
}
};
BudgetCalculationResult budgetCalculationResult = new BudgetCalculationResult();
LocalDate termStartDate = new LocalDate(2018, 1, 1);
// when
LeaseItem itemFound = budgetAssignmentService.findOrCreateLeaseItemForServiceChargeBudgeted(lease, budgetCalculationResult, termStartDate);
// then
assertThat(itemFound).isEqualTo(itemToBeFound);
}
use of org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult 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();
}
Aggregations