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");
}
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();
}
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;
}
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;
}
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;
}
Aggregations