use of org.estatio.module.lease.dom.occupancy.Occupancy in project estatio by estatio.
the class InvoiceItemForLeaseRepository method newInvoiceItem.
@Programmatic
public InvoiceItemForLease newInvoiceItem(final LeaseTerm leaseTerm, final LocalDateInterval interval, final LocalDateInterval calculationInterval, final LocalDateInterval effectiveInterval, final LocalDate dueDate, final String interactionId) {
final Lease lease = leaseTerm.getLeaseItem().getLease();
final InvoiceForLease invoice = invoiceRepository.findOrCreateMatchingInvoice(leaseTerm.getApplicationTenancy(), leaseTerm.getLeaseItem().getPaymentMethod(), lease, InvoiceStatus.NEW, dueDate, interactionId);
final InvoiceItemForLease invoiceItem = newItem(invoice, dueDate);
invoiceItem.setLeaseTerm(leaseTerm);
invoiceItem.setStartDate(interval.startDate());
invoiceItem.setEndDate(interval.endDate());
invoiceItem.setEffectiveStartDate(effectiveInterval.startDate());
invoiceItem.setEffectiveEndDate(effectiveInterval.endDate());
invoiceItem.setCalculationStartDate(calculationInterval.startDate());
invoiceItem.setCalculationEndDate(calculationInterval.endDate());
// redundantly persist, these are immutable
// assumes only one occupancy per lease...
invoiceItem.setLease(lease);
final Optional<Occupancy> occupancyIfAny = lease.primaryOccupancy();
occupancyIfAny.ifPresent(occupancy -> {
Unit unit = occupancy.getUnit();
invoiceItem.setFixedAsset(unit);
});
persistIfNotAlready(invoiceItem);
return invoiceItem;
}
use of org.estatio.module.lease.dom.occupancy.Occupancy in project estatio by estatio.
the class BudgetAssignmentService_Test method before.
@Before
public void before() throws Exception {
budgetAssignmentService = new BudgetAssignmentService();
o1 = new Occupancy();
leaseWith1ActiveOccupancy = new Lease() {
@Override
public SortedSet<Occupancy> getOccupancies() {
return new TreeSet<>(Arrays.asList(o1));
}
};
o2 = new Occupancy();
o3 = new Occupancy();
leaseWith2ActiveOccupancies = new Lease() {
@Override
public SortedSet<Occupancy> getOccupancies() {
return new TreeSet<>(Arrays.asList(o2, o3));
}
};
o4 = new Occupancy();
leaseWithNoActiveOccupancies = new Lease() {
@Override
public SortedSet<Occupancy> getOccupancies() {
return new TreeSet<>(Arrays.asList(o4));
}
};
o5 = new Occupancy();
leaseTerminated = new Lease() {
@Override
public SortedSet<Occupancy> getOccupancies() {
return new TreeSet<>(Arrays.asList(o5));
}
};
budget = new Budget();
LocalDate startDate = new LocalDate(2015, 01, 01);
LocalDate endDate = new LocalDate(2015, 12, 31);
budget.setStartDate(startDate);
budget.setEndDate(endDate);
LeaseRepository leaseRepository = new LeaseRepository() {
@Override
public List<Lease> findLeasesByProperty(final Property property) {
return Arrays.asList(leaseWith1ActiveOccupancy, leaseWith2ActiveOccupancies, leaseWithNoActiveOccupancies, leaseTerminated);
}
};
budgetAssignmentService.leaseRepository = leaseRepository;
}
use of org.estatio.module.lease.dom.occupancy.Occupancy in project estatio by estatio.
the class DocumentTypeAndTemplatesFSForInvoicesUsingSsrs_Test method when_primary_occupancy.
@Test
public void when_primary_occupancy() throws Exception {
// given
final Occupancy stubOccupancy = new Occupancy();
stubOccupancy.setUnit(stubUnit);
stubOccupancy.setBrand(stubBrand);
context.checking(new Expectations() {
{
allowing(mockLease).primaryOccupancy();
will(returnValue(Optional.of(stubOccupancy)));
}
});
// when
final Object rendererModel = rendererModelFactory.newRendererModel(mockDocumentTemplate, mockDocument);
// given
final RendererForFreemarker renderer = rendererForFreemarker();
// when
final String nameText = DocumentTypeAndTemplatesFSForInvoicesUsingSsrs.loadResource("InvoiceEmailCoverNoteSubjectLine.ftl");
final String rendered = renderer.renderCharsToChars(stubDocumentType, "", "/", 0L, nameText, rendererModel);
// then
Assertions.assertThat(rendered).isEqualTo("Invoice 2016-11-01, XXX XXX-123 Buyer-1 Brandino");
}
use of org.estatio.module.lease.dom.occupancy.Occupancy in project estatio by estatio.
the class InvoiceItemForLeaseDtoFactory method newDto.
@Programmatic
public InvoiceItemDto newDto(final InvoiceItem item) {
InvoiceItemDto dto = new InvoiceItemDto();
if (item instanceof InvoiceItemForLease) {
InvoiceItemForLease invoiceItemForLease = (InvoiceItemForLease) item;
final Lease lease = invoiceItemForLease.getLease();
if (lease != null) {
dto.setAgreementReference(lease.getReference());
}
final FixedAsset fixedAsset = invoiceItemForLease.getFixedAsset();
if (fixedAsset != null) {
dto.setFixedAssetReference(fixedAsset.getReference());
dto.setFixedAssetExternalReference(fixedAsset.getExternalReference());
}
}
final Charge charge = item.getCharge();
dto.setChargeReference(charge.getReference());
dto.setChargeDescription(charge.getDescription());
dto.setChargeExternalReference(charge.getExternalReference());
dto.setChargeName(charge.getName());
final ChargeGroup group = charge.getGroup();
dto.setChargeGroupReference(group.getReference());
dto.setChargeGroupName(group.getName());
final Tax tax = item.getTax();
final TaxRate rate = item.getTaxRate();
dto.setTaxReference(tax.getReference());
dto.setTaxName(tax.getName());
dto.setTaxDescription(tax.getDescription());
dto.setTaxExternalReference(rate == null || rate.getExternalReference() == null ? tax.getExternalReference() : rate.getExternalReference());
dto.setNetAmount(item.getNetAmount());
dto.setGrossAmount(item.getGrossAmount());
dto.setVatAmount(item.getVatAmount());
dto.setDescription(item.getDescription());
dto.setStartDate(asXMLGregorianCalendar(item.getStartDate()));
dto.setEndDate(asXMLGregorianCalendar(item.getEndDate()));
dto.setEffectiveStartDate(asXMLGregorianCalendar(firstNonNull(item.getEffectiveStartDate(), item.getStartDate())));
dto.setEffectiveEndDate(asXMLGregorianCalendar(firstNonNull(item.getEffectiveEndDate(), item.getEndDate())));
if (item instanceof InvoiceItemForLease) {
final InvoiceItemForLease invoiceItemForLease = (InvoiceItemForLease) item;
final InvoiceForLease invoice = (InvoiceForLease) invoiceItemForLease.getInvoice();
final Lease leaseIfAny = invoice.getLease();
if (leaseIfAny != null) {
final SortedSet<Occupancy> occupancies = leaseIfAny.getOccupancies();
if (!occupancies.isEmpty()) {
// final Optional<Occupancy> occupancyIfAny =
// occupancies.stream().filter(x -> x.getInterval().overlaps(item.getEffectiveInterval())).findFirst();
final Optional<Occupancy> occupancyIfAny = Optional.ofNullable(occupancies.first());
if (occupancyIfAny.isPresent()) {
final Occupancy occupancy = occupancyIfAny.orElse(occupancies.last());
final Brand brand = occupancy.getBrand();
dto.setOccupancyBrand(brand == null ? null : brand.getName());
if (dto.getFixedAssetReference() == null) {
// the unit was not retrieved through the invoice item, so get it from the occupancy then.
dto.setFixedAssetReference(occupancy.getUnit().getReference());
dto.setFixedAssetExternalReference(occupancy.getUnit().getExternalReference());
}
} else {
// throw new IllegalArgumentException("Invoice has an effective date range outside the scope of the occupanies");
throw new IllegalArgumentException("No Occupancy Found");
}
}
}
}
return dto;
}
use of org.estatio.module.lease.dom.occupancy.Occupancy in project estatio by estatio.
the class Lease method copyOccupancies.
private void copyOccupancies(final Lease newLease, final LocalDate startDate) {
for (Occupancy occupancy : this.getOccupancies()) {
if (occupancy.getInterval().contains(startDate) || occupancy.getInterval().endDateExcluding().equals(startDate)) {
Occupancy newOccupancy = newLease.newOccupancy(startDate, occupancy.getUnit());
newOccupancy.setActivity(occupancy.getActivity());
newOccupancy.setBrand(occupancy.getBrand());
newOccupancy.setSector(occupancy.getSector());
newOccupancy.setUnitSize(occupancy.getUnitSize());
newOccupancy.setReportOCR(occupancy.getReportOCR());
newOccupancy.setReportRent(occupancy.getReportRent());
newOccupancy.setReportTurnover(occupancy.getReportTurnover());
}
}
}
Aggregations