Use Billing module Java API

 Add subscription service usage
Example
...
@EJB private CRMBOSubscriptionBean subscriptionBean;
@EJB private CRMBOSubscriptionServiceBean subscriptionServiceBean;
@EJB private CRMBOProductBean productBean;
@EJB private CRMBOUsageServiceCatalogBean usageServiceCatalogBean;
@EJB private CRMProcessServiceUsageAdditionBean processServiceUsageAdditionBean;
...
 
public CRMDOSubscriptionAction addSubscriptionServiceUsage(String subscriptionNumber, String productCode, String subscriptionServiceID, BigDecimal usageAmount, BillingDirectiveState billingDirective, String uscName){
	
	ArrayList<String> associations = new ArrayList<String>();
	associations.add("accountReceivable");
	associations.add("accountReceivable.billToAddress");
	associations.add("type");
	CRMDOSubscription subscription = subscriptionBean.loadByNumber(subscriptionNumber);
 
	//Load product
	ArrayList<String> productAssociations = new ArrayList<String>();
	productAssociations.add("type");
	productAssociations.add("type.udrType");
	productAssociations.add("type.udrType.udrTypeUOM");
	CRMDOProduct product = productBean.loadByCode(productCode);
	
	//Load subscription service
	CRMDOSubscriptionService subscriptionService =subscriptionServiceBean.load(subscriptionServiceID);
 
	//Load usage service catalog
	CRMDOUsageServiceCatalog usageServiceCatalog = usageServiceCatalogBean.loadByName(uscName);
 
	//Create a set of UDRs
	Set<CRMDOUdr> udrs = new HashSet<CRMDOUdr>();
 
	//Construct UDR(s)
	CRMDOUdr udr = udrBean.construct(subscription, subscriptionService, product);
	udr.setUsageAmount(usageAmount);
	udr.setBillingDirective(billingDirective);
	if(billingDirective.equals(BillingDirectiveState.NOT_TO_BE_BILLED))
	{
		udr.setRatingState(UdrRatingState.COMPLETED);
	}
	udr.setUsageServiceCatalog(usageServiceCatalog);
 
	//Add UDR to UDRS set
	udrs.add(udr);
 
	//Construct service usage addition
	ServiceUsageAddition serviceUsageAddition = processServiceUsageAdditionBean.constructServiceUsageAddition(subscription);
	serviceUsageAddition.setUdrsToBeProcessed(udrs);
 
	CRMDOSubscriptionAction subscriptionAction = processServiceUsageAdditionBean.submit(serviceUsageAddition);

 
	return subscriptionAction ;
}
 Bill Subscriber
Example
...
@EJB private CRMBOSubscriptionBean subscriptionBean;
@EJB private CRMProcessSubscriptionBillBean processSubscriptionBillBean;
@EJB private CRMBOAccountReceivableBean accountBean;
@EJB private CRMBOContactInformationBean contactInformationBean; 
...
 
public CRMDOSubscriptionAction billSubscription(String subscriptionNumber, Date asOfDate){
	
	CRMDOSubscription subscription = subscriptionBean.loadByNumber(subscriptionNumber);
 
	if(subscription.getRatingState() != null
	   && subscription.getRatingState().equals(SubscriptionRatingState.COMPLETED))
	{
		throw new InvalidValueException(getCRMSession(), "subscription. Subscription is already billed");
	}
 
	SubscriptionBill subscriptionBill = processSubscriptionBillBean.constructSubscriptionBill(subscription);
 
	CRMDOAccountReceivable account = (CRMDOAccountReceivable)accountBean.load(subscription.getAccountReceivable().getId());
	account.setContactInformation((CRMDOContactInformation)contactInformationBean.load(subscription.getAccountReceivable().getContactInformation().getId()));
	subscriptionBill.getSubscription().setAccountReceivable(account);
	
	BillType billtype = subscription.getEffectiveBillingTerm().getBillingTermScheme().getBillingType();
		
	if (billtype!=null && billtype.equals(BillType.NORMAL))
	{
	
		if (asOfDate!=null)
		{
			processSubscriptionBillBean.setBillAsOfDate(subscriptionBill, BillAsOfDateOption.SPECIFIC_DATE, asOfDate);
		}
		else
		{
			//as of date is the current date
			processSubscriptionBillBean.setBillAsOfDate(subscriptionBill, BillAsOfDateOption.SCHEDULED_DATE, null);
		}
	}
	else //if it's PREPAID
	{
		Date asOfDate = subscriptionBean.getNextLatestRatedToDate(subscription);
		if(asOfDate!=null && asOfDate.after(getCurrentDate()))
		{
			processSubscriptionBillBean.setBillAsOfDate(subscriptionBill, BillAsOfDateOption.SPECIFIC_DATE, asOfDate);
		}
		else
		{
			//as of date is the current date
			processSubscriptionBillBean.setBillAsOfDate(subscriptionBill, BillAsOfDateOption.SCHEDULED_DATE, null);
		}
	}
 
	CRMDOSubscriptionAction subscriptionAction = processSubscriptionBillBean.submit(subscriptionBill);
		
	return subscriptionAction;
}

 

Â