Search in sources :

Example 21 with Unit

use of org.estatio.module.asset.dom.Unit in project estatio by estatio.

the class InvoiceImportManager method getLines.

@Action(semantics = SemanticsOf.SAFE)
@ActionLayout(contributed = Contributed.AS_ASSOCIATION)
public List<InvoiceImportLine> getLines() {
    List<InvoiceImportLine> result = new ArrayList<>();
    for (Lease lease : leaseRepository.findByAssetAndActiveOnDate(getProperty(), clockService.now())) {
        PaymentMethod paymentMethod = null;
        Unit unit = lease.primaryOccupancy().get().getUnit();
        if (lease.getItems().size() > 0) {
            if (leaseItemRepository.findLeaseItemsByType(lease, LeaseItemType.RENT).size() > 0) {
                paymentMethod = leaseItemRepository.findLeaseItemsByType(lease, LeaseItemType.RENT).get(0).getPaymentMethod();
            } else {
                paymentMethod = lease.getItems().first().getPaymentMethod();
            }
            result.add(new InvoiceImportLine(lease.getReference(), null, paymentMethod.name(), null, null, null, null, null, unit.getReference()));
        } else {
            result.add(new InvoiceImportLine(lease.getReference(), null, null, null, null, null, null, null, unit.getReference()));
        }
    }
    return result;
}
Also used : Lease(org.estatio.module.lease.dom.Lease) ArrayList(java.util.ArrayList) PaymentMethod(org.estatio.module.invoice.dom.PaymentMethod) Unit(org.estatio.module.asset.dom.Unit) Action(org.apache.isis.applib.annotation.Action) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

Example 22 with Unit

use of org.estatio.module.asset.dom.Unit in project estatio by estatio.

the class OccupancyImport method importData.

@Override
@Programmatic
public List<Object> importData(Object previousRow) {
    final Lease lease = fetchLease(leaseReference);
    final Unit unit = unitRepository.findUnitByReference(unitReference);
    if (unitReference != null && unit == null) {
        throw new ApplicationException(String.format("Unit with reference %s not found.", unitReference));
    }
    Occupancy occupancy = occupancyRepository.findByLeaseAndUnitAndStartDate(lease, unit, startDate);
    if (occupancy == null) {
        occupancy = occupancyRepository.newOccupancy(lease, unit, startDate);
    }
    occupancy.setEndDate(endDate);
    occupancy.setUnitSizeName(size);
    occupancy.setBrandName(brand != null ? brand.replaceAll("\\p{C}", "").trim() : null, null, null);
    occupancy.setSectorName(sector);
    occupancy.setActivityName(activity);
    occupancy.setReportTurnover(reportTurnover != null ? Occupancy.OccupancyReportingType.valueOf(reportTurnover) : Occupancy.OccupancyReportingType.NO);
    occupancy.setReportRent(reportRent != null ? Occupancy.OccupancyReportingType.valueOf(reportRent) : Occupancy.OccupancyReportingType.NO);
    occupancy.setReportOCR(reportOCR != null ? Occupancy.OccupancyReportingType.valueOf(reportOCR) : Occupancy.OccupancyReportingType.NO);
    return Lists.newArrayList(occupancy);
}
Also used : ApplicationException(org.apache.isis.applib.ApplicationException) 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 23 with Unit

use of org.estatio.module.asset.dom.Unit in project estatio by estatio.

the class InvoiceAttributesVM method getUnitName.

@Programmatic
public String getUnitName() {
    final Optional<InvoiceItem> invoiceItemOptional = invoice.getItems().stream().findFirst();
    if (invoiceItemOptional.isPresent()) {
        final InvoiceItemForLease invoiceItem = (InvoiceItemForLease) invoiceItemOptional.get();
        final FixedAsset fixedAsset = invoiceItem.getFixedAsset();
        if (fixedAsset != null && fixedAsset instanceof Unit) {
            return fixedAsset.getName();
        }
    }
    return null;
}
Also used : InvoiceItem(org.estatio.module.invoice.dom.InvoiceItem) InvoiceItemForLease(org.estatio.module.lease.dom.invoicing.InvoiceItemForLease) FixedAsset(org.estatio.module.asset.dom.FixedAsset) Unit(org.estatio.module.asset.dom.Unit) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 24 with Unit

use of org.estatio.module.asset.dom.Unit in project estatio by estatio.

the class Property_vacantUnits_Test method occupiedUnits.

@Test
public void occupiedUnits() throws Exception {
    // given
    Property property = new Property();
    Unit unit1 = new Unit();
    Unit unit2 = new Unit();
    Property_vacantUnits mixin = new Property_vacantUnits(property);
    mixin.occupancyRepository = mockOccupancyRepository;
    mixin.clockService = mockClockService;
    // when
    Occupancy occupancy1 = new Occupancy();
    occupancy1.setUnit(unit1);
    Occupancy occupancy2 = new Occupancy();
    occupancy1.setUnit(unit2);
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockOccupancyRepository).findByProperty(property);
            will(returnValue(Arrays.asList(occupancy1, occupancy2)));
        }
    });
    // then
    Assertions.assertThat(mixin.occupiedUnits().size()).isEqualTo(2);
    // and when
    LocalDate now = new LocalDate(2017, 01, 01);
    occupancy1.setEndDate(now);
    occupancy2.setEndDate(now.plusDays(1));
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockOccupancyRepository).findByProperty(property);
            will(returnValue(Arrays.asList(occupancy1, occupancy2)));
            allowing(mockClockService).now();
            will(returnValue(now));
        }
    });
    // then
    Assertions.assertThat(mixin.occupiedUnits().size()).isEqualTo(1);
}
Also used : Expectations(org.jmock.Expectations) Occupancy(org.estatio.module.lease.dom.occupancy.Occupancy) Unit(org.estatio.module.asset.dom.Unit) Property(org.estatio.module.asset.dom.Property) LocalDate(org.joda.time.LocalDate) Test(org.junit.Test)

Example 25 with Unit

use of org.estatio.module.asset.dom.Unit in project estatio by estatio.

the class Property_vacantUnits_Test method vacant_Units_works.

@Test
public void vacant_Units_works() throws Exception {
    // given
    Property property = new Property();
    Unit unit1 = new Unit();
    Unit unit2 = new Unit();
    Property_vacantUnits mixin = new Property_vacantUnits(property);
    mixin.unitRepository = mockUnitRepository;
    mixin.occupancyRepository = mockOccupancyRepository;
    mixin.clockService = mockClockService;
    LocalDate now = new LocalDate(2017, 01, 01);
    // expect
    context.checking(new Expectations() {

        {
            allowing(mockOccupancyRepository).findByProperty(property);
            oneOf(mockUnitRepository).findByProperty(property);
            will(returnValue(Arrays.asList(unit1, unit2)));
        }
    });
    // when
    List<Unit> expectedVacantUnits = mixin.$$();
    // then
    Assertions.assertThat(expectedVacantUnits.size()).isEqualTo(2);
    // and expect
    context.checking(new Expectations() {

        {
            allowing(mockOccupancyRepository).findByProperty(property);
            oneOf(mockUnitRepository).findByProperty(property);
            will(returnValue(Arrays.asList(unit1, unit2)));
            oneOf(mockClockService).now();
            will(returnValue(now));
        }
    });
    // when
    unit1.setEndDate(now.plusDays(1));
    expectedVacantUnits = mixin.$$();
    // then
    Assertions.assertThat(expectedVacantUnits.size()).isEqualTo(2);
    // and expect
    context.checking(new Expectations() {

        {
            allowing(mockOccupancyRepository).findByProperty(property);
            oneOf(mockUnitRepository).findByProperty(property);
            will(returnValue(Arrays.asList(unit1, unit2)));
            oneOf(mockClockService).now();
            will(returnValue(now));
        }
    });
    // when
    unit1.setEndDate(now);
    expectedVacantUnits = mixin.$$();
    // then
    Assertions.assertThat(expectedVacantUnits.size()).isEqualTo(1);
    Assertions.assertThat(expectedVacantUnits).doesNotContain(unit1);
}
Also used : Expectations(org.jmock.Expectations) Unit(org.estatio.module.asset.dom.Unit) Property(org.estatio.module.asset.dom.Property) LocalDate(org.joda.time.LocalDate) Test(org.junit.Test)

Aggregations

Unit (org.estatio.module.asset.dom.Unit)27 Test (org.junit.Test)10 BigDecimal (java.math.BigDecimal)8 Lease (org.estatio.module.lease.dom.Lease)8 Occupancy (org.estatio.module.lease.dom.occupancy.Occupancy)8 LocalDate (org.joda.time.LocalDate)8 Programmatic (org.apache.isis.applib.annotation.Programmatic)6 Property (org.estatio.module.asset.dom.Property)5 ArrayList (java.util.ArrayList)3 KeyTable (org.estatio.module.budget.dom.keytable.KeyTable)3 InvoiceForLease (org.estatio.module.lease.dom.invoicing.InvoiceForLease)3 Expectations (org.jmock.Expectations)3 Before (org.junit.Before)3 Action (org.apache.isis.applib.annotation.Action)2 InvoiceItemForLease (org.estatio.module.lease.dom.invoicing.InvoiceItemForLease)2 Brand (org.estatio.module.lease.dom.occupancy.tags.Brand)2 Party (org.estatio.module.party.dom.Party)2 LandRegister (org.estatio.module.registration.dom.LandRegister)2 AbstractBeanPropertiesTest (org.incode.module.unittestsupport.dom.bean.AbstractBeanPropertiesTest)2 List (java.util.List)1