Search in sources :

Example 1 with CalculationResult

use of org.estatio.module.lease.dom.invoicing.InvoiceCalculationService.CalculationResult in project estatio by estatio.

the class LeaseTermForTurnoverRent method doAlign.

// //////////////////////////////////////
@Override
protected void doAlign() {
    if (getStatus() != LeaseTermStatus.APPROVED) {
        // Collect all results
        BigDecimal newContractualRent = BigDecimal.ZERO;
        List<LeaseItemSource> sourceItems = getLeaseItem().getSourceItems();
        List<CalculationResult> calculationResults = new ArrayList<>();
        for (LeaseItemSource leaseItemSource : sourceItems) {
            // Make the calculation interval deliberately longer then the duration of the turnover rent term to make sure
            // that indexations that are done in retrospect are included in the calculation
            final LocalDateInterval calculationInterval = new LocalDateInterval(getStartDate(), getEndDate().plusYears(1));
            calculationResults.addAll(leaseItemSource.getSourceItem().calculationResults(calculationInterval));
        }
        // TODO: do prorata when intervals don't match
        for (CalculationResult result : calculationResults) {
            if (getInterval().contains(result.invoicingInterval().asLocalDateInterval())) {
                newContractualRent = newContractualRent.add(result.value());
            }
        }
        if (ObjectUtils.compare(getContractualRent(), newContractualRent) != 0) {
            setContractualRent(newContractualRent);
        }
        // Budgeted Turnover Rent
        if (getTotalBudgetedRent() != null) {
            BigDecimal newBudgetedTurnoverRent = getTotalBudgetedRent().subtract(getContractualRent());
            if (newBudgetedTurnoverRent.compareTo(BigDecimal.ZERO) < 0) {
                newBudgetedTurnoverRent = BigDecimal.ZERO;
            }
            if (ObjectUtils.compare(getBudgetedTurnoverRent(), newBudgetedTurnoverRent) != 0) {
                setBudgetedTurnoverRent(newBudgetedTurnoverRent);
            }
        }
        // Audited Turnover Rent
        if (getTurnoverRentRule() != null) {
            // Ignore the rule when empty
            TurnoverRentRuleHelper helper = new TurnoverRentRuleHelper(getTurnoverRentRule());
            BigDecimal newAuditedTurnoverRent = helper.calculateRent(getAuditedTurnover()).subtract(getContractualRent());
            if (ObjectUtils.compare(newAuditedTurnoverRent, BigDecimal.ZERO) < 0) {
                newAuditedTurnoverRent = BigDecimal.ZERO;
            }
            if (ObjectUtils.compare(getAuditedTurnoverRent(), newAuditedTurnoverRent) != 0) {
                setAuditedTurnoverRent(newAuditedTurnoverRent);
            }
        }
    }
}
Also used : CalculationResult(org.estatio.module.lease.dom.invoicing.InvoiceCalculationService.CalculationResult) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) LocalDateInterval(org.incode.module.base.dom.valuetypes.LocalDateInterval)

Aggregations

BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 CalculationResult (org.estatio.module.lease.dom.invoicing.InvoiceCalculationService.CalculationResult)1 LocalDateInterval (org.incode.module.base.dom.valuetypes.LocalDateInterval)1