Search in sources :

Example 1 with InvoiceCalculationParameters

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

the class InvoiceServiceMenu method doCalculateRetroInvoices.

// //////////////////
private Object doCalculateRetroInvoices(final ApplicationTenancy applicationTenancy, final List<LeaseItemType> leaseItemTypes, final LocalDate startDueDate, final LocalDate nextDueDate) {
    for (Lease lease : leaseRepository.allLeases()) {
        if (lease.getApplicationTenancy().getPath().matches(applicationTenancy.getPath() + ".*")) {
            for (LocalDate dueDate : lease.dueDatesInRange(startDueDate, nextDueDate)) {
                InvoiceCalculationParameters parameters = InvoiceCalculationParameters.builder().lease(lease).leaseItemTypes(leaseItemTypes).invoiceRunType(InvoiceRunType.NORMAL_RUN).invoiceDueDate(dueDate).startDueDate(startDueDate).nextDueDate(dueDate.plusDays(1)).build();
                String runId = invoiceCalculationService.calculateAndInvoice(parameters);
                if (runId != null) {
                    final InvoiceSummaryForInvoiceRun summaryForInvoiceRun = invoiceSummaries.findByRunId(runId);
                    if (summaryForInvoiceRun != null) {
                        summaryForInvoiceRun.saveAllAsHistoric();
                    } else {
                        getContainer().warnUser(String.format("Run Id [%s] not found", runId));
                    }
                }
            }
        }
    }
    return "Done";
}
Also used : Lease(org.estatio.module.lease.dom.Lease) InvoiceSummaryForInvoiceRun(org.estatio.module.lease.dom.invoicing.summary.InvoiceSummaryForInvoiceRun) InvoiceCalculationParameters(org.estatio.module.lease.dom.invoicing.InvoiceCalculationParameters) LocalDate(org.joda.time.LocalDate)

Example 2 with InvoiceCalculationParameters

use of org.estatio.module.lease.dom.invoicing.InvoiceCalculationParameters 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 3 with InvoiceCalculationParameters

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

the class CreateRetroInvoices method createLease.

@Programmatic
public ExecutionContext createLease(final Lease lease, final LocalDate startDueDate, final LocalDate nextDueDate, final ExecutionContext fixtureResults) {
    final SortedSet<LocalDate> dueDates = lease.dueDatesInRange(startDueDate, nextDueDate);
    for (LocalDate dueDate : dueDates) {
        InvoiceCalculationParameters parameters = InvoiceCalculationParameters.builder().lease(lease).leaseItemTypes(InvoiceCalculationSelection.ALL_ITEMS.selectedTypes()).invoiceRunType(InvoiceRunType.NORMAL_RUN).invoiceDueDate(dueDate).startDueDate(startDueDate).nextDueDate(dueDate.plusDays(1)).build();
        createAndApprove(parameters, fixtureResults);
    }
    return fixtureResults;
}
Also used : InvoiceCalculationParameters(org.estatio.module.lease.dom.invoicing.InvoiceCalculationParameters) LocalDate(org.joda.time.LocalDate) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Aggregations

InvoiceCalculationParameters (org.estatio.module.lease.dom.invoicing.InvoiceCalculationParameters)3 LocalDate (org.joda.time.LocalDate)2 BigDecimal (java.math.BigDecimal)1 Programmatic (org.apache.isis.applib.annotation.Programmatic)1 Lease (org.estatio.module.lease.dom.Lease)1 InvoiceItemForLease (org.estatio.module.lease.dom.invoicing.InvoiceItemForLease)1 InvoiceSummaryForInvoiceRun (org.estatio.module.lease.dom.invoicing.summary.InvoiceSummaryForInvoiceRun)1