Search in sources :

Example 6 with Occupancy

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;
}
Also used : Lease(org.estatio.module.lease.dom.Lease) Occupancy(org.estatio.module.lease.dom.occupancy.Occupancy) Unit(org.estatio.module.asset.dom.Unit) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 7 with Occupancy

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;
}
Also used : Lease(org.estatio.module.lease.dom.Lease) Occupancy(org.estatio.module.lease.dom.occupancy.Occupancy) Budget(org.estatio.module.budget.dom.budget.Budget) SortedSet(java.util.SortedSet) LocalDate(org.joda.time.LocalDate) Property(org.estatio.module.asset.dom.Property) LeaseRepository(org.estatio.module.lease.dom.LeaseRepository) Before(org.junit.Before)

Example 8 with Occupancy

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");
}
Also used : Expectations(org.jmock.Expectations) Occupancy(org.estatio.module.lease.dom.occupancy.Occupancy) RendererForFreemarker(org.incode.module.docrendering.freemarker.dom.impl.RendererForFreemarker) Test(org.junit.Test)

Example 9 with Occupancy

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;
}
Also used : InvoiceItemDto(org.estatio.canonical.invoice.v1.InvoiceItemDto) Lease(org.estatio.module.lease.dom.Lease) InvoiceForLease(org.estatio.module.lease.dom.invoicing.InvoiceForLease) InvoiceItemForLease(org.estatio.module.lease.dom.invoicing.InvoiceItemForLease) Charge(org.estatio.module.charge.dom.Charge) InvoiceItemForLease(org.estatio.module.lease.dom.invoicing.InvoiceItemForLease) Tax(org.estatio.module.tax.dom.Tax) FixedAsset(org.estatio.module.asset.dom.FixedAsset) Brand(org.estatio.module.lease.dom.occupancy.tags.Brand) InvoiceForLease(org.estatio.module.lease.dom.invoicing.InvoiceForLease) ChargeGroup(org.estatio.module.charge.dom.ChargeGroup) Occupancy(org.estatio.module.lease.dom.occupancy.Occupancy) TaxRate(org.estatio.module.tax.dom.TaxRate) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 10 with Occupancy

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());
        }
    }
}
Also used : Occupancy(org.estatio.module.lease.dom.occupancy.Occupancy)

Aggregations

Occupancy (org.estatio.module.lease.dom.occupancy.Occupancy)17 Lease (org.estatio.module.lease.dom.Lease)9 Unit (org.estatio.module.asset.dom.Unit)8 Programmatic (org.apache.isis.applib.annotation.Programmatic)6 InvoiceForLease (org.estatio.module.lease.dom.invoicing.InvoiceForLease)3 Brand (org.estatio.module.lease.dom.occupancy.tags.Brand)3 LocalDate (org.joda.time.LocalDate)3 ArrayList (java.util.ArrayList)2 AgreementRole (org.estatio.module.agreement.dom.AgreementRole)2 Property (org.estatio.module.asset.dom.Property)2 Budget (org.estatio.module.budget.dom.budget.Budget)2 Charge (org.estatio.module.charge.dom.Charge)2 ChargeGroup (org.estatio.module.charge.dom.ChargeGroup)2 InvoiceItemForLease (org.estatio.module.lease.dom.invoicing.InvoiceItemForLease)2 Tax (org.estatio.module.tax.dom.Tax)2 Expectations (org.jmock.Expectations)2 Before (org.junit.Before)2 Test (org.junit.Test)2 BigDecimal (java.math.BigDecimal)1 SortedSet (java.util.SortedSet)1