Search in sources :

Example 1 with LeaseItemStatus

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

Example 2 with LeaseItemStatus

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

the class LeaseTermImportAbstract method initLeaseItem.

protected LeaseItem initLeaseItem() {
    // find or create leaseItem
    final Lease lease = fetchLease(getLeaseReference());
    final ApplicationTenancy leaseItemApplicationTenancy = ObjectUtils.firstNonNull(securityApplicationTenancyRepository.findByPath(getLeaseItemAtPath()), lease.getApplicationTenancy());
    final Charge charge = fetchCharge(getItemChargeReference());
    final LeaseItemType itemType = fetchLeaseItemType(getItemTypeName());
    LeaseItem item = lease.findItem(itemType, getItemStartDate(), getItemSequence());
    if (item == null) {
        item = lease.newItem(itemType, LeaseAgreementRoleTypeEnum.LANDLORD, charge, InvoicingFrequency.valueOf(getItemInvoicingFrequency()), PaymentMethod.valueOf(getItemPaymentMethod()), getItemStartDate());
        item.setSequence(getItemSequence());
    }
    item.setEpochDate(getItemEpochDate());
    item.setNextDueDate(getItemNextDueDate());
    final LeaseItemStatus leaseItemStatus = LeaseItemStatus.valueOfElse(getItemStatus(), LeaseItemStatus.ACTIVE);
    item.setStatus(leaseItemStatus);
    // Find source item and create source link
    if (getSourceItemTypeName() != null) {
        final LeaseItemType sourceItemType = LeaseItemType.valueOf(sourceItemTypeName);
        LeaseItem sourceItem = item.getLease().findItem(sourceItemType, sourceItemStartDate, sourceItemSequence);
        if (sourceItem != null) {
            item.findOrCreateSourceItem(sourceItem);
        }
    }
    return item;
}
Also used : Lease(org.estatio.module.lease.dom.Lease) Charge(org.estatio.module.charge.dom.Charge) LeaseItemStatus(org.estatio.module.lease.dom.LeaseItemStatus) LeaseItemType(org.estatio.module.lease.dom.LeaseItemType) ApplicationTenancy(org.isisaddons.module.security.dom.tenancy.ApplicationTenancy) LeaseItem(org.estatio.module.lease.dom.LeaseItem)

Example 3 with LeaseItemStatus

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

the class LeaseTermForServiceChargeImport method importData.

@Programmatic
@Override
public List<Object> importData(final Object previousRow) {
    // find or create leaseItem
    final Lease lease = fetchLease(leaseReference);
    final ApplicationTenancy leaseItemApplicationTenancy = ObjectUtils.firstNonNull(securityApplicationTenancyRepository.findByPath(leaseItemAtPath), lease.getApplicationTenancy());
    final Charge charge = fetchCharge(itemChargeReference);
    final LeaseItemType itemType = fetchLeaseItemType(itemTypeName);
    final LocalDate itemStartDateToUse = itemStartDate == null ? lease.getStartDate() : itemStartDate;
    final LeaseAgreementRoleTypeEnum invoicedByToUse = this.invoicedBy == null ? LeaseAgreementRoleTypeEnum.LANDLORD : LeaseAgreementRoleTypeEnum.valueOf(this.invoicedBy);
    final PaymentMethod paymentMethodToUse = itemPaymentMethod == null ? lease.defaultPaymentMethod() : PaymentMethod.valueOf(itemPaymentMethod);
    LeaseItem item = lease.findItem(itemType, charge, itemStartDateToUse, invoicedByToUse);
    if (item == null) {
        item = lease.newItem(itemType, invoicedByToUse, charge, InvoicingFrequency.valueOf(itemInvoicingFrequency), paymentMethodToUse, itemStartDateToUse);
        item.setSequence(itemSequence);
    }
    item.setEpochDate(itemEpochDate);
    item.setNextDueDate(itemNextDueDate);
    final LeaseItemStatus leaseItemStatus = LeaseItemStatus.valueOfElse(itemStatus, LeaseItemStatus.ACTIVE);
    item.setStatus(leaseItemStatus);
    // create term
    LeaseTermForServiceCharge term = (LeaseTermForServiceCharge) item.findTermWithSequence(sequence);
    if (term == null) {
        if (startDate == null) {
            throw new IllegalArgumentException("startDate cannot be empty");
        }
        if (sequence.equals(BigInteger.ONE)) {
            term = (LeaseTermForServiceCharge) item.newTerm(startDate, endDate);
        } else {
            final LeaseTerm previousTerm = item.findTermWithSequence(sequence.subtract(BigInteger.ONE));
            if (previousTerm == null) {
                throw new IllegalArgumentException(String.format("Previous term not found %s", lease.getReference()));
            }
            term = (LeaseTermForServiceCharge) previousTerm.createNext(startDate, endDate);
        }
        term.setSequence(sequence);
    }
    term.setStatus(LeaseTermStatus.valueOf(status));
    // set service charge term values
    term.setBudgetedValue(budgetedValue);
    term.setAuditedValue(auditedValue);
    return Lists.newArrayList(term);
}
Also used : LeaseAgreementRoleTypeEnum(org.estatio.module.lease.dom.LeaseAgreementRoleTypeEnum) Lease(org.estatio.module.lease.dom.Lease) LeaseTermForServiceCharge(org.estatio.module.lease.dom.LeaseTermForServiceCharge) Charge(org.estatio.module.charge.dom.Charge) PaymentMethod(org.estatio.module.invoice.dom.PaymentMethod) LeaseItemStatus(org.estatio.module.lease.dom.LeaseItemStatus) LeaseTermForServiceCharge(org.estatio.module.lease.dom.LeaseTermForServiceCharge) LeaseItemType(org.estatio.module.lease.dom.LeaseItemType) LocalDate(org.joda.time.LocalDate) ApplicationTenancy(org.isisaddons.module.security.dom.tenancy.ApplicationTenancy) LeaseItem(org.estatio.module.lease.dom.LeaseItem) LeaseTerm(org.estatio.module.lease.dom.LeaseTerm) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Aggregations

LeaseItem (org.estatio.module.lease.dom.LeaseItem)3 LeaseItemStatus (org.estatio.module.lease.dom.LeaseItemStatus)3 Charge (org.estatio.module.charge.dom.Charge)2 Lease (org.estatio.module.lease.dom.Lease)2 LeaseItemType (org.estatio.module.lease.dom.LeaseItemType)2 ApplicationTenancy (org.isisaddons.module.security.dom.tenancy.ApplicationTenancy)2 Programmatic (org.apache.isis.applib.annotation.Programmatic)1 PaymentMethod (org.estatio.module.invoice.dom.PaymentMethod)1 LeaseAgreementRoleTypeEnum (org.estatio.module.lease.dom.LeaseAgreementRoleTypeEnum)1 LeaseTerm (org.estatio.module.lease.dom.LeaseTerm)1 LeaseTermForServiceCharge (org.estatio.module.lease.dom.LeaseTermForServiceCharge)1 LocalDate (org.joda.time.LocalDate)1