Search in sources :

Example 6 with BudgetCalculationResult

use of org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult in project estatio by estatio.

the class BudgetAssignmentService_Test method findOrCreateLeaseItemForServiceChargeBudgeted_works_when_no_item_to_copy_from_found.

@Test
public void findOrCreateLeaseItemForServiceChargeBudgeted_works_when_no_item_to_copy_from_found() throws Exception {
    // given
    BudgetAssignmentService budgetAssignmentService = new BudgetAssignmentService() {

        @Override
        LeaseItem findItemToCopyFrom(final Lease lease) {
            return null;
        }
    };
    Charge charge = new Charge();
    BudgetCalculationResult budgetCalculationResult = new BudgetCalculationResult();
    budgetCalculationResult.setInvoiceCharge(charge);
    LocalDate termStartDate = new LocalDate(2018, 1, 1);
    InvoicingFrequency invoicingFrequencyGuess = InvoicingFrequency.QUARTERLY_IN_ADVANCE;
    PaymentMethod paymentMethodGuess = PaymentMethod.DIRECT_DEBIT;
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockLease).findFirstActiveItemOfTypeAndChargeOnDate(LeaseItemType.SERVICE_CHARGE, charge, termStartDate);
            will(returnValue(null));
            oneOf(mockLease).newItem(LeaseItemType.SERVICE_CHARGE, LeaseAgreementRoleTypeEnum.LANDLORD, budgetCalculationResult.getInvoiceCharge(), invoicingFrequencyGuess, paymentMethodGuess, termStartDate);
        }
    });
    // when
    budgetAssignmentService.findOrCreateLeaseItemForServiceChargeBudgeted(mockLease, budgetCalculationResult, termStartDate);
}
Also used : Expectations(org.jmock.Expectations) Lease(org.estatio.module.lease.dom.Lease) Charge(org.estatio.module.charge.dom.Charge) PaymentMethod(org.estatio.module.invoice.dom.PaymentMethod) LocalDate(org.joda.time.LocalDate) BudgetCalculationResult(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult) InvoicingFrequency(org.estatio.module.lease.dom.InvoicingFrequency) Test(org.junit.Test)

Example 7 with BudgetCalculationResult

use of org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult in project estatio by estatio.

the class BudgetAssignmentService_Test method findOrCreateLeaseItemForServiceChargeBudgeted_works_when_item_to_copy_from_found.

@Test
public void findOrCreateLeaseItemForServiceChargeBudgeted_works_when_item_to_copy_from_found() throws Exception {
    // given
    LeaseItem leaseItemToCopyFrom = new LeaseItem();
    leaseItemToCopyFrom.setInvoicingFrequency(InvoicingFrequency.QUARTERLY_IN_ADVANCE);
    leaseItemToCopyFrom.setPaymentMethod(PaymentMethod.CHEQUE);
    BudgetAssignmentService budgetAssignmentService = new BudgetAssignmentService() {

        @Override
        LeaseItem findItemToCopyFrom(final Lease lease) {
            return leaseItemToCopyFrom;
        }
    };
    Charge charge = new Charge();
    BudgetCalculationResult budgetCalculationResult = new BudgetCalculationResult();
    budgetCalculationResult.setInvoiceCharge(charge);
    LocalDate termStartDate = new LocalDate(2018, 1, 1);
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockLease).findFirstActiveItemOfTypeAndChargeOnDate(LeaseItemType.SERVICE_CHARGE, charge, termStartDate);
            will(returnValue(null));
            oneOf(mockLease).newItem(LeaseItemType.SERVICE_CHARGE, LeaseAgreementRoleTypeEnum.LANDLORD, budgetCalculationResult.getInvoiceCharge(), leaseItemToCopyFrom.getInvoicingFrequency(), leaseItemToCopyFrom.getPaymentMethod(), termStartDate);
        }
    });
    // when
    budgetAssignmentService.findOrCreateLeaseItemForServiceChargeBudgeted(mockLease, budgetCalculationResult, termStartDate);
}
Also used : Expectations(org.jmock.Expectations) Lease(org.estatio.module.lease.dom.Lease) Charge(org.estatio.module.charge.dom.Charge) 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 8 with BudgetCalculationResult

use of org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult 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;
}
Also used : BudgetItem(org.estatio.module.budget.dom.budgetitem.BudgetItem) ArrayList(java.util.ArrayList) BudgetOverrideValue(org.estatio.module.budgetassignment.dom.override.BudgetOverrideValue) BudgetCalculationRun(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationRun) BigDecimal(java.math.BigDecimal) PartitionItem(org.estatio.module.budget.dom.partioning.PartitionItem) BudgetCalculationResult(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult) BudgetCalculation(org.estatio.module.budget.dom.budgetcalculation.BudgetCalculation)

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