use of org.estatio.canonical.invoice.v1.InvoiceItemDto 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.canonical.invoice.v1.InvoiceItemDto in project estatio by estatio.
the class InvoiceItemForLeaseDtoFactory_Test method occupancy_is_ignored_when_invoice_item_has_unit.
@Test
public void occupancy_is_ignored_when_invoice_item_has_unit() throws Exception {
// Given
invoiceItem.setEffectiveStartDate(new LocalDate(2013, 10, 1));
Unit unitOnItem = new Unit();
unitOnItem.setReference("XXX");
invoiceItem.setFixedAsset(unitOnItem);
// When
InvoiceItemDto invoiceItemDto = new InvoiceItemForLeaseDtoFactory().newDto(invoiceItem);
// Then
assertThat(invoiceItemDto.getFixedAssetReference()).isEqualTo("XXX");
assertThat(invoiceItemDto.getOccupancyBrand()).isEqualTo("BRAND");
}
use of org.estatio.canonical.invoice.v1.InvoiceItemDto in project estatio by estatio.
the class InvoiceItemForLeaseDtoFactory_Test method occupancy_is_used_when_in_scope.
@Test
public void occupancy_is_used_when_in_scope() throws Exception {
// Given
invoiceItem.setEffectiveStartDate(new LocalDate(2013, 10, 1));
// When
InvoiceItemDto invoiceItemDto = new InvoiceItemForLeaseDtoFactory().newDto(invoiceItem);
// Then
assertThat(invoiceItemDto.getFixedAssetReference()).isEqualTo("UN");
assertThat(invoiceItemDto.getOccupancyBrand()).isEqualTo("BRAND");
}
use of org.estatio.canonical.invoice.v1.InvoiceItemDto in project estatio by estatio.
the class InvoiceItemForLeaseDtoFactory_Test method fall_back_to_date_when_effective_is_empty.
@Test
public void fall_back_to_date_when_effective_is_empty() throws Exception {
// Given
assertThat(invoiceItem.getEffectiveStartDate()).isNull();
assertThat(invoiceItem.getStartDate()).isNull();
final LocalDate startDate = new LocalDate(2016, 1, 1);
// When
invoiceItem.setStartDate(startDate);
InvoiceItemDto invoiceItemDto = new InvoiceItemForLeaseDtoFactory().newDto(invoiceItem);
// Then
assertThat(invoiceItemDto.getStartDate().toString()).isEqualTo("2016-01-01T00:00:00.000Z");
assertThat(invoiceItemDto.getEffectiveStartDate().toString()).isEqualTo("2016-01-01T00:00:00.000Z");
}
use of org.estatio.canonical.invoice.v1.InvoiceItemDto in project estatio by estatio.
the class InvoiceItemForLeaseDtoFactory_Test method throw_error_when_outside_scope_of_occupancies.
// TODO: See ECP-196
@Ignore
@Test(expected = IllegalArgumentException.class)
public void throw_error_when_outside_scope_of_occupancies() throws Exception {
// Given
invoiceItem.setEffectiveStartDate(new LocalDate(2014, 1, 1));
// When
InvoiceItemDto invoiceItemDto = new InvoiceItemForLeaseDtoFactory().newDto(invoiceItem);
}
Aggregations