Search in sources :

Example 1 with LeaseItem

use of org.estatio.module.lease.dom.LeaseItem 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 LeaseItem

use of org.estatio.module.lease.dom.LeaseItem in project estatio by estatio.

the class BudgetAssignmentService_Test method itemToCopyFrom_with_lease_having_no_rent_and_no_service_charge_item_works.

@Test
public void itemToCopyFrom_with_lease_having_no_rent_and_no_service_charge_item_works() throws Exception {
    // given
    LeaseItem anyItemOtherThanRentOrServiceCharge = new LeaseItem();
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockLease).findFirstItemOfType(LeaseItemType.SERVICE_CHARGE);
            will(returnValue(null));
            oneOf(mockLease).findFirstItemOfType(LeaseItemType.RENT);
            will(returnValue(null));
            allowing(mockLease).getItems();
            will(returnValue(new TreeSet(Arrays.asList(anyItemOtherThanRentOrServiceCharge))));
        }
    });
    // when
    LeaseItem itemToCopyFrom = budgetAssignmentService.findItemToCopyFrom(mockLease);
    // then
    assertThat(itemToCopyFrom).isEqualTo(anyItemOtherThanRentOrServiceCharge);
}
Also used : Expectations(org.jmock.Expectations) TreeSet(java.util.TreeSet) LeaseItem(org.estatio.module.lease.dom.LeaseItem) Test(org.junit.Test)

Example 3 with LeaseItem

use of org.estatio.module.lease.dom.LeaseItem 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 4 with LeaseItem

use of org.estatio.module.lease.dom.LeaseItem in project estatio by estatio.

the class InvoiceForLeaseBuilder method createInvoiceItemsForTermsOfFirstLeaseItemOfType.

private List<InvoiceItemForLease> createInvoiceItemsForTermsOfFirstLeaseItemOfType(final InvoiceForLease invoice, final LeaseItemType leaseItemType, final LocalDate startDate, final LocalDateInterval interval, final ExecutionContext ec) {
    final Lease lease = invoice.getLease();
    final LeaseItem firstLeaseItem = lease.findFirstItemOfType(leaseItemType);
    final SortedSet<LeaseTerm> terms = firstLeaseItem.getTerms();
    List<InvoiceItemForLease> items = Lists.newArrayList();
    for (final LeaseTerm term : terms) {
        InvoiceItemForLease item = invoiceItemForLeaseRepository.newInvoiceItem(term, interval, interval, interval, startDate, null);
        item.setInvoice(invoice);
        item.setSequence(invoice.nextItemSequence());
        ec.addResult(this, item);
        items.add(item);
    }
    return items;
}
Also used : Lease(org.estatio.module.lease.dom.Lease) InvoiceForLease(org.estatio.module.lease.dom.invoicing.InvoiceForLease) InvoiceItemForLease(org.estatio.module.lease.dom.invoicing.InvoiceItemForLease) InvoiceItemForLease(org.estatio.module.lease.dom.invoicing.InvoiceItemForLease) LeaseItem(org.estatio.module.lease.dom.LeaseItem) LeaseTerm(org.estatio.module.lease.dom.LeaseTerm)

Example 5 with LeaseItem

use of org.estatio.module.lease.dom.LeaseItem in project estatio by estatio.

the class LeaseStatusService method statusOf.

LeaseStatus statusOf(Lease lease) {
    int itemCount = 0;
    int disabledCount = 0;
    for (LeaseItem item : lease.getItems()) {
        itemCount++;
        LeaseItemStatus itemStatus = refreshStatus(item);
        if (itemStatus.equals(LeaseItemStatus.SUSPENDED)) {
            disabledCount++;
        }
    }
    if (itemCount > 0 && itemCount == disabledCount) {
        return LeaseStatus.SUSPENDED;
    }
    if (itemCount > 0 && disabledCount > 0) {
        return LeaseStatus.SUSPENDED_PARTIALLY;
    }
    if (lease.getTenancyEndDate() != null && clockService.now().isAfter(lease.getTenancyEndDate())) {
        return LeaseStatus.TERMINATED;
    }
    return LeaseStatus.ACTIVE;
}
Also used : LeaseItemStatus(org.estatio.module.lease.dom.LeaseItemStatus) LeaseItem(org.estatio.module.lease.dom.LeaseItem)

Aggregations

LeaseItem (org.estatio.module.lease.dom.LeaseItem)35 ChargeGroup (org.estatio.module.charge.dom.ChargeGroup)10 ChargeGroup_enum (org.estatio.module.charge.fixtures.chargegroups.enums.ChargeGroup_enum)10 Lease (org.estatio.module.lease.dom.Lease)10 Programmatic (org.apache.isis.applib.annotation.Programmatic)7 Charge (org.estatio.module.charge.dom.Charge)6 LeaseTerm (org.estatio.module.lease.dom.LeaseTerm)6 LocalDate (org.joda.time.LocalDate)6 LeaseItemType (org.estatio.module.lease.dom.LeaseItemType)5 Test (org.junit.Test)5 LeaseTermForIndexable (org.estatio.module.lease.dom.LeaseTermForIndexable)4 LeaseTermForServiceCharge (org.estatio.module.lease.dom.LeaseTermForServiceCharge)4 ApplicationTenancy (org.isisaddons.module.security.dom.tenancy.ApplicationTenancy)4 BudgetCalculationResult (org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult)3 LeaseItemStatus (org.estatio.module.lease.dom.LeaseItemStatus)3 LeaseTermForDeposit (org.estatio.module.lease.dom.LeaseTermForDeposit)3 LeaseTermForFixed (org.estatio.module.lease.dom.LeaseTermForFixed)3 LeaseTermForTurnoverRent (org.estatio.module.lease.dom.LeaseTermForTurnoverRent)2 LocalDateInterval (org.incode.module.base.dom.valuetypes.LocalDateInterval)2 Expectations (org.jmock.Expectations)2