Search in sources :

Example 6 with InvoiceItemForLease

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);
}
Also used : InvoiceForLease(org.estatio.module.lease.dom.invoicing.InvoiceForLease) Property_calculateInvoices(org.estatio.module.lease.contributions.Property_calculateInvoices) InvoiceItemForLease(org.estatio.module.lease.dom.invoicing.InvoiceItemForLease) LocalDate(org.joda.time.LocalDate) Property(org.estatio.module.asset.dom.Property) Test(org.junit.Test)

Example 7 with InvoiceItemForLease

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;
}
Also used : InvoiceItemForLease(org.estatio.module.lease.dom.invoicing.InvoiceItemForLease) InvoiceCalculationParameters(org.estatio.module.lease.dom.invoicing.InvoiceCalculationParameters) BigDecimal(java.math.BigDecimal)

Example 8 with InvoiceItemForLease

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;
}
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 9 with InvoiceItemForLease

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;
}
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 10 with InvoiceItemForLease

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);
}
Also used : Brand(org.estatio.module.lease.dom.occupancy.tags.Brand) Lease(org.estatio.module.lease.dom.Lease) InvoiceForLease(org.estatio.module.lease.dom.invoicing.InvoiceForLease) InvoiceItemForLease(org.estatio.module.lease.dom.invoicing.InvoiceItemForLease) InvoiceForLease(org.estatio.module.lease.dom.invoicing.InvoiceForLease) ChargeGroup(org.estatio.module.charge.dom.ChargeGroup) Occupancy(org.estatio.module.lease.dom.occupancy.Occupancy) Charge(org.estatio.module.charge.dom.Charge) InvoiceItemForLease(org.estatio.module.lease.dom.invoicing.InvoiceItemForLease) Tax(org.estatio.module.tax.dom.Tax) Unit(org.estatio.module.asset.dom.Unit) LocalDate(org.joda.time.LocalDate) Before(org.junit.Before)

Aggregations

InvoiceItemForLease (org.estatio.module.lease.dom.invoicing.InvoiceItemForLease)10 InvoiceForLease (org.estatio.module.lease.dom.invoicing.InvoiceForLease)8 Property (org.estatio.module.asset.dom.Property)5 LocalDate (org.joda.time.LocalDate)5 Property_calculateInvoices (org.estatio.module.lease.contributions.Property_calculateInvoices)4 Test (org.junit.Test)4 Lease (org.estatio.module.lease.dom.Lease)3 Programmatic (org.apache.isis.applib.annotation.Programmatic)2 FixedAsset (org.estatio.module.asset.dom.FixedAsset)2 Unit (org.estatio.module.asset.dom.Unit)2 Charge (org.estatio.module.charge.dom.Charge)2 ChargeGroup (org.estatio.module.charge.dom.ChargeGroup)2 Occupancy (org.estatio.module.lease.dom.occupancy.Occupancy)2 Brand (org.estatio.module.lease.dom.occupancy.tags.Brand)2 Tax (org.estatio.module.tax.dom.Tax)2 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 ToString (lombok.ToString)1 InvoiceItemDto (org.estatio.canonical.invoice.v1.InvoiceItemDto)1 InvoiceItem (org.estatio.module.invoice.dom.InvoiceItem)1