Search in sources :

Example 1 with BudgetCalculationResult

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();
    }
}
Also used : LeaseTermForServiceCharge(org.estatio.module.lease.dom.LeaseTermForServiceCharge) BudgetCalculationRun(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationRun) LocalDate(org.joda.time.LocalDate) LeaseItem(org.estatio.module.lease.dom.LeaseItem) LocalDateInterval(org.incode.module.base.dom.valuetypes.LocalDateInterval) BudgetCalculationResult(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult)

Example 2 with BudgetCalculationResult

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;
}
Also used : Occupancy(org.estatio.module.lease.dom.occupancy.Occupancy) ArrayList(java.util.ArrayList) BudgetCalculationRun(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationRun) BudgetCalculationResult(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult)

Example 3 with BudgetCalculationResult

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();
        }
    }
}
Also used : Partitioning(org.estatio.module.budget.dom.partioning.Partitioning) LeaseTermForServiceCharge(org.estatio.module.lease.dom.LeaseTermForServiceCharge) Charge(org.estatio.module.charge.dom.Charge) BudgetCalculationResult(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult)

Example 4 with BudgetCalculationResult

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);
}
Also used : Lease(org.estatio.module.lease.dom.Lease) Charge(org.estatio.module.charge.dom.Charge) LeaseItemType(org.estatio.module.lease.dom.LeaseItemType) LocalDate(org.joda.time.LocalDate) LeaseItem(org.estatio.module.lease.dom.LeaseItem) BudgetCalculationResult(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult) Test(org.junit.Test)

Example 5 with BudgetCalculationResult

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();
}
Also used : BudgetOverrideRepository(org.estatio.module.budgetassignment.dom.override.BudgetOverrideRepository) BudgetCalculationRepository(org.estatio.module.budget.dom.budgetcalculation.BudgetCalculationRepository) EstatioRole(org.estatio.module.base.dom.EstatioRole) Lease(org.estatio.module.lease.dom.Lease) Inject(javax.inject.Inject) ActionLayout(org.apache.isis.applib.annotation.ActionLayout) BudgetCalculationRun(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationRun) Budget(org.estatio.module.budget.dom.budget.Budget) UserService(org.apache.isis.applib.services.user.UserService) Action(org.apache.isis.applib.annotation.Action) LeaseTermForServiceCharge(org.estatio.module.lease.dom.LeaseTermForServiceCharge) BudgetOverride(org.estatio.module.budgetassignment.dom.override.BudgetOverride) PartitionItem(org.estatio.module.budget.dom.partioning.PartitionItem) BudgetCalculationType(org.estatio.module.budget.dom.budgetcalculation.BudgetCalculationType) BudgetCalculationResultLinkRepository(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResultLinkRepository) BudgetCalculationResult(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult) BudgetCalculationResultLink(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResultLink) Collectors(java.util.stream.Collectors) PartitionItemRepository(org.estatio.module.budget.dom.partioning.PartitionItemRepository) LeaseRepository(org.estatio.module.lease.dom.LeaseRepository) Mixin(org.apache.isis.applib.annotation.Mixin) SemanticsOf(org.apache.isis.applib.annotation.SemanticsOf) ParameterLayout(org.apache.isis.applib.annotation.ParameterLayout) Contributed(org.apache.isis.applib.annotation.Contributed) BudgetCalculationRunRepository(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationRunRepository) BudgetItem(org.estatio.module.budget.dom.budgetitem.BudgetItem) BudgetCalculationResultLink(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResultLink) Lease(org.estatio.module.lease.dom.Lease) BudgetOverride(org.estatio.module.budgetassignment.dom.override.BudgetOverride) BudgetItem(org.estatio.module.budget.dom.budgetitem.BudgetItem) LeaseTermForServiceCharge(org.estatio.module.lease.dom.LeaseTermForServiceCharge) BudgetCalculationRun(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationRun) PartitionItem(org.estatio.module.budget.dom.partioning.PartitionItem) BudgetCalculationResult(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult) Action(org.apache.isis.applib.annotation.Action) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

Aggregations

BudgetCalculationResult (org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult)8 BudgetCalculationRun (org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationRun)4 Charge (org.estatio.module.charge.dom.Charge)4 Lease (org.estatio.module.lease.dom.Lease)4 LocalDate (org.joda.time.LocalDate)4 LeaseItem (org.estatio.module.lease.dom.LeaseItem)3 LeaseTermForServiceCharge (org.estatio.module.lease.dom.LeaseTermForServiceCharge)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 BudgetItem (org.estatio.module.budget.dom.budgetitem.BudgetItem)2 PartitionItem (org.estatio.module.budget.dom.partioning.PartitionItem)2 Expectations (org.jmock.Expectations)2 BigDecimal (java.math.BigDecimal)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Action (org.apache.isis.applib.annotation.Action)1 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)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