public static LocalDate alignProposedBillCycleDate(final LocalDate proposedDate, final int billingCycleDay, final BillingPeriod billingPeriod) { // billingCycleDay alignment only makes sense for month based BillingPeriod (MONTHLY, QUARTERLY, BIANNUAL, ANNUAL) final boolean isMonthBased = (billingPeriod.getPeriod().getMonths() | billingPeriod.getPeriod().getYears()) > 0; if (!isMonthBased) { return proposedDate; } final int lastDayOfMonth = proposedDate.dayOfMonth().getMaximumValue(); int proposedBillCycleDate = proposedDate.getDayOfMonth(); if (proposedBillCycleDate < billingCycleDay) { if (billingCycleDay <= lastDayOfMonth) { proposedBillCycleDate = billingCycleDay; } else { proposedBillCycleDate = lastDayOfMonth; } } return new LocalDate(proposedDate.getYear(), proposedDate.getMonthOfYear(), proposedBillCycleDate, proposedDate.getChronology()); }
@Override public int hashCode() { int result = billingPeriod != null ? billingPeriod.hashCode() : 0; result = 31 * result + (recurringPrice != null ? recurringPrice.hashCode() : 0); return result; }
@Override public Collection<Plan> findPlans(final Product product, final BillingPeriod period) { final List<Plan> result = new ArrayList<Plan>(plans.size()); for (final Plan cur : getPlans()) { if (cur.getProduct().equals(product) && (cur.getRecurringBillingPeriod() != null && cur.getRecurringBillingPeriod().equals(period))) { result.add(cur); } } return result; }
final LocalDate[] perBillingPeriodMostRecentConsumableInArrearItemEndDate = new LocalDate[BillingPeriod.values().length - 1]; // Exclude the NO_BILLING_PERIOD int idx = 0; for (final BillingPeriod bp : BillingPeriod.values()) { if (bp != BillingPeriod.NO_BILLING_PERIOD) { final LocalDate makerDateThanCannotBeChosenAsTheMinOfAllDates = InvoiceDateUtils.advanceByNPeriods(targetDate, bp, config.getMaxRawUsagePreviousPeriod(internalCallContext)); final Usage usage = knownUsage.get(item.getUsageName()); if (perBillingPeriodMostRecentConsumableInArrearItemEndDate[usage.getBillingPeriod().ordinal()] == null) { perBillingPeriodMostRecentConsumableInArrearItemEndDate[usage.getBillingPeriod().ordinal()] = item.getEndDate(); if (!containsNullEntries(perBillingPeriodMostRecentConsumableInArrearItemEndDate)) { break; for (final BillingPeriod bp : BillingPeriod.values()) { if (bp != BillingPeriod.NO_BILLING_PERIOD) { final LocalDate tmp = perBillingPeriodMostRecentConsumableInArrearItemEndDate[idx];
if (phase == null) { throw new SubscriptionBaseError(String.format("No initial PlanPhase for Product %s, term %s and set %s does not exist in the catalog", spec.getProductName(), spec.getBillingPeriod().toString(), plan.getPriceListName()));
@Override public void writeExternal(final ObjectOutput out) throws IOException { out.writeObject(product); out.writeBoolean(productCategory != null); if (productCategory != null) { out.writeUTF(productCategory.name()); } out.writeBoolean(billingPeriod != null); if (billingPeriod != null) { out.writeUTF(billingPeriod.name()); } out.writeObject(priceList); }
@Override public List<Listing> getAvailableAddOnListings(final String baseProductName, @Nullable final String priceListName) { final List<Listing> availAddons = new ArrayList<Listing>(); try { final Product product = findCurrentProduct(baseProductName); if (product != null) { for (final Product availAddon : product.getAvailable()) { for (final BillingPeriod billingPeriod : BillingPeriod.values()) { for (final PriceList priceList : getPriceLists().getAllPriceLists()) { if (priceListName == null || priceListName.equals(priceList.getName())) { final Collection<Plan> addonInList = priceList.findPlans(availAddon, billingPeriod); for (final Plan cur : addonInList) { availAddons.add(new DefaultListing(cur, priceList)); } } } } } } } catch (final CatalogApiException e) { // No such product - just return an empty list } return availAddons; }
private List<UsageJson> buildUsagesJson(final Usage[] usages) throws CurrencyValueNull { List<UsageJson> usagesJson = new ArrayList<UsageJson>(); for (int i = 0; i < usages.length; i++) { usagesJson.add(new UsageJson(usages[i].getBillingPeriod().toString(), buildTiers(usages[i].getTiers()))); } return usagesJson; }
@Override public void writeExternal(final ObjectOutput out) throws IOException { out.writeBoolean(billingPeriod != null); if (billingPeriod != null) { out.writeUTF(billingPeriod.name()); } out.writeObject(recurringPrice); out.writeUTF(planName); out.writeBoolean(phaseType != null); if (phaseType != null) { out.writeUTF(phaseType.name()); } }
@Override public List<Listing> getAvailableAddOnListings(final String baseProductName, @Nullable final String priceListName) { final List<Listing> availAddons = new ArrayList<Listing>(); try { final Product product = findCurrentProduct(baseProductName); if (product != null) { for (final Product availAddon : product.getAvailable()) { for (final BillingPeriod billingPeriod : BillingPeriod.values()) { for (final PriceList priceList : getPriceLists().getAllPriceLists()) { if (priceListName == null || priceListName.equals(priceList.getName())) { final Collection<Plan> addonInList = priceList.findPlans(availAddon, billingPeriod); for (final Plan cur : addonInList) { availAddons.add(new DefaultListing(cur, priceList)); } } } } } } } catch (final CatalogApiException e) { // No such product - just return an empty list } return availAddons; }
DateTime proposedDate = chargedThroughDate; while (proposedDate.isAfter(clock.getUTCNow())) { proposedDate = proposedDate.minus(billingPeriod.getPeriod());
@Override public int hashCode() { int result = name != null ? name.hashCode() : 0; result = 31 * result + (billingMode != null ? billingMode.hashCode() : 0); result = 31 * result + (usageType != null ? usageType.hashCode() : 0); result = 31 * result + (tierBlockPolicy != null ? tierBlockPolicy.hashCode() : 0); result = 31 * result + (billingPeriod != null ? billingPeriod.hashCode() : 0); result = 31 * result + (limits != null ? Arrays.hashCode(limits) : 0); result = 31 * result + (blocks != null ? Arrays.hashCode(blocks) : 0); result = 31 * result + (tiers != null ? Arrays.hashCode(tiers) : 0); result = 31 * result + (fixedPrice != null ? fixedPrice.hashCode() : 0); result = 31 * result + (recurringPrice != null ? recurringPrice.hashCode() : 0); return result; }
if (!BillingPeriod.NO_BILLING_PERIOD.equals(getRecurringBillingPeriod()) && recurringBillingMode == null) { errors.add(new ValidationError(String.format("Invalid recurring billingMode for plan '%s'", name), DefaultPlan.class, ""));
if (phase == null) { throw new SubscriptionBaseError(String.format("No initial PlanPhase for Product %s, term %s and set %s does not exist in the catalog", spec.getProductName(), spec.getBillingPeriod().toString(), plan.getPriceListName()));
@Override public void writeExternal(final ObjectOutput out) throws IOException { super.writeExternal(out); out.writeObject(fromProduct); out.writeBoolean(fromProductCategory != null); if (fromProductCategory != null) { out.writeUTF(fromProductCategory.name()); } out.writeBoolean(fromBillingPeriod != null); if (fromBillingPeriod != null) { out.writeUTF(fromBillingPeriod.name()); } out.writeObject(fromPriceList); out.writeObject(toPriceList); }
public static LocalDate recedeByNPeriods(final LocalDate initialDate, final BillingPeriod billingPeriod, final int nbPeriods) { LocalDate proposedDate = initialDate; for (int i = 0; i < nbPeriods; i++) { proposedDate = proposedDate.minus(billingPeriod.getPeriod()); } return proposedDate; } }
@Override public int hashCode() { int result = product != null ? product.hashCode() : 0; result = 31 * result + (productCategory != null ? productCategory.hashCode() : 0); result = 31 * result + (billingPeriod != null ? billingPeriod.hashCode() : 0); result = 31 * result + (priceList != null ? priceList.hashCode() : 0); return result; }
(fromProduct == null || fromProduct.equals(inFromProduct)) && (fromProductCategory == null || fromProductCategory.equals(inFromProductCategory)) && (fromBillingPeriod == null || fromBillingPeriod.equals(inFromBillingPeriod)) && (this.toProduct == null || this.toProduct.equals(inToProduct)) && (this.toProductCategory == null || this.toProductCategory.equals(inToProductCategory)) && (this.toBillingPeriod == null || this.toBillingPeriod.equals(inToBillingPeriod)) && (fromPriceList == null || fromPriceList.equals(inFromPriceList)) && (toPriceList == null || toPriceList.equals(inToPriceList))
@Override public void writeExternal(final ObjectOutput out) throws IOException { out.writeBoolean(phaseType != null); if (phaseType != null) { out.writeUTF(phaseType.name()); } out.writeObject(fromProduct); out.writeBoolean(fromProductCategory != null); if (fromProductCategory != null) { out.writeUTF(fromProductCategory.name()); } out.writeBoolean(fromBillingPeriod != null); if (fromBillingPeriod != null) { out.writeUTF(fromBillingPeriod.name()); } out.writeObject(fromPriceList); out.writeObject(toProduct); out.writeBoolean(toProductCategory != null); if (toProductCategory != null) { out.writeUTF(toProductCategory.name()); } out.writeBoolean(toBillingPeriod != null); if (toBillingPeriod != null) { out.writeUTF(toBillingPeriod.name()); } out.writeObject(toPriceList); }
public static LocalDate advanceByNPeriods(final LocalDate initialDate, final BillingPeriod billingPeriod, final int nbPeriods) { LocalDate proposedDate = initialDate; for (int i = 0; i < nbPeriods; i++) { proposedDate = proposedDate.plus(billingPeriod.getPeriod()); } return proposedDate; }