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