- Print
- DarkLight
Number Series
Number series are a way to generate numbers for data transaction and are widely used in the Comactivity Supply Chain Suite.
The function includes a setup of number series and an API to retrieve the next number.
The setup is done in the menu under System Administration/Application Settings. See example below.
The tables and columns for number series are in Rep_CACORE (and more lately also in the ComActivityBASE project, but still in metadataid CACORE), which is the intended place for them in the future.
The API for retrieving values from a number series is net.comactivity.core.applications.services.NumberSeriesService and it is found in project net.comactivity.core.
Examples
Example 1: Getting a package number from number series:
Using the API:
public class PackagingReportStartNewPacking extends AbstractRule {
...
public static int retrieveNewPackageNo(LogicalUnitOfWork luow) {
try {
// Retrieve next Package Number from number serie 650
NumberSeriesService ns = (NumberSeriesService) SystemWorkspace.getApplicationService("NumberSeriesService");
String enterprise = luow.getSessionValues().getValue("Enterprise");
NumberSeries nsPackageNo = ns.getNumberSeries(enterprise, "650");
int packageNo = ns.getNextNumber(enterprise, nsPackageNo, null, null);
return packageNo;
} catch (Exception e) {
AppErr.handleException(luow, PackageHeader.class, e);
return 0;
}
}
Example:
Retrieving a new invoice number for an invoice within the Supply Chain Suite, controlled by Company and by Sales order category (0 = Normal invoice, 1= Credit, 8 = Internal invoice, 9 = Distribution Order):
You can see from the above that the intention is that company 001 invoices range from 1-1999999, company 002 from 2000000 to 2999999 and company 004 from 4000000 to 4999999, and within these ranges there are subranges to easily distinguish different kinds of invoices.
When I set the number series up like this it also means I need to pass more paremeters into the interface, which is illustrated below.
public class SalesOrderInvoicingRunImpl extends ApplicationService implements SalesOrderInvoicingRun {
...
// Use right number series for sales invoice number
numberserie = NoSeriesHeader.NOSERIESID_SALES_INVOICE;
try {
value1 = sotype.getCompany();
String value2 = String.valueOf(sotype.getSOCategory());
salesInvoiceNo = NoSeriesHeader.getNewOrderNumber(salesDeliveryHeader.getEnterprise(), numberserie, value1, value2);
} catch (ApplicationException err) {
// no invoice number found, terminate
ApplicationError numberSeriesError = null;
if (err.getCAError() instanceof ApplicationError) {
numberSeriesError = (ApplicationError) err.getCAError();
AppErr.handleException(env, getClass(), numberSeriesError);
else {
AppErr.handleException(env, getClass(), "Number series error: " + numberserie);
}
error = true;
}
Note: The number series component itself never operates under commit control since this would create a bottleneck in the system. Which of course does not stop you to invoke from within a database transaction with commit control - but also if you end rolling back, that number series will be consumed.