Search in sources :

Example 1 with InvoiceItemForLease

use of org.estatio.module.lease.dom.invoicing.InvoiceItemForLease in project estatio by estatio.

the class InvoiceForLeaseBuilder method execute.

@Override
protected void execute(final ExecutionContext ec) {
    checkParam("lease", ec, Lease.class);
    checkParam("seller", ec, Party.class);
    checkParam("buyer", ec, Party.class);
    checkParam("paymentMethod", ec, PaymentMethod.class);
    checkParam("currency", ec, Currency.class);
    checkParam("dueDate", ec, LocalDate.class);
    defaultParam("invoiceDate", ec, getDueDate());
    final String interactionId = null;
    final InvoiceForLease invoice = invoiceForLeaseRepository.newInvoice(applicationTenancy, seller, buyer, paymentMethod, currency, dueDate, lease, interactionId);
    invoice.setInvoiceDate(this.invoiceDate);
    ec.addResult(this, invoice);
    final Property property = lease.getProperty();
    final String format = property.getReference() + "-%06d";
    final BigInteger lastIncrement = BigInteger.ZERO;
    this.numerator = numeratorForCollectionRepository.createInvoiceNumberNumerator(property, format, lastIncrement, applicationTenancy);
    ec.addResult(this, numerator);
    for (ItemsSpec itemSpec : itemSpecs) {
        final List<InvoiceItemForLease> items = createInvoiceItemsForTermsOfFirstLeaseItemOfType(invoice, itemSpec.leaseItemType, itemSpec.startDate, itemSpec.interval, ec);
        this.items.addAll(items);
    }
    object = invoice;
}
Also used : InvoiceForLease(org.estatio.module.lease.dom.invoicing.InvoiceForLease) BigInteger(java.math.BigInteger) InvoiceItemForLease(org.estatio.module.lease.dom.invoicing.InvoiceItemForLease) ToString(lombok.ToString) Property(org.estatio.module.asset.dom.Property)

Example 2 with InvoiceItemForLease

use of org.estatio.module.lease.dom.invoicing.InvoiceItemForLease in project estatio by estatio.

the class InvoiceForLeaseBuilder method createInvoiceItemsForTermsOfFirstLeaseItemOfType.

private List<InvoiceItemForLease> createInvoiceItemsForTermsOfFirstLeaseItemOfType(final InvoiceForLease invoice, final LeaseItemType leaseItemType, final LocalDate startDate, final LocalDateInterval interval, final ExecutionContext ec) {
    final Lease lease = invoice.getLease();
    final LeaseItem firstLeaseItem = lease.findFirstItemOfType(leaseItemType);
    final SortedSet<LeaseTerm> terms = firstLeaseItem.getTerms();
    List<InvoiceItemForLease> items = Lists.newArrayList();
    for (final LeaseTerm term : terms) {
        InvoiceItemForLease item = invoiceItemForLeaseRepository.newInvoiceItem(term, interval, interval, interval, startDate, null);
        item.setInvoice(invoice);
        item.setSequence(invoice.nextItemSequence());
        ec.addResult(this, item);
        items.add(item);
    }
    return items;
}
Also used : Lease(org.estatio.module.lease.dom.Lease) InvoiceForLease(org.estatio.module.lease.dom.invoicing.InvoiceForLease) InvoiceItemForLease(org.estatio.module.lease.dom.invoicing.InvoiceItemForLease) InvoiceItemForLease(org.estatio.module.lease.dom.invoicing.InvoiceItemForLease) LeaseItem(org.estatio.module.lease.dom.LeaseItem) LeaseTerm(org.estatio.module.lease.dom.LeaseTerm)

Example 3 with InvoiceItemForLease

use of org.estatio.module.lease.dom.invoicing.InvoiceItemForLease in project estatio by estatio.

the class InvoiceCalculationForDeposit_IntegTest method in_arrears_and_in_advance_in_one_retro_run_works.

@Test
public void in_arrears_and_in_advance_in_one_retro_run_works() {
    // given
    setUpTheGiven();
    // EST-1750: to mimick behaviour through UI
    sessionManagementService.nextSession();
    // when
    LocalDate invoiceDueDate = VT.ld(2012, 1, 1);
    // NOTE: the user has to realize that the due date for invoices in arrears is the last date of the period
    LocalDate startDueDate = VT.ld(2011, 12, 31);
    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.RETRO_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(6);
    InvoiceItemForLease depositItem010Advance = (InvoiceItemForLease) invoiceFor010Advance.findFirstItemWithCharge(chargeForDeposit);
    assertThat(depositItem010Advance.getNetAmount()).isEqualTo(depositValueAfterIndexation);
    InvoiceForLease invoiceFor011Arrears = invoiceForLeaseRepository.findByLease(poisonLease011Arrears).get(0);
    assertThat(invoiceFor011Arrears.getItems().size()).isEqualTo(6);
    InvoiceItemForLease depositItem011Arrears = (InvoiceItemForLease) invoiceFor011Arrears.findFirstItemWithCharge(chargeForDeposit);
    // The user expects that the indexation on 1-1-2012 - which is outside the quarter being invoiced in arrears - is NOT taken into account
    assertThat(depositItem011Arrears.getNetAmount()).isEqualTo(depositValueBeforeIndexation);
}
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 4 with InvoiceItemForLease

use of org.estatio.module.lease.dom.invoicing.InvoiceItemForLease in project estatio by estatio.

the class InvoiceCalculationForDeposit_IntegTest method in_arrears_and_in_advance_in_one_normal_run_works.

@Test
public void in_arrears_and_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: the user has to realize that the due date for invoices in arrears is the last date of the period
    LocalDate startDueDate = VT.ld(2011, 12, 31);
    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(2);
    InvoiceItemForLease rentItem011 = (InvoiceItemForLease) invoiceFor011Arrears.findFirstItemWithCharge(chargeForRent);
    assertThat(rentItem011.getNetAmount()).isEqualTo(quarterlyRentAfterIndexation);
    InvoiceItemForLease depositItem011Arrears = (InvoiceItemForLease) invoiceFor011Arrears.findFirstItemWithCharge(chargeForDeposit);
    // The user expects that the indexation on 1-1-2012 - which is outside the quarter being invoiced in arrears - is NOT taken into account
    assertThat(depositItem011Arrears.getNetAmount()).isEqualTo(depositValueBeforeIndexation);
}
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 5 with InvoiceItemForLease

use of org.estatio.module.lease.dom.invoicing.InvoiceItemForLease in project estatio by estatio.

the class InvoiceCalculationForDeposit_IntegTest method with_due_date_deposit_before_period_retro_run_yields_same_results.

@Test
public void with_due_date_deposit_before_period_retro_run_yields_same_results() {
    // given
    setUpTheGiven();
    // EST-1750: to mimick behaviour through UI
    sessionManagementService.nextSession();
    // when
    LocalDate invoiceDueDate = VT.ld(2012, 1, 1);
    // NOT: NOW it does NOT matter 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.RETRO_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(6);
    InvoiceItemForLease depositItem010Advance = (InvoiceItemForLease) invoiceFor010Advance.findFirstItemWithCharge(chargeForDeposit);
    assertThat(depositItem010Advance.getNetAmount()).isEqualTo(depositValueAfterIndexation);
    InvoiceForLease invoiceFor011Arrears = invoiceForLeaseRepository.findByLease(poisonLease011Arrears).get(0);
    assertThat(invoiceFor011Arrears.getItems().size()).isEqualTo(6);
    InvoiceItemForLease depositItem011Arrears = (InvoiceItemForLease) invoiceFor011Arrears.findFirstItemWithCharge(chargeForDeposit);
    // The user expects that the indexation on 1-1-2012 - which is outside the quarter being invoiced in arrears - is NOT taken into account
    assertThat(depositItem011Arrears.getNetAmount()).isEqualTo(depositValueBeforeIndexation);
}
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)

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