Search in sources :

Example 31 with LeaseItem

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

the class LeaseItemForTurnoverRentBuilder method execute.

@Override
protected void execute(final ExecutionContext ec) {
    defaultParam("charge", ec, Charge_enum.ItTurnoverRent.findUsing(serviceRegistry));
    final ChargeGroup group = getCharge().getGroup();
    final ChargeGroup_enum expectedGroup = ChargeGroup_enum.TurnoverRent;
    if (group != expectedGroup.findUsing(serviceRegistry)) {
        throw new IllegalArgumentException("Charge's group must be " + expectedGroup.getRef());
    }
    LeaseItem leaseItem = new LeaseItemBuilder().setLease(lease).setCharge(charge).setLeaseItemType(LEASE_ITEM_TYPE).setInvoicingFrequency(INVOICING_FREQUENCY).setInvoicedBy(invoicedBy).setPaymentMethod(paymentMethod).setStatus(status).setSequence(sequence).build(this, ec).getObject();
    if (sourceItem != null) {
        if (leaseItem.getSourceItems().isEmpty()) {
            leaseItem.newSourceItem(sourceItem);
        }
    }
    for (LeaseTermForTurnoverRentBuilder.TermSpec termSpec : termSpecs) {
        final LeaseTermForTurnoverRent term = new LeaseTermForTurnoverRentBuilder().setLeaseItem(leaseItem).setStartDate(termSpec.startDate).setEndDate(termSpec.endDate).setLeaseTermFrequency(termSpec.leaseTermFrequency).setTurnoverRentRule(termSpec.turnoverRentRule).build(this, ec).getObject();
        terms.add(term);
    }
    object = leaseItem;
}
Also used : ChargeGroup(org.estatio.module.charge.dom.ChargeGroup) ChargeGroup_enum(org.estatio.module.charge.fixtures.chargegroups.enums.ChargeGroup_enum) LeaseTermForTurnoverRent(org.estatio.module.lease.dom.LeaseTermForTurnoverRent) LeaseItem(org.estatio.module.lease.dom.LeaseItem)

Example 32 with LeaseItem

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

the class LeaseTermForDepositImport method importData.

@Programmatic
@Override
public List<Object> importData(final Object previousRow) {
    // Early validation
    if (LeaseItemType.valueOf(itemTypeName) != LeaseItemType.DEPOSIT) {
        throw new IllegalArgumentException("Not a deposit type");
    }
    // Find or create deposit item
    final LeaseItemImport leaseItemImport = new LeaseItemImport(leaseReference, itemTypeName, itemSequence, itemStartDate, itemChargeReference, itemEpochDate, itemNextDueDate, itemInvoicingFrequency, itemPaymentMethod, itemStatus, itemAtPath);
    domainObjectContainer.injectServicesInto(leaseItemImport);
    LeaseItem depositItem = leaseItemImport.importItem(false);
    // link to source item if sourceItemTypeName is given
    if (sourceItemTypeName != null) {
        // Find source item and find or create source link
        final LeaseItemType sourceItemType = LeaseItemType.valueOf(sourceItemTypeName);
        LeaseItem rentItem = depositItem.getLease().findItem(sourceItemType, sourceItemStartDate, sourceItemSequence);
        depositItem.findOrCreateSourceItem(rentItem);
    }
    LeaseTermForDeposit term = (LeaseTermForDeposit) depositItem.findTermWithSequence(BigInteger.ONE);
    if (term == null) {
        // the start date of the term defaults to the start date of the item (which in turn defaults to the start date of the lease)
        term = (LeaseTermForDeposit) depositItem.newTerm(ObjectUtils.firstNonNull(startDate, depositItem.getStartDate()), endDate);
    }
    // set deposit term values
    term.setStatus(LeaseTermStatus.valueOf(status));
    // fraction defaults to Manual
    Fraction fractionOrDefault = fraction != null ? Fraction.valueOf(fraction) : Fraction.MANUAL;
    term.setFraction(fractionOrDefault);
    // when fraction is set to manual and fixed deposit calculation date is not given the startdate of the item is used
    if (fraction.equals("MANUAL") && fixedDepositCalculationDate == null) {
        term.setFixedDepositCalculationDate(term.getLeaseItem().getStartDate());
    } else {
        term.setFixedDepositCalculationDate(fixedDepositCalculationDate);
    }
    term.setIncludeVat(includeVat);
    if (useManualDepositValue != null && useManualDepositValue) {
        term.setManualDepositValue(manualDepositValue);
    }
    return Lists.newArrayList(term);
}
Also used : LeaseTermForDeposit(org.estatio.module.lease.dom.LeaseTermForDeposit) Fraction(org.estatio.module.lease.dom.Fraction) LeaseItemType(org.estatio.module.lease.dom.LeaseItemType) LeaseItem(org.estatio.module.lease.dom.LeaseItem) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 33 with LeaseItem

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

the class LeaseTermForFixedImport method importData.

@Programmatic
@Override
public List<Object> importData(Object previousRow) {
    LeaseItem item = initLeaseItem();
    // create term
    LeaseTermForFixed term = (LeaseTermForFixed) item.findTermWithSequence(getSequence());
    if (term == null) {
        if (getStartDate() == null) {
            throw new IllegalArgumentException("startDate cannot be empty");
        }
        if (getSequence().equals(BigInteger.ONE)) {
            term = (LeaseTermForFixed) item.newTerm(getStartDate(), getEndDate());
        } else {
            final LeaseTerm previousTerm = item.findTermWithSequence(getSequence().subtract(BigInteger.ONE));
            if (previousTerm == null) {
                throw new IllegalArgumentException("Previous term not found");
            }
            term = (LeaseTermForFixed) previousTerm.createNext(getStartDate(), getEndDate());
        }
        term.setSequence(getSequence());
    }
    term.setStatus(LeaseTermStatus.valueOf(getStatus()));
    // set turnover rent term values
    term.setValue(getValue());
    return Lists.newArrayList(term);
}
Also used : LeaseTermForFixed(org.estatio.module.lease.dom.LeaseTermForFixed) LeaseItem(org.estatio.module.lease.dom.LeaseItem) LeaseTerm(org.estatio.module.lease.dom.LeaseTerm) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 34 with LeaseItem

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

the class LeaseTermForIndexableRentImport method importData.

@Programmatic
@Override
public List<Object> importData(final Object previousRow) {
    final LeaseItemImport leaseItemImport = new LeaseItemImport(leaseReference, itemTypeName, itemSequence, itemStartDate, itemChargeReference, itemEpochDate, itemNextDueDate, itemInvoicingFrequency, itemPaymentMethod, itemStatus, itemAtPath);
    domainObjectContainer.injectServicesInto(leaseItemImport);
    LeaseItem item = leaseItemImport.importItem(false);
    // create term
    LeaseTermForIndexable term = (LeaseTermForIndexable) item.findTermWithSequence(sequence);
    if (term == null) {
        if (startDate == null) {
            throw new IllegalArgumentException("startDate cannot be empty");
        }
        if (sequence.equals(BigInteger.ONE) || !item.getType().autoCreateTerms()) {
            // create a standalone term on the first or when autoCreateTerms is false
            term = (LeaseTermForIndexable) item.newTerm(startDate, endDate);
        } else {
            // join the current with the previous
            final LeaseTerm previousTerm = item.findTermWithSequence(sequence.subtract(BigInteger.ONE));
            if (previousTerm == null) {
                throw new IllegalArgumentException(String.format("Previous term not found: %s", this.toString()));
            }
            term = (LeaseTermForIndexable) previousTerm.createNext(startDate, endDate);
        }
        term.setSequence(sequence);
    }
    term.setStatus(LeaseTermStatus.valueOf(status));
    final ApplicationTenancy applicationTenancy = term.getLeaseItem().getApplicationTenancy();
    // set indexation term values
    term.setIndexationMethod(indexationMethod == null ? null : IndexationMethod.valueOf(indexationMethod));
    term.setIndex(indexReference == null ? null : indexRepository.findOrCreateIndex(applicationTenancy, indexReference, indexReference));
    term.setFrequency(indexationFrequency == null ? null : LeaseTermFrequency.valueOf(indexationFrequency));
    term.setEffectiveDate(effectiveDate);
    term.setBaseValue(baseValue);
    term.setIndexedValue(indexedValue);
    term.setSettledValue(settledValue);
    term.setBaseIndexStartDate(baseIndexStartDate);
    term.setBaseIndexValue(baseIndexValue);
    term.setNextIndexStartDate(nextIndexStartDate);
    term.setNextIndexValue(nextIndexValue);
    term.setIndexationPercentage(indexationPercentage);
    term.setLevellingPercentage(levellingPercentage);
    return Lists.newArrayList(term);
}
Also used : LeaseTermForIndexable(org.estatio.module.lease.dom.LeaseTermForIndexable) LeaseItem(org.estatio.module.lease.dom.LeaseItem) LeaseTerm(org.estatio.module.lease.dom.LeaseTerm) ApplicationTenancy(org.isisaddons.module.security.dom.tenancy.ApplicationTenancy) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 35 with LeaseItem

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