use of org.estatio.module.lease.dom.LeaseItem in project estatio by estatio.
the class BudgetAssignmentService method assign.
public void assign(final Budget budget) {
for (BudgetCalculationRun run : budgetCalculationRunRepository.findByBudgetAndTypeAndStatus(budget, BudgetCalculationType.BUDGETED, Status.NEW)) {
for (BudgetCalculationResult resultForLease : run.getBudgetCalculationResults()) {
LocalDate termStartDate = run.getLease().getStartDate().isAfter(budget.getStartDate()) ? run.getLease().getStartDate() : budget.getStartDate();
LeaseItem leaseItem = findOrCreateLeaseItemForServiceChargeBudgeted(run.getLease(), resultForLease, termStartDate);
LeaseTermForServiceCharge leaseTerm = (LeaseTermForServiceCharge) leaseTermRepository.findOrCreateWithStartDate(leaseItem, new LocalDateInterval(termStartDate, budget.getEndDate()));
budgetCalculationResultLinkRepository.findOrCreateLink(resultForLease, leaseTerm);
leaseTerm.setBudgetedValue(resultForLease.getValue());
}
run.finalizeRun();
}
}
use of org.estatio.module.lease.dom.LeaseItem in project estatio by estatio.
the class BudgetAssignmentService_Test method itemToCopyFrom_with_lease_having_no_rent_and_no_service_charge_item_works.
@Test
public void itemToCopyFrom_with_lease_having_no_rent_and_no_service_charge_item_works() throws Exception {
// given
LeaseItem anyItemOtherThanRentOrServiceCharge = new LeaseItem();
// expect
context.checking(new Expectations() {
{
oneOf(mockLease).findFirstItemOfType(LeaseItemType.SERVICE_CHARGE);
will(returnValue(null));
oneOf(mockLease).findFirstItemOfType(LeaseItemType.RENT);
will(returnValue(null));
allowing(mockLease).getItems();
will(returnValue(new TreeSet(Arrays.asList(anyItemOtherThanRentOrServiceCharge))));
}
});
// when
LeaseItem itemToCopyFrom = budgetAssignmentService.findItemToCopyFrom(mockLease);
// then
assertThat(itemToCopyFrom).isEqualTo(anyItemOtherThanRentOrServiceCharge);
}
use of org.estatio.module.lease.dom.LeaseItem in project estatio by estatio.
the class BudgetAssignmentService_Test method findOrCreateLeaseItemForServiceChargeBudgeted_returns_active_item_when_found.
@Test
public void findOrCreateLeaseItemForServiceChargeBudgeted_returns_active_item_when_found() throws Exception {
// given
LeaseItem itemToBeFound = new LeaseItem();
Lease lease = new Lease() {
@Override
public LeaseItem findFirstActiveItemOfTypeAndChargeOnDate(final LeaseItemType leaseItemType, final Charge charge, final LocalDate date) {
return itemToBeFound;
}
};
BudgetCalculationResult budgetCalculationResult = new BudgetCalculationResult();
LocalDate termStartDate = new LocalDate(2018, 1, 1);
// when
LeaseItem itemFound = budgetAssignmentService.findOrCreateLeaseItemForServiceChargeBudgeted(lease, budgetCalculationResult, termStartDate);
// then
assertThat(itemFound).isEqualTo(itemToBeFound);
}
use of org.estatio.module.lease.dom.LeaseItem in project estatio by estatio.
the class InvoiceForLeaseBuilder method createInvoiceItemsForTermsOfFirstLeaseItemOfType.
private List<InvoiceItemForLease> createInvoiceItemsForTermsOfFirstLeaseItemOfType(final InvoiceForLease invoice, final LeaseItemType leaseItemType, final LocalDate startDate, final LocalDateInterval interval, final ExecutionContext ec) {
final Lease lease = invoice.getLease();
final LeaseItem firstLeaseItem = lease.findFirstItemOfType(leaseItemType);
final SortedSet<LeaseTerm> terms = firstLeaseItem.getTerms();
List<InvoiceItemForLease> items = Lists.newArrayList();
for (final LeaseTerm term : terms) {
InvoiceItemForLease item = invoiceItemForLeaseRepository.newInvoiceItem(term, interval, interval, interval, startDate, null);
item.setInvoice(invoice);
item.setSequence(invoice.nextItemSequence());
ec.addResult(this, item);
items.add(item);
}
return items;
}
use of org.estatio.module.lease.dom.LeaseItem in project estatio by estatio.
the class LeaseStatusService method statusOf.
LeaseStatus statusOf(Lease lease) {
int itemCount = 0;
int disabledCount = 0;
for (LeaseItem item : lease.getItems()) {
itemCount++;
LeaseItemStatus itemStatus = refreshStatus(item);
if (itemStatus.equals(LeaseItemStatus.SUSPENDED)) {
disabledCount++;
}
}
if (itemCount > 0 && itemCount == disabledCount) {
return LeaseStatus.SUSPENDED;
}
if (itemCount > 0 && disabledCount > 0) {
return LeaseStatus.SUSPENDED_PARTIALLY;
}
if (lease.getTenancyEndDate() != null && clockService.now().isAfter(lease.getTenancyEndDate())) {
return LeaseStatus.TERMINATED;
}
return LeaseStatus.ACTIVE;
}
Aggregations