Search in sources :

Example 11 with LocalDateInterval

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

the class PeriodUtilTest method periodFromInterval_success.

@Test
public void periodFromInterval_success() throws Exception {
    // given
    LocalDate startDate;
    LocalDate endDate;
    LocalDateInterval interval;
    // when
    startDate = new LocalDate(2017, 01, 01);
    endDate = new LocalDate(2017, 12, 31);
    interval = new LocalDateInterval(startDate, endDate);
    // then
    Assertions.assertThat(PeriodUtil.periodFromInterval(interval)).isEqualTo("2017");
    // when
    startDate = new LocalDate(2016, 07, 01);
    endDate = new LocalDate(2017, 06, 30);
    interval = new LocalDateInterval(startDate, endDate);
    // then
    Assertions.assertThat(PeriodUtil.periodFromInterval(interval)).isEqualTo("F2017");
}
Also used : LocalDate(org.joda.time.LocalDate) LocalDateInterval(org.incode.module.base.dom.valuetypes.LocalDateInterval) Test(org.junit.Test)

Example 12 with LocalDateInterval

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

the class PeriodUtilTest method periodFromInterval_fail.

@Test
public void periodFromInterval_fail() throws Exception {
    // given
    LocalDate startDate;
    LocalDate endDate;
    LocalDateInterval interval;
    // when
    startDate = new LocalDate(2017, 01, 02);
    endDate = new LocalDate(2017, 12, 31);
    interval = new LocalDateInterval(startDate, endDate);
    // then
    Assertions.assertThat(PeriodUtil.periodFromInterval(interval)).isNull();
    // when
    startDate = new LocalDate(2016, 07, 01);
    endDate = new LocalDate(2017, 06, 29);
    interval = new LocalDateInterval(startDate, endDate);
    // then
    Assertions.assertThat(PeriodUtil.periodFromInterval(interval)).isNull();
}
Also used : LocalDate(org.joda.time.LocalDate) LocalDateInterval(org.incode.module.base.dom.valuetypes.LocalDateInterval) Test(org.junit.Test)

Example 13 with LocalDateInterval

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

the class LeaseTerm method verifyUntil.

@Action(semantics = SemanticsOf.IDEMPOTENT)
public LeaseTerm verifyUntil(final LocalDate date) {
    LeaseTerm nextTerm = getNext();
    boolean autoCreateTerms = getLeaseItem().getType().autoCreateTerms();
    if (autoCreateTerms) {
        // Remove items after the period
        LocalDateInterval effectiveInterval = getLeaseItem().getEffectiveInterval();
        LocalDate endDateExcluding = effectiveInterval != null ? effectiveInterval.endDateExcluding() : date;
        if (getNext() != null && endDateExcluding != null && getNext().getStartDate().compareTo(endDateExcluding) >= 0) {
            getNext().doRemove();
            return this;
        }
    }
    align();
    if (autoCreateTerms) {
        // convenience code to automatically create terms but not for terms
        // who have a start date after today
        LocalDateInterval effectiveInterval = getLeaseItem().getEffectiveInterval();
        LocalDate minDate = ObjectUtils.min(effectiveInterval == null ? null : effectiveInterval.endDateExcluding(), date);
        LocalDate nextStartDate = nextStartDate();
        if (nextTerm == null && nextStartDate.compareTo(minDate) < 0) {
            LocalDate nextstartDate = default0CreateNext(null, null);
            LocalDate nextEndDate = default1CreateNext(null, null);
            nextTerm = createNext(nextstartDate, nextEndDate);
        }
    }
    if (nextTerm != null) {
        nextTerm.verifyUntil(date);
    }
    return this;
}
Also used : LocalDate(org.joda.time.LocalDate) LocalDateInterval(org.incode.module.base.dom.valuetypes.LocalDateInterval) Action(org.apache.isis.applib.annotation.Action)

Example 14 with LocalDateInterval

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

the class LeaseTerm method verify.

// //////////////////////////////////////
@Action(semantics = SemanticsOf.IDEMPOTENT, invokeOn = InvokeOn.OBJECT_AND_COLLECTION)
public LeaseTerm verify() {
    LocalDateInterval effectiveInterval = getLeaseItem().getEffectiveInterval();
    verifyUntil(ObjectUtils.min(effectiveInterval == null ? null : effectiveInterval.endDateExcluding(), getClockService().now()));
    return this;
}
Also used : LocalDateInterval(org.incode.module.base.dom.valuetypes.LocalDateInterval) Action(org.apache.isis.applib.annotation.Action)

Example 15 with LocalDateInterval

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

the class InvoiceCalculationService method calculateTerm.

/**
 * Calculates a term for a given list of invoicing intervals
 *
 * @param leaseTerm
 * @param intervals
 * @return
 */
@Programmatic
public List<CalculationResult> calculateTerm(final LeaseTerm leaseTerm, final List<InvoicingInterval> intervals) {
    final List<CalculationResult> results2 = Lists.newArrayList();
    if (!intervals.isEmpty()) {
        LocalDate dueDateForCalculation = intervals.get(intervals.size() - 1).dueDate();
        for (final InvoicingInterval invoicingInterval : intervals) {
            final LocalDate epochDate = ObjectUtils.firstNonNull(leaseTerm.getLeaseItem().getEpochDate(), systemEpochDate());
            if (!invoicingInterval.dueDate().isBefore(epochDate)) {
                final LocalDateInterval effectiveInterval = invoicingInterval.asLocalDateInterval().overlap(leaseTerm.getEffectiveInterval());
                if (effectiveInterval == null) {
                    results2.add(new CalculationResult(invoicingInterval));
                } else {
                    final BigDecimal overlapDays = new BigDecimal(effectiveInterval.days());
                    final BigDecimal frequencyDays = new BigDecimal(invoicingInterval.days());
                    final BigDecimal rangeFactor = frequencyDays.equals(BigDecimal.ZERO) ? BigDecimal.ZERO : overlapDays.divide(frequencyDays, MathContext.DECIMAL64);
                    final BigDecimal annualFactor = leaseTerm.getLeaseItem().getInvoicingFrequency().annualMultiplier();
                    final CalculationResult calculationResult = new CalculationResult(invoicingInterval, effectiveInterval, calculateValue(rangeFactor, annualFactor, leaseTerm.valueForDate(dueDateForCalculation), leaseTerm.valueType()));
                    results2.add(calculationResult);
                }
            }
        }
    }
    return results2;
}
Also used : InvoicingInterval(org.estatio.module.invoice.dom.InvoicingInterval) LocalDate(org.joda.time.LocalDate) LocalDateInterval(org.incode.module.base.dom.valuetypes.LocalDateInterval) BigDecimal(java.math.BigDecimal) Programmatic(org.apache.isis.applib.annotation.Programmatic)

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