use of org.estatio.module.invoice.dom.InvoicingInterval in project estatio by estatio.
the class InvoicingFrequency_Test method test_due_date.
@Test
public void test_due_date() throws Exception {
// Given
final InvoicingInterval invoicingInterval = InvoicingFrequency.QUARTERLY_IN_ARREARS.intervalMatching(new LocalDate(2013, 1, 1));
assertThat(invoicingInterval.dueDate()).isEqualTo(new LocalDate(2013, 3, 31));
}
use of org.estatio.module.invoice.dom.InvoicingInterval in project estatio by estatio.
the class InvoicingFrequency_Test method testIntervalsInRange.
@Test
public void testIntervalsInRange() {
List<InvoicingInterval> intervalsInRange = InvoicingFrequency.QUARTERLY_IN_ADVANCE.intervalsInRange(new LocalDate(2012, 1, 1), new LocalDate(2014, 4, 1));
assertThat(intervalsInRange).hasSize(9);
}
use of org.estatio.module.invoice.dom.InvoicingInterval 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();
}
use of org.estatio.module.invoice.dom.InvoicingInterval in project estatio by estatio.
the class LeaseItem method dueDatesInRange.
@Programmatic
public SortedSet<LocalDate> dueDatesInRange(LocalDate startDueDate, LocalDate nextDueDate) {
final SortedSet<LocalDate> dates = Sets.newTreeSet();
List<InvoicingInterval> invoiceIntervals = getInvoicingFrequency().intervalsInDueDateRange(startDueDate, nextDueDate);
for (InvoicingInterval interval : invoiceIntervals) {
dates.add(interval.dueDate());
}
return dates;
}
use of org.estatio.module.invoice.dom.InvoicingInterval 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