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);
}
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);
}
Aggregations