use of org.killbill.billing.invoice.generator.BillingIntervalDetail in project killbill by killbill.
the class ContiguousIntervalUsageInArrear method build.
/**
* Builds the transitionTimes associated to that usage section. Those are determined based on billing events for when to start and when to stop,
* the per usage billingPeriod and finally the targetDate.
* <p/>
* Those transition dates define the well defined billing granularity periods that should be billed for that specific usage section.
*
* @param closedInterval whether there was a last billing event referencing the usage section or whether this is ongoing and
* then targetDate will define the endDate.
*/
public ContiguousIntervalUsageInArrear build(final boolean closedInterval) {
Preconditions.checkState(!isBuilt.get());
Preconditions.checkState((!closedInterval && billingEvents.size() >= 1) || (closedInterval && billingEvents.size() >= 2));
final LocalDate startDate = internalTenantContext.toLocalDate(billingEvents.get(0).getEffectiveDate());
if (targetDate.isBefore(startDate)) {
return this;
}
final LocalDate endDate = closedInterval ? internalTenantContext.toLocalDate(billingEvents.get(billingEvents.size() - 1).getEffectiveDate()) : targetDate;
final BillingIntervalDetail bid = new BillingIntervalDetail(startDate, endDate, targetDate, getBCD(), usage.getBillingPeriod(), usage.getBillingMode());
int numberOfPeriod = 0;
// First billingCycleDate prior startDate
LocalDate nextBillCycleDate = bid.getFutureBillingDateFor(numberOfPeriod);
if (startDate.compareTo(rawUsageStartDate) >= 0) {
transitionTimes.add(startDate);
}
while (!nextBillCycleDate.isAfter(endDate)) {
if (nextBillCycleDate.isAfter(startDate)) {
if (nextBillCycleDate.compareTo(rawUsageStartDate) >= 0) {
transitionTimes.add(nextBillCycleDate);
}
}
numberOfPeriod++;
nextBillCycleDate = bid.getFutureBillingDateFor(numberOfPeriod);
}
if (closedInterval && endDate.isAfter(transitionTimes.get(transitionTimes.size() - 1))) {
transitionTimes.add(endDate);
}
isBuilt.set(true);
return this;
}
use of org.killbill.billing.invoice.generator.BillingIntervalDetail in project killbill by killbill.
the class ContiguousIntervalUsageInArrear method computeNextNotificationDate.
private LocalDate computeNextNotificationDate() {
LocalDate result = null;
final Iterator<BillingEvent> eventIt = billingEvents.iterator();
BillingEvent nextEvent = eventIt.next();
while (eventIt.hasNext()) {
final BillingEvent thisEvent = nextEvent;
nextEvent = eventIt.next();
final LocalDate startDate = internalTenantContext.toLocalDate(thisEvent.getEffectiveDate());
final LocalDate endDate = internalTenantContext.toLocalDate(nextEvent.getEffectiveDate());
final BillingIntervalDetail bid = new BillingIntervalDetail(startDate, endDate, targetDate, thisEvent.getBillCycleDayLocal(), usage.getBillingPeriod(), BillingMode.IN_ARREAR);
final LocalDate nextBillingCycleDate = bid.getNextBillingCycleDate();
result = (result == null || result.compareTo(nextBillingCycleDate) < 0) ? nextBillingCycleDate : result;
}
final LocalDate startDate = internalTenantContext.toLocalDate(nextEvent.getEffectiveDate());
final BillingIntervalDetail bid = new BillingIntervalDetail(startDate, null, targetDate, nextEvent.getBillCycleDayLocal(), usage.getBillingPeriod(), BillingMode.IN_ARREAR);
final LocalDate nextBillingCycleDate = bid.getNextBillingCycleDate();
result = (result == null || result.compareTo(nextBillingCycleDate) < 0) ? nextBillingCycleDate : result;
return result;
}
Aggregations