use of org.estatio.module.lease.dom.invoicing.InvoiceItemForLease in project estatio by estatio.
the class InvoiceCalculationForDeposit_IntegTest method just_in_advance_in_one_normal_run_works.
@Test
public void just_in_advance_in_one_normal_run_works() {
// given
setUpTheGiven();
// EST-1750: to mimick behaviour through UI
sessionManagementService.nextSession();
// when
LocalDate invoiceDueDate = VT.ld(2012, 1, 1);
// NOTE: NOW it matters that the due date of the deposit term is in the past
LocalDate startDueDate = VT.ld(2012, 1, 1);
LocalDate nextDueDate = VT.ld(2012, 1, 2);
Property oxford = Property_enum.OxfGb.findUsing(serviceRegistry);
final LocalDate dateOfInvoiceRun = VT.ld(2011, 12, 1);
setFixtureClockDate(dateOfInvoiceRun);
mixin(Property_calculateInvoices.class, oxford).exec(InvoiceRunType.NORMAL_RUN, Arrays.asList(LeaseItemType.RENT, LeaseItemType.DEPOSIT), invoiceDueDate, startDueDate, nextDueDate);
// EST-1750: to mimick behaviour through UI
transactionService.nextTransaction();
// TODO: manage extra boilerplate because of new session -> to be handled in new programming model?
reloadObjectsForNewSession();
assertThat(rentItem010.getTerms().size()).isEqualTo(2);
assertThat(rentItem011.getTerms().size()).isEqualTo(2);
// then
InvoiceForLease invoiceFor010Advance = invoiceForLeaseRepository.findByLease(poisonLease010Advance).get(0);
assertThat(invoiceFor010Advance.getItems().size()).isEqualTo(2);
InvoiceItemForLease rentItem010 = (InvoiceItemForLease) invoiceFor010Advance.findFirstItemWithCharge(chargeForRent);
assertThat(rentItem010.getNetAmount()).isEqualTo(quarterlyRentAfterIndexation);
InvoiceItemForLease depositItem010Advance = (InvoiceItemForLease) invoiceFor010Advance.findFirstItemWithCharge(chargeForDeposit);
assertThat(depositItem010Advance.getNetAmount()).isEqualTo(depositValueAfterIndexation);
InvoiceForLease invoiceFor011Arrears = invoiceForLeaseRepository.findByLease(poisonLease011Arrears).get(0);
assertThat(invoiceFor011Arrears.getItems().size()).isEqualTo(1);
InvoiceItemForLease rentItem011 = (InvoiceItemForLease) invoiceFor011Arrears.findFirstItemWithCharge(chargeForRent);
assertThat(rentItem011.getNetAmount()).isEqualTo(quarterlyRentAfterIndexation);
}
use of org.estatio.module.lease.dom.invoicing.InvoiceItemForLease in project estatio by estatio.
the class InvoiceCalculationService_normalRun_IntegTest method calculateNormalRunAndAssert.
private String calculateNormalRunAndAssert(final LeaseTerm leaseTerm, final LocalDate startDueDate, final LocalDate nextDueDate, final LocalDateInterval interval, final Double expected, final boolean expectedAdjustment, final LocalDateInterval expectedEffectiveInterval) {
transactionService.nextTransaction();
isisJdoSupport.refresh(leaseTerm);
InvoiceCalculationParameters parameters = InvoiceCalculationParameters.builder().leaseTerm(leaseTerm).invoiceRunType(InvoiceRunType.NORMAL_RUN).invoiceDueDate(startDueDate).startDueDate(startDueDate).nextDueDate(nextDueDate).build();
final String runId = invoiceCalculationService.calculateAndInvoice(parameters);
InvoiceItemForLease invoiceItem = invoiceItemForLeaseRepository.findUnapprovedInvoiceItem(leaseTerm, interval);
isisJdoSupport.refresh(leaseTerm);
BigDecimal netAmount = invoiceItem == null ? VT.bd2(0) : invoiceItem.getNetAmount();
final String reason = "size " + invoiceItemForLeaseRepository.findByLeaseTermAndInvoiceStatus(leaseTerm, InvoiceStatus.NEW).size();
assertThat(netAmount).isEqualTo(VT.bd2hup(expected)).as(reason);
Boolean adjustment = invoiceItem == null ? false : invoiceItem.getAdjustment();
assertThat(adjustment).isEqualTo(expectedAdjustment);
if (expectedEffectiveInterval != null) {
assertThat(invoiceItem.getEffectiveInterval()).isEqualTo(expectedEffectiveInterval);
}
return runId;
}
use of org.estatio.module.lease.dom.invoicing.InvoiceItemForLease 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.invoicing.InvoiceItemForLease 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.lease.dom.invoicing.InvoiceItemForLease in project estatio by estatio.
the class InvoiceItemForLeaseDtoFactory_Test method setUp.
@Before
public void setUp() throws Exception {
// given
ChargeGroup chargeGroup = new ChargeGroup();
chargeGroup.setReference("CG");
Charge charge = new Charge();
charge.setReference("CH");
charge.setExternalReference("CHE");
charge.setGroup(chargeGroup);
Tax tax = new Tax();
Unit unit = new Unit();
unit.setReference("UN");
Brand brand = new Brand();
brand.setName("BRAND");
Occupancy occupancy = new Occupancy();
occupancy.setEndDate(new LocalDate(2013, 12, 31));
occupancy.setUnit(unit);
occupancy.setBrand(brand);
Lease lease = new Lease();
lease.getOccupancies().add(occupancy);
InvoiceForLease invoice = new InvoiceForLease();
invoice.setLease(lease);
invoiceItem = new InvoiceItemForLease();
invoiceItem.setInvoice(invoice);
invoiceItem.setCharge(charge);
invoiceItem.setTax(tax);
}
Aggregations