Search in sources :

Example 6 with LocalDateInterval

use of org.incode.module.base.dom.valuetypes.LocalDateInterval in project estatio by estatio.

the class InvoiceCalculationParameters method toString.

public String toString() {
    TitleBuffer tb = new TitleBuffer();
    tb.append(" -", property().getReference()).append(" -", leasesToReferences()).append(" -", leaseItemTypes()).append(" -", invoiceDueDate()).append(" -", new LocalDateInterval(startDueDate, nextDueDate, IntervalEnding.EXCLUDING_END_DATE)).toString();
    return tb.toString();
}
Also used : TitleBuffer(org.apache.isis.applib.util.TitleBuffer) LocalDateInterval(org.incode.module.base.dom.valuetypes.LocalDateInterval)

Example 7 with LocalDateInterval

use of org.incode.module.base.dom.valuetypes.LocalDateInterval in project estatio by estatio.

the class InvoiceCalculationService method calculateDueDateRange.

/**
 * Calculates a term with a given invoicing frequency
 */
@Programmatic
public List<CalculationResult> calculateDueDateRange(final LeaseTerm leaseTerm, final InvoiceCalculationParameters parameters) {
    final LocalDateInterval dueDateRangeInterval = parameters.invoiceRunType().equals(InvoiceRunType.RETRO_RUN) && leaseTerm.getLeaseItem().getLease().getStartDate().compareTo(parameters.dueDateRange().startDate()) < 0 ? new LocalDateInterval(leaseTerm.getLeaseItem().getLease().getStartDate(), parameters.dueDateRange().endDateExcluding(), IntervalEnding.EXCLUDING_END_DATE) : parameters.dueDateRange();
    // performance, EST-315, should get some attention.
    if (dueDateRangeInterval.isValid()) {
        final List<InvoicingInterval> intervals = leaseTerm.getLeaseItem().getInvoicingFrequency().intervalsInDueDateRange(dueDateRangeInterval, leaseTerm.getInterval());
        final LocalDate dueDateForCalculation = parameters.dueDateRange().endDateExcluding().minusDays(1);
        return calculateTerm(leaseTerm, intervals);
    }
    return Lists.newArrayList();
}
Also used : InvoicingInterval(org.estatio.module.invoice.dom.InvoicingInterval) LocalDate(org.joda.time.LocalDate) LocalDateInterval(org.incode.module.base.dom.valuetypes.LocalDateInterval) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 8 with LocalDateInterval

use of org.incode.module.base.dom.valuetypes.LocalDateInterval in project estatio by estatio.

the class InvoiceCalculationService method createInvoiceItems.

/**
 * Calculates an invoice item with the difference between the already
 * invoiced and calculated value.
 */
void createInvoiceItems(final LeaseTerm leaseTerm, final InvoiceCalculationParameters parameters, final List<CalculationResult> results) {
    for (CalculationResult result : results) {
        // values on a normal run
        if (result.value().compareTo(BigDecimal.ZERO) != 0 || parameters.invoiceRunType().equals(InvoiceRunType.RETRO_RUN)) {
            final LocalDateInterval invoicingInterval = result.invoicingInterval().asLocalDateInterval();
            BigDecimal invoicedValue = invoiceItemForLeaseRepository.invoicedValue(leaseTerm, invoicingInterval);
            BigDecimal newValue = result.value().subtract(invoicedValue);
            // 
            LocalDateInterval calculationInterval = result.effectiveInterval();
            LocalDateInterval effectiveInterval = calculationInterval;
            Boolean adjustment = false;
            if (newValue.compareTo(BigDecimal.ZERO) != 0) {
                if (invoicedValue.compareTo(BigDecimal.ZERO) != 0) {
                    // Has been invoiced before
                    if (invoiceItemForLeaseRepository.findByLeaseTermAndEffectiveInterval(leaseTerm, calculationInterval).size() > 0) {
                        // this exact period has been invoiced before so it is an adjusment
                        adjustment = true;
                    } else {
                        // there is new calculated amount which is caused by tinkering the dates
                        effectiveInterval = attemptToCalculateRightSideLeftover(invoicingInterval, calculationInterval);
                    }
                }
                InvoiceItemForLease invoiceItem = invoiceItemForLeaseRepository.createUnapprovedInvoiceItem(leaseTerm, invoicingInterval, calculationInterval, effectiveInterval, parameters.invoiceDueDate(), interactionId);
                invoiceItem.setNetAmount(newValue);
                invoiceItem.setQuantity(BigDecimal.ONE);
                LeaseItem leaseItem = leaseTerm.getLeaseItem();
                Charge charge = leaseItem.getCharge();
                invoiceItem.setCharge(charge);
                invoiceItem.setTax(leaseItem.getEffectiveTax());
                final InvoiceItemAttributesVM vm = new InvoiceItemAttributesVM(invoiceItem);
                final String description = fragmentRenderService.render(vm, "description");
                invoiceItem.setDescription(description);
                invoiceItem.verify();
                invoiceItem.setAdjustment(adjustment);
            }
        }
    }
}
Also used : InvoiceItemAttributesVM(org.estatio.module.lease.dom.invoicing.ssrs.InvoiceItemAttributesVM) Charge(org.estatio.module.charge.dom.Charge) LocalDateInterval(org.incode.module.base.dom.valuetypes.LocalDateInterval) BigDecimal(java.math.BigDecimal) LeaseItem(org.estatio.module.lease.dom.LeaseItem)

Example 9 with LocalDateInterval

use of org.incode.module.base.dom.valuetypes.LocalDateInterval in project estatio by estatio.

the class Lease method verifyUntil.

@Action(semantics = SemanticsOf.IDEMPOTENT)
public Lease verifyUntil(final LocalDate date) {
    for (LeaseItem item : getItems()) {
        LocalDateInterval effectiveInterval = item.getEffectiveInterval();
        item.verifyUntil(ObjectUtils.min(effectiveInterval == null ? null : effectiveInterval.endDateExcluding(), date));
    }
    return this;
}
Also used : LocalDateInterval(org.incode.module.base.dom.valuetypes.LocalDateInterval) Action(org.apache.isis.applib.annotation.Action)

Example 10 with LocalDateInterval

use of org.incode.module.base.dom.valuetypes.LocalDateInterval in project estatio by estatio.

the class LeaseTermRepository method findTermsWithInvalidInterval.

@Action(semantics = SemanticsOf.SAFE)
@MemberOrder(sequence = "30")
public List<LeaseTerm> findTermsWithInvalidInterval() {
    List<LeaseTerm> lts = allLeaseTerms();
    List<LeaseTerm> returnList = new ArrayList<>();
    LocalDateInterval ldi;
    for (LeaseTerm lt : lts) {
        try {
            if ((ldi = lt.getEffectiveInterval()) == null) {
                returnList.add(lt);
                continue;
            }
            if (!ldi.isValid()) {
                returnList.add(lt);
                continue;
            }
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            returnList.add(lt);
        }
    }
    if (returnList.isEmpty()) {
        return null;
    } else {
        return returnList;
    }
}
Also used : ArrayList(java.util.ArrayList) LocalDateInterval(org.incode.module.base.dom.valuetypes.LocalDateInterval) Action(org.apache.isis.applib.annotation.Action) MemberOrder(org.apache.isis.applib.annotation.MemberOrder)

Aggregations

LocalDateInterval (org.incode.module.base.dom.valuetypes.LocalDateInterval)17 LocalDate (org.joda.time.LocalDate)8 BigDecimal (java.math.BigDecimal)4 Action (org.apache.isis.applib.annotation.Action)4 Programmatic (org.apache.isis.applib.annotation.Programmatic)3 ArrayList (java.util.ArrayList)2 MemberOrder (org.apache.isis.applib.annotation.MemberOrder)2 Charge (org.estatio.module.charge.dom.Charge)2 InvoicingInterval (org.estatio.module.invoice.dom.InvoicingInterval)2 LeaseItem (org.estatio.module.lease.dom.LeaseItem)2 Test (org.junit.Test)2 Nullable (javax.annotation.Nullable)1 TitleBuffer (org.apache.isis.applib.util.TitleBuffer)1 FixedAssetRole (org.estatio.module.asset.dom.role.FixedAssetRole)1 BudgetCalculationResult (org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult)1 BudgetCalculationRun (org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationRun)1 CodaElement (org.estatio.module.capex.dom.coda.CodaElement)1 CodaElementLevel (org.estatio.module.capex.dom.coda.CodaElementLevel)1 CodaTransactionType (org.estatio.module.capex.dom.coda.CodaTransactionType)1 DocumentType (org.estatio.module.capex.dom.coda.DocumentType)1