Search in sources :

Example 6 with LeaseItemType

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

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

LeaseItemType (org.estatio.module.lease.dom.LeaseItemType)7 LeaseItem (org.estatio.module.lease.dom.LeaseItem)5 Charge (org.estatio.module.charge.dom.Charge)4 Lease (org.estatio.module.lease.dom.Lease)4 Programmatic (org.apache.isis.applib.annotation.Programmatic)3 LocalDate (org.joda.time.LocalDate)3 Test (org.junit.Test)3 LeaseTermForServiceChargeBudgetAuditManager (org.estatio.module.budgetassignment.imports.LeaseTermForServiceChargeBudgetAuditManager)2 LeaseItemStatus (org.estatio.module.lease.dom.LeaseItemStatus)2 ApplicationTenancy (org.isisaddons.module.security.dom.tenancy.ApplicationTenancy)2 BudgetCalculationResult (org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult)1 PaymentMethod (org.estatio.module.invoice.dom.PaymentMethod)1 Fraction (org.estatio.module.lease.dom.Fraction)1 LeaseAgreementRoleTypeEnum (org.estatio.module.lease.dom.LeaseAgreementRoleTypeEnum)1 LeaseTerm (org.estatio.module.lease.dom.LeaseTerm)1 LeaseTermForDeposit (org.estatio.module.lease.dom.LeaseTermForDeposit)1 LeaseTermForServiceCharge (org.estatio.module.lease.dom.LeaseTermForServiceCharge)1