Search in sources :

Example 1 with Fraction

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

Aggregations

Programmatic (org.apache.isis.applib.annotation.Programmatic)1 Fraction (org.estatio.module.lease.dom.Fraction)1 LeaseItem (org.estatio.module.lease.dom.LeaseItem)1 LeaseItemType (org.estatio.module.lease.dom.LeaseItemType)1 LeaseTermForDeposit (org.estatio.module.lease.dom.LeaseTermForDeposit)1