Search in sources :

Example 46 with Lease

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

the class InvoiceImportManager method getLines.

@Action(semantics = SemanticsOf.SAFE)
@ActionLayout(contributed = Contributed.AS_ASSOCIATION)
public List<InvoiceImportLine> getLines() {
    List<InvoiceImportLine> result = new ArrayList<>();
    for (Lease lease : leaseRepository.findByAssetAndActiveOnDate(getProperty(), clockService.now())) {
        PaymentMethod paymentMethod = null;
        Unit unit = lease.primaryOccupancy().get().getUnit();
        if (lease.getItems().size() > 0) {
            if (leaseItemRepository.findLeaseItemsByType(lease, LeaseItemType.RENT).size() > 0) {
                paymentMethod = leaseItemRepository.findLeaseItemsByType(lease, LeaseItemType.RENT).get(0).getPaymentMethod();
            } else {
                paymentMethod = lease.getItems().first().getPaymentMethod();
            }
            result.add(new InvoiceImportLine(lease.getReference(), null, paymentMethod.name(), null, null, null, null, null, unit.getReference()));
        } else {
            result.add(new InvoiceImportLine(lease.getReference(), null, null, null, null, null, null, null, unit.getReference()));
        }
    }
    return result;
}
Also used : Lease(org.estatio.module.lease.dom.Lease) ArrayList(java.util.ArrayList) PaymentMethod(org.estatio.module.invoice.dom.PaymentMethod) Unit(org.estatio.module.asset.dom.Unit) Action(org.apache.isis.applib.annotation.Action) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

Example 47 with Lease

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

the class LeaseImport method importData.

@Programmatic
@Override
public List<Object> importData(final Object previousRow) {
    final Party tenant = fetchParty(tenantReference);
    final Party landlord = fetchParty(landlordReference);
    Lease lease = leaseRepository.findLeaseByReferenceElseNull(reference);
    final LeaseType leaseType = leaseTypeRepository.findByReference(type);
    final Property property = fetchProperty(propertyReference, null, false);
    if (lease == null) {
        lease = leaseRepository.newLease(property.getApplicationTenancy(), reference, name, leaseType, startDate, endDate, tenancyStartDate, tenancyEndDate, landlord, tenant);
    }
    lease.setTenancyStartDate(tenancyStartDate);
    lease.setTenancyEndDate(tenancyEndDate);
    lease.setExternalReference(externalReference);
    lease.setComments(getComments());
    if (getProlongationPeriod() != null) {
        prolongationOptionRepository.newProlongationOption(lease, getProlongationPeriod(), getNotificationPeriod(), null);
    }
    if (getPreviousLeaseReference() != null) {
        Lease previous = leaseRepository.findLeaseByReference(getPreviousLeaseReference());
        if (previous == null) {
            // oops, not found?
            System.out.println(String.format("On lease [%s] the previous lease [%s] was not found", getReference(), getPreviousLeaseReference()));
        } else {
            lease.setPrevious(previous);
            // Huh? Two sided
            previous.setNext(lease);
        }
    }
    return Lists.newArrayList(lease);
}
Also used : Party(org.estatio.module.party.dom.Party) Lease(org.estatio.module.lease.dom.Lease) LeaseType(org.estatio.module.lease.dom.LeaseType) Property(org.estatio.module.asset.dom.Property) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 48 with Lease

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

the class LeaseItemImport method fetchLease.

private Lease fetchLease(final String leaseReference) {
    final Lease lease;
    lease = leaseRepository.findLeaseByReference(leaseReference.trim().replaceAll("~", "+"));
    if (lease == null) {
        throw new ApplicationException(String.format("Lease with reference %s not found.", leaseReference));
    }
    return lease;
}
Also used : ApplicationException(org.apache.isis.applib.ApplicationException) Lease(org.estatio.module.lease.dom.Lease)

Example 49 with Lease

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

the class LeaseTermForIndexableRentImport method fetchLease.

private Lease fetchLease(final String leaseReference) {
    final Lease lease;
    lease = leaseRepository.findLeaseByReference(leaseReference.trim().replaceAll("~", "+"));
    if (lease == null) {
        throw new ApplicationException(String.format("Lease with reference %s not found.", leaseReference));
    }
    return lease;
}
Also used : ApplicationException(org.apache.isis.applib.ApplicationException) Lease(org.estatio.module.lease.dom.Lease)

Example 50 with Lease

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

Lease (org.estatio.module.lease.dom.Lease)57 LocalDate (org.joda.time.LocalDate)17 Programmatic (org.apache.isis.applib.annotation.Programmatic)16 ApplicationException (org.apache.isis.applib.ApplicationException)11 Charge (org.estatio.module.charge.dom.Charge)11 Test (org.junit.Test)11 LeaseItem (org.estatio.module.lease.dom.LeaseItem)10 Occupancy (org.estatio.module.lease.dom.occupancy.Occupancy)10 Unit (org.estatio.module.asset.dom.Unit)9 InvoiceForLease (org.estatio.module.lease.dom.invoicing.InvoiceForLease)9 Property (org.estatio.module.asset.dom.Property)7 Party (org.estatio.module.party.dom.Party)6 Action (org.apache.isis.applib.annotation.Action)5 ApplicationTenancy (org.isisaddons.module.security.dom.tenancy.ApplicationTenancy)5 Before (org.junit.Before)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 PaymentMethod (org.estatio.module.invoice.dom.PaymentMethod)4 InvoiceItemForLease (org.estatio.module.lease.dom.invoicing.InvoiceItemForLease)4 BigDecimal (java.math.BigDecimal)3