public static LocalDate alignProposedBillCycleDate(final DateTime proposedDate, final int billingCycleDay, final BillingPeriod billingPeriod, final InternalTenantContext internalTenantContext) { final LocalDate proposedLocalDate = internalTenantContext.toLocalDate(proposedDate); final LocalDate resultingLocalDate = alignProposedBillCycleDate(proposedLocalDate, billingCycleDay, billingPeriod); return resultingLocalDate; }
private static int calculateBcdFromSubscription(final SubscriptionBase subscription, final InternalTenantContext internalTenantContext) { final DateTime date = subscription.getDateOfFirstRecurringNonZeroCharge(); final int bcdLocal = internalTenantContext.toLocalDate(date).getDayOfMonth(); log.debug("Calculated BCD: subscriptionId='{}', subscriptionStartDate='{}', bcd='{}'", subscription.getId(), date.toDateTimeISO(), bcdLocal); return bcdLocal; } }
private DateTime getDryRunEffectiveDate(@Nullable final LocalDate inputDate, final SubscriptionBase subscription, final InternalTenantContext context) { if (inputDate == null) { return null; } // We first use context account reference time to get a candidate) final DateTime tmp = context.toUTCDateTime(inputDate); // If we realize that the candidate is on the same LocalDate boundary as the subscription startDate but a bit prior we correct it to avoid weird things down the line if (inputDate.compareTo(context.toLocalDate(subscription.getStartDate())) == 0 && tmp.compareTo(subscription.getStartDate()) < 0) { return subscription.getStartDate(); } else { return tmp; } }
public void checkAddonCreationRights(final SubscriptionBase baseSubscription, final Plan targetAddOnPlan, final DateTime requestedDate, final InternalTenantContext context) throws SubscriptionBaseApiException { if (baseSubscription.getState() == EntitlementState.CANCELLED || (baseSubscription.getState() == EntitlementState.PENDING && context.toLocalDate(baseSubscription.getStartDate()).compareTo(context.toLocalDate(requestedDate)) < 0)) { throw new SubscriptionBaseApiException(ErrorCode.SUB_CREATE_AO_BP_NON_ACTIVE, targetAddOnPlan.getName()); } final Plan currentOrPendingPlan = baseSubscription.getCurrentOrPendingPlan(); final Product baseProduct = currentOrPendingPlan.getProduct(); if (isAddonIncluded(baseProduct, targetAddOnPlan)) { throw new SubscriptionBaseApiException(ErrorCode.SUB_CREATE_AO_ALREADY_INCLUDED, targetAddOnPlan.getName(), currentOrPendingPlan.getProduct().getName()); } if (!isAddonAvailable(baseProduct, targetAddOnPlan)) { throw new SubscriptionBaseApiException(ErrorCode.SUB_CREATE_AO_NOT_AVAILABLE, targetAddOnPlan.getName(), currentOrPendingPlan.getProduct().getName()); } }
public static LocalDate alignProposedBillCycleDate(final DateTime proposedDate, final int billingCycleDay, final BillingPeriod billingPeriod, final InternalTenantContext internalTenantContext) { final LocalDate proposedLocalDate = internalTenantContext.toLocalDate(proposedDate); final LocalDate resultingLocalDate = alignProposedBillCycleDate(proposedLocalDate, billingCycleDay, billingPeriod); return resultingLocalDate; }
(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 LocalDate transitionStartDate = internalTenantContext.toLocalDate(billingEvent.getEffectiveDate()); if (i == billingEvents.size() - 1) { addTransitionTimesForBillingEvent(transitionStartDate, endDate, billingEvent.getBillCycleDayLocal()); } else { final BillingEvent nextBillingEvent = billingEvents.get(i + 1); final LocalDate nextEndDate = internalTenantContext.toLocalDate(nextBillingEvent.getEffectiveDate()); addTransitionTimesForBillingEvent(transitionStartDate, nextEndDate, billingEvent.getBillCycleDayLocal());
private static int calculateBcdFromSubscription(final SubscriptionBase subscription, final InternalTenantContext internalTenantContext) { final DateTime date = subscription.getDateOfFirstRecurringNonZeroCharge(); final int bcdLocal = internalTenantContext.toLocalDate(date).getDayOfMonth(); log.debug("Calculated BCD: subscriptionId='{}', subscriptionStartDate='{}', bcd='{}'", subscription.getId(), date.toDateTimeISO(), bcdLocal); return bcdLocal; } }
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; }
private DateTime getDryRunEffectiveDate(@Nullable final LocalDate inputDate, final SubscriptionBase subscription, final InternalTenantContext context) { if (inputDate == null) { return null; } // We first use context account reference time to get a candidate) final DateTime tmp = context.toUTCDateTime(inputDate); // If we realize that the candidate is on the same LocalDate boundary as the subscription startDate but a bit prior we correct it to avoid weird things down the line if (inputDate.compareTo(context.toLocalDate(subscription.getStartDate())) == 0 && tmp.compareTo(subscription.getStartDate()) < 0) { return subscription.getStartDate(); } else { return tmp; } }
/** * Check if the date portion of a date/time is before or equals at now (as returned by the clock). * * @param inputDate the fully qualified DateTime * @param accountTimeZone the account timezone * @param internalTenantContext the context * @return true if the inputDate, once converted into a LocalDate using account timezone is less or equals than today */ private boolean isBeforeOrEqualsToday(final DateTime inputDate, final DateTimeZone accountTimeZone, final InternalTenantContext internalTenantContext) { final LocalDate localDateNowInAccountTimezone = clock.getToday(accountTimeZone); final LocalDate targetDateInAccountTimezone = internalTenantContext.toLocalDate(inputDate); return targetDateInAccountTimezone.compareTo(localDateNowInAccountTimezone) <= 0; }
public void checkAddonCreationRights(final SubscriptionBase baseSubscription, final Plan targetAddOnPlan, final DateTime requestedDate, final InternalTenantContext context) throws SubscriptionBaseApiException { if (baseSubscription.getState() == EntitlementState.CANCELLED || (baseSubscription.getState() == EntitlementState.PENDING && context.toLocalDate(baseSubscription.getStartDate()).compareTo(context.toLocalDate(requestedDate)) < 0)) { throw new SubscriptionBaseApiException(ErrorCode.SUB_CREATE_AO_BP_NON_ACTIVE, targetAddOnPlan.getName()); } final Plan currentOrPendingPlan = baseSubscription.getCurrentOrPendingPlan(); final Product baseProduct = currentOrPendingPlan.getProduct(); if (isAddonIncluded(baseProduct, targetAddOnPlan)) { throw new SubscriptionBaseApiException(ErrorCode.SUB_CREATE_AO_ALREADY_INCLUDED, targetAddOnPlan.getName(), currentOrPendingPlan.getProduct().getName()); } if (!isAddonAvailable(baseProduct, targetAddOnPlan)) { throw new SubscriptionBaseApiException(ErrorCode.SUB_CREATE_AO_NOT_AVAILABLE, targetAddOnPlan.getName(), currentOrPendingPlan.getProduct().getName()); } }
@Override public Iterable<DefaultInvoice> prepareInvoices() throws InvoiceApiException { final LocalDate invoiceDate = internalTenantContext.toLocalDate(context.getCreatedDate());