Manages sales data series and the sales data records logged against them, and the points allocation sources that turn those records into reward points or debits. Covers creating and looking up series, categories and extra fields; recording, finding and aggregating individual sales data points; and running the points allocation engine, including a dry-run mode that writes a preview spreadsheet instead of issuing real points. Reached from server-side JS as the registered "dataSeriesManager" service.

Group: Managers

Implements: StartableService


Properties

PropertyReturnsDescription
allCategoriesList<SalesDataSeriesCategory>Finds all sales data series categories for the current tenant.
allSeriesList<SalesDataSeries>Finds all sales data series for the current tenant.

Methods

dryRunPreviewPath(SalesDataSeries series) · hasDryRunPreview(SalesDataSeries series) · deleteDryRunPreview(SalesDataSeries series) · createDryRunPreviewTable(SalesDataSeries series) · findDataSeriesContent(String seriesName) · findByIds(Collection<Long> ids) · countUnprocessedSalesRecs() · countUnprocessedSalesRecs(Date startDate, Date endDate) · findEntitiesWithUnprocessedRecs() · countPointsAllocationsWithErrors() · findPointsAllocationsWithErrors(SearchProperties searchProperties) · dataSeriesExtraFields(SalesDataSeries sds) · resetPointsAllocations(List<SalesDataRecord> records, boolean deleteSales) · resetPointsAllocations(SalesDataRecord rec, boolean deleteSale, boolean resetPointsBalance) · resetPointsAllocations(SalesDataRecord rec, boolean deleteSale, boolean resetPointsBalance, boolean createDebitForUsedPoints) · resetPointsAllocations(SalesDataRecord rec) · resetSalesRecord(SalesDataRecord rec) · resetPointsAllocations(SalesDataRecord rec, boolean deleteSales) · resetListPointsAllocations(List<PointsAllocation> listPa, boolean deleteSales) · resetPointsAllocation(PointsAllocation pa, boolean deleteSales, boolean resetPointsBalance) · resetPointsAllocation(PointsAllocation pa, boolean deleteSales) · processPointsAllocation(SalesDataSeries series, Consumer<String> progressCallback) · processPointsAllocation(PointsAllocationSource pas, List<SalesDataRecord> records, Consumer<String> progressCallback, Set<SalesDataRecord> processed) · processPointsAllocation(PointsAllocationSource pas, List<SalesDataRecord> records, Consumer<String> progressCallback, Set<SalesDataRecord> processed, Map<Long,Set<Long>> entitiesRewards) · processSingleRecordPoints(SalesDataRecord r) · testPointsAllocation(PointsAllocationSource pas, SalesDataRecord r) · testPointsAllocation(PointsAllocationSource pas, SalesDataRecord r, List<String> logs) · createPointsAllocationSource(String name, String title, SalesDataSeries series, Reward reward) · findPointsAllocationSource(Long id) · findPointsAllocation(Long id) · pointsAllocations(SalesDataRecord salesDataRecord) · updateSalesRecord(SalesDataRecord record, FormContext rc) · salesRecordUpdated(SalesDataRecord sdr) · allocationType(String s) · newPointsAllocationSourceBuilder(SalesDataSeries series) · duplicatePointsAllocationSource(String name, String title, SalesDataSeries series, PointsAllocationSource fromPAS) · calculateAllocationPoints(PointsAllocationSource pas, SalesDataRecord r) · calculateAllocationPoints(PointsAllocationSource pas, SalesDataRecord r, Formatter f) · findPointsRecipient(SalesDataRecord rec, PointsAllocationSource source) · isAllocationPointsIncluded(PointsAllocationSource pas, SalesDataRecord r) · findMatchingSources(SalesDataSeries series, SalesDataRecord r) · sum(SalesDataSeries series, BaseEntity attributedTo, Date startDate, Date endDate) · sum(SalesDataSeries series, Set<BaseEntity> attributedTo, Date startDate, Date endDate) · sumByOrg(SalesDataSeries series, Organisation attributedTo, Date startDate, Date endDate) · average(SalesDataSeries series, BaseEntity attributedTo, Date startDate, Date endDate) · count(SalesDataSeries series, BaseEntity attributedTo, Date startDate, Date endDate) · minimum(SalesDataSeries series, BaseEntity attributedTo, Date startDate, Date endDate) · maximum(SalesDataSeries series, BaseEntity attributedTo, Date startDate, Date endDate) · createSeries(String name, String title, Group salesByGroup) · createSeries(String name, String title, Group salesByGroup, Website website, String defaultAgg, boolean autoCalculation) · createSeries(String name, String title, Group salesByGroup, Website website, String defaultAgg, boolean autoCalculation, SalesType salesType) · findAggregationType(String aggregationType) · findSeriesByName(String name) · dataSeries(String name) · getAllSeries() · getAllCategories() · findCategoryByName(String name) · createCategory(String name, String title) · dataSeriesSalesType(String name) · dataSeriesFrequency(String name) · dataSeriesAggregationType(String name) · isOrgSaleType(SalesDataSeries series) · findRecord(long id) · findRecords(SalesDataSeries series, Date from, Date to, String orderByField, Boolean asc) · findRecords(SalesDataSeries series, BaseEntity baseEntity, Date from, Date to) · findRecords(SalesDataSeries series, List<BaseEntity> baseEntities, Date from, Date to, String orderByField, Boolean asc) · sumRecords(SalesDataSeries series, BaseEntity baseEntity, Date from, Date to) · averageRecords(SalesDataSeries series, BaseEntity baseEntity, Date from, Date to) · countRecords(SalesDataSeries series, BaseEntity baseEntity, Date from, Date to) · findEntityForSeries(SalesDataSeries series, Profile user) · findEntitiesForSeries(SalesDataSeries series, Profile user) · toRecordBeans(List<SalesDataRecord> recs) · insertDataPoint(DataPoint dp) · salesDataRecordUpdated(SalesDataRecord sdr) · deleteRecord(SalesDataRecord sdr) · findDataRecords(SalesDataSeries series, BaseEntity attributedTo, Date from, Date to, Map<String,String> fields) · findDataRecords(SalesDataSeries series, Set<BaseEntity> attributedTo, Date from, Date to) · findDataPoint(SalesDataSeries series, BaseEntity attributedTo, Date from, Date to, Map<String,String> fields) · newDataPoint() · createRandomTestData(SalesDataSeries series, BigDecimal avgAmount, Date startDate, Date endDate, long numRecords, OrgType orgType, Category skuCat) · findById(Long id) · findByName(String name) · productPrice(SalesDataRecord rec, String storeName) · productItemisedPrice(SalesDataRecord rec, String storeName) · getAppliesToOrgs(Profile p, List<Group> appliesToGroups) · processPointsAllocationForParticipant(SalesDataSeries series, BaseEntity participant) · submitPointsAllocationProcess() · submitPointsAllocationProcessForSeries(SalesDataSeries series) · findSalesType(String salesType) · findPointsSources(Reward promotion) · findPointsRules(Reward promotion) · validateExtraFieldName(String fieldName, Narrative validationMessage) · newDataSeriesExtraFieldBuilder() · newDataSeriesExtraFieldBuilderV2(SalesDataSeries series)

dryRunPreviewPath(SalesDataSeries series)

Returns: Path

Path of the series' own dry-run preview spreadsheet - a plain, mechanic-owned file that never touches the reward service or any persisted entity. Keyed on the series' name rather than its numeric id, since the path is visible to admins (e.g. in the "view preview" link) and the name is the user-meaningful identifier.

ParameterDescription
seriesa sales data series

hasDryRunPreview(SalesDataSeries series)

Returns: boolean

Checks whether the series' dry-run preview spreadsheet has actually been created, meaning at least one row has been recorded since it was last cleared.

ParameterDescription
seriesa sales data series

deleteDryRunPreview(SalesDataSeries series)

Returns: void

Permanently discards every row in the series' dry-run preview spreadsheet.

ParameterDescription
seriesthe sales data series to clear the dry-run preview for

createDryRunPreviewTable(SalesDataSeries series)

Returns: void

Creates the series' dry-run preview spreadsheet (header row only), if it doesn't already exist. Called once from the single-threaded root map task of a points-allocation scan (see PointsAllocationMapReduceProcessable), before any records are processed - potentially concurrently, on separate threads - so no two batches can race to create the table themselves and each write a header row.

ParameterDescription
seriesthe sales data series, which must be in dry-run mode

findDataSeriesContent(String seriesName)

Returns: DataSeriesContent

This finds any content configuration for the named data series. The returned object has information to control the presentation of fields and the series as a whole

ParameterDescription
seriesName- the name of the series to find content for

findByIds(Collection<Long> ids)

Returns: List<SalesDataRecord>

Looks up sales data records by id, batching the query in groups of 1000 to stay within database parameter limits.

ParameterDescription
idsthe record ids to look up; a null or empty collection returns an empty list

countUnprocessedSalesRecs()

Returns: long

Counts sales records across all series that have not yet had their reward points processed.

countUnprocessedSalesRecs(Date startDate, Date endDate)

Returns: long

Counts sales records across all series that have not yet had their reward points processed, restricted to a date range.

ParameterDescription
startDatethe earliest record date to include; may be null for no lower bound
endDatethe latest record date to include; may be null for no upper bound

findEntitiesWithUnprocessedRecs()

Returns: List<Long>

Finds the ids of entities (profiles or organisations) that have at least one unprocessed sales record in any series.

countPointsAllocationsWithErrors()

Returns: long

Counts points allocation records that recorded an error while processing, across the whole account with no date restriction.

findPointsAllocationsWithErrors(SearchProperties searchProperties)

Returns: List<PointsAllocation>

Finds points allocation records that recorded an error while processing.

ParameterDescription
searchPropertiespaging and sorting options to apply to the search

dataSeriesExtraFields(SalesDataSeries sds)

Returns: List<ExtraField>

Parses the custom extra fields configured on a series' fieldset into ExtraField objects.

ParameterDescription
sdsthe sales data series to read extra fields from; may be null, or have no fieldset, in which case an empty list is returned

resetPointsAllocations(List<SalesDataRecord> records, boolean deleteSales)

Returns: void

Resets all available reward points for the given sales records, optionally deleting the sales records themselves, then refreshes the points balance for every entity affected.

ParameterDescription
recordsthe sales records to reset; records with no rewards issued yet are skipped
deleteSalesif true, delete each sales record after resetting its rewards; if false, clear its rewards-issued date instead

resetPointsAllocations(SalesDataRecord rec, boolean deleteSale, boolean resetPointsBalance)

Returns: void

Resets a sales record's reward points, optionally deleting the sales record and optionally refreshing the points balance for entities affected.

ParameterDescription
recthe sales record to reset
deleteSaleif true, delete the sales record after resetting its rewards
resetPointsBalanceif true, refresh the points balance for every entity affected

resetPointsAllocations(SalesDataRecord rec, boolean deleteSale, boolean resetPointsBalance, boolean createDebitForUsedPoints)

Returns: void

Resets a sales record's reward points, optionally deleting the sales record, optionally refreshing the points balance for entities affected, and optionally creating a debit to claw back any points already used.

ParameterDescription
recthe sales record to reset
deleteSaleif true, delete the sales record after resetting its rewards
resetPointsBalanceif true, refresh the points balance for every entity affected
createDebitForUsedPointsif true, create a debit for any of the reset points that have already been used

resetPointsAllocations(SalesDataRecord rec)

Returns: void

Resets a sales record's reward points without deleting the record or refreshing the points balance.

ParameterDescription
recthe sales record to reset

resetSalesRecord(SalesDataRecord rec)

Returns: void

Resets a sales record's own rewards, and unwinds any record-matcher activity it is involved in, whether as one of the records a match consumed (SOURCE) or as a record a match generated (DEST). For every such match group, every OTHER destination record the group produced (ie not rec itself) has its own rewards reset and is then deleted, and the group itself is deleted. rec is only ever reset, never deleted, since callers are typically resetting the record whose detail page they are viewing. Only unwinds one level of matching - if a destination record deleted here was itself later consumed as a source by a further match, that further match is left untouched.

ParameterDescription
recthe sales record to reset

resetPointsAllocations(SalesDataRecord rec, boolean deleteSales)

Returns: void

Resets all available reward points for a sales record and deletes it; the points balance is not refreshed.

ParameterDescription
recthe sales record to reset and delete
deleteSalesif true, delete the sales record after resetting its rewards

resetListPointsAllocations(List<PointsAllocation> listPa, boolean deleteSales)

Returns: void

Resets a list of points allocations, optionally deleting their sales records, then refreshes the points balance for every entity affected.

ParameterDescription
listPathe points allocations to reset
deleteSalesif true, delete each allocation's sales record after resetting its rewards

resetPointsAllocation(PointsAllocation pa, boolean deleteSales, boolean resetPointsBalance)

Returns: void

Resets a single points allocation, optionally deleting its sales record, and optionally refreshing the points balance for the entities affected.

ParameterDescription
pathe points allocation to reset
deleteSalesif true, delete the allocation's sales record after resetting its rewards
resetPointsBalanceif true, refresh the points balance for every entity affected

resetPointsAllocation(PointsAllocation pa, boolean deleteSales)

Returns: void

Resets a single points allocation and optionally deletes its sales record, without refreshing the points balance.

ParameterDescription
pathe points allocation to reset
deleteSalesif true, delete the allocation's sales record after resetting its rewards

processPointsAllocation(SalesDataSeries series, Consumer<String> progressCallback)

Returns: void

Runs the full points allocation scan for a series: processes its record matchers, finds every sales record not yet allocated points, then processes each of the series' points allocation sources against them, refreshing the points balance for every entity affected once done (unless the series is in dry-run mode, in which case rows are written to the preview spreadsheet instead).

ParameterDescription
seriesthe sales data series to process
progressCallbackoptional callback invoked with human-readable progress messages; may be null

processPointsAllocation(PointsAllocationSource pas, List<SalesDataRecord> records, Consumer<String> progressCallback, Set<SalesDataRecord> processed)

Returns: void

Processes a single points allocation source against a list of sales records, without capturing which entities' points balances need refreshing afterwards.

ParameterDescription
pasthe points allocation source to process
recordsthe sales records to consider
progressCallbackoptional callback invoked with human-readable progress messages; may be null
processedrecords that were included and processed are added to this set

processPointsAllocation(PointsAllocationSource pas, List<SalesDataRecord> records, Consumer<String> progressCallback, Set<SalesDataRecord> processed, Map<Long,Set<Long>> entitiesRewards)

Returns: void

Processes a single points allocation source against a list of sales records - skipping deleted sources, sources tied to an inactive promotion, and sources with no reward configured. For each included record, awards or debits points individually, or (in SUM allocation mode) accumulates the amount per participant and awards or debits the total once all records have been considered.

ParameterDescription
pasthe points allocation source to process
recordsthe sales records to consider
progressCallbackoptional callback invoked with human-readable progress messages; may be null
processedrecords that were included and processed are added to this set
entitiesRewardsentity-id to reward-ids map that captures which entities' balances need refreshing afterwards; may be null

processSingleRecordPoints(SalesDataRecord r)

Returns: void

Processes reward points for a single sales record against every non-deleted points allocation source with a reward on its series, then refreshes the points balance for entities affected (unless the series is in dry-run mode). Does nothing if the record is null or already has a rewards-issued date.

ParameterDescription
rthe sales record to process

testPointsAllocation(PointsAllocationSource pas, SalesDataRecord r)

Returns: PointsAllocationResult

Calculates what a points allocation source would award or debit for a sales record, without persisting anything or logging detail messages.

ParameterDescription
pasthe points allocation source to test
rthe sales record to test against

testPointsAllocation(PointsAllocationSource pas, SalesDataRecord r, List<String> logs)

Returns: PointsAllocationResult

Calculates what a points allocation source would award or debit for a sales record, without persisting anything, capturing the log messages produced while evaluating the source's rules.

ParameterDescription
pasthe points allocation source to test
rthe sales record to test against
logslog messages produced while evaluating the source are appended here; may be null to skip capture

createPointsAllocationSource(String name, String title, SalesDataSeries series, Reward reward)

Returns: void

Creates a new points allocation source on a series, with the given reward.

ParameterDescription
namethe source's unique, path-safe name
titlethe source's display title
seriesthe sales data series to create the source on
rewardthe reward the source issues points against

findPointsAllocationSource(Long id)

Returns: PointsAllocationSource

Finds a points allocation source by id.

ParameterDescription
idthe points allocation source id

findPointsAllocation(Long id)

Returns: PointsAllocation

Finds a points allocation by id, for the current tenant.

ParameterDescription
idthe points allocation id

pointsAllocations(SalesDataRecord salesDataRecord)

Returns: List<PointsAllocation>

Finds all points allocations that were calculated from a sales record.

ParameterDescription
salesDataRecordthe sales record to find allocations for

updateSalesRecord(SalesDataRecord record, FormContext rc)

Returns: void

Updates a sales record's fields from posted form parameters and then refreshes its search index entry.

ParameterDescription
recordthe sales record to update
rcthe form context to bind the posted parameters from

salesRecordUpdated(SalesDataRecord sdr)

Returns: void

Deprecated. Use salesDataRecordUpdated instead. Call this after updating properties on a sales data record so it can update the search index.

ParameterDescription
sdrthe sales record that was updated

allocationType(String s)

Returns: AllocationType

Parses a points allocation source allocation-type name (e.g. "INDIVIDUAL", "SUM") into its enum value.

ParameterDescription
sthe allocation type name

newPointsAllocationSourceBuilder(SalesDataSeries series)

Returns: PointsAllocationSourceBuilder

Creates a new fluent builder for configuring and creating a points allocation source on a series.

ParameterDescription
seriesthe sales data series the new points allocation source will belong to

duplicatePointsAllocationSource(String name, String title, SalesDataSeries series, PointsAllocationSource fromPAS)

Returns: void

Creates a new points allocation source on a series by copying the configuration of an existing one.

ParameterDescription
namethe new source's unique, path-safe name
titlethe new source's display title
seriesthe sales data series to create the new source on
fromPASthe existing points allocation source to copy configuration from

calculateAllocationPoints(PointsAllocationSource pas, SalesDataRecord r)

Returns: PointsAllocationResult

Calculates the points a points allocation source would award or debit for a sales record - via a configured points rule type if one is set, otherwise via the source's MVEL expression, otherwise falling back to the record's raw amount.

ParameterDescription
pasthe points allocation source to calculate points for
rthe sales record to calculate against

calculateAllocationPoints(PointsAllocationSource pas, SalesDataRecord r, Formatter f)

Returns: PointsAllocationResult

Calculates the points a points allocation source would award or debit for a sales record, using the given formatter to evaluate the source's MVEL expression if one is configured.

ParameterDescription
pasthe points allocation source to calculate points for
rthe sales record to calculate against
fthe formatter used to evaluate the MVEL expression and coerce its result to a number

findPointsRecipient(SalesDataRecord rec, PointsAllocationSource source)

Returns: BaseEntity

Resolves the entity a points allocation source would issue points to or debit points from for a sales record - the record's salesBy entity if the source has no recipient expression configured, otherwise the profile or organisation the source's recipient KCode expression resolves to.

ParameterDescription
recthe sales record to resolve a recipient for
sourcethe points allocation source whose recipient rule is evaluated

isAllocationPointsIncluded(PointsAllocationSource pas, SalesDataRecord r)

Returns: boolean

Checks whether a sales record satisfies a points allocation source's inclusion rules - the connected promotion's status, date range and eligibility (if any), and then the source's configured points rule type or ignore expression.

ParameterDescription
pasthe points allocation source whose rules are evaluated
rthe sales record to check

findMatchingSources(SalesDataSeries series, SalesDataRecord r)

Returns: List<PointsAllocationSource>

Finds the non-deleted points allocation sources on a series whose inclusion rules match a sales record.

ParameterDescription
seriesthe sales data series whose points allocation sources are checked
rthe sales record to match against

sum(SalesDataSeries series, BaseEntity attributedTo, Date startDate, Date endDate)

Returns: BigDecimal

Sums a series' sales record amounts attributed to a single entity within a date range.

ParameterDescription
seriesthe sales data series to aggregate
attributedTothe entity to filter records by
startDatethe earliest record date to include; may be null for no lower bound
endDatethe latest record date to include; may be null for no upper bound

sum(SalesDataSeries series, Set<BaseEntity> attributedTo, Date startDate, Date endDate)

Returns: BigDecimal

Sums a series' sales record amounts attributed to any of a set of entities within a date range.

ParameterDescription
seriesthe sales data series to aggregate
attributedTothe entities to filter records by
startDatethe earliest record date to include; may be null for no lower bound
endDatethe latest record date to include; may be null for no upper bound

sumByOrg(SalesDataSeries series, Organisation attributedTo, Date startDate, Date endDate)

Returns: BigDecimal

Sums a series' sales record amounts attributed to a single organisation's sales team within a date range.

ParameterDescription
seriesthe sales data series to aggregate
attributedTothe organisation to filter records by
startDatethe earliest record date to include; may be null for no lower bound
endDatethe latest record date to include; may be null for no upper bound

average(SalesDataSeries series, BaseEntity attributedTo, Date startDate, Date endDate)

Returns: BigDecimal

Averages a series' sales record amounts attributed to a single entity within a date range.

ParameterDescription
seriesthe sales data series to aggregate
attributedTothe entity to filter records by
startDatethe earliest record date to include; may be null for no lower bound
endDatethe latest record date to include; may be null for no upper bound

count(SalesDataSeries series, BaseEntity attributedTo, Date startDate, Date endDate)

Returns: long

Counts a series' sales records attributed to a single entity within a date range.

ParameterDescription
seriesthe sales data series to count records in
attributedTothe entity to filter records by
startDatethe earliest record date to include; may be null for no lower bound
endDatethe latest record date to include; may be null for no upper bound

minimum(SalesDataSeries series, BaseEntity attributedTo, Date startDate, Date endDate)

Returns: BigDecimal

Finds the minimum sales record amount attributed to a single entity within a date range.

ParameterDescription
seriesthe sales data series to aggregate
attributedTothe entity to filter records by
startDatethe earliest record date to include; may be null for no lower bound
endDatethe latest record date to include; may be null for no upper bound

maximum(SalesDataSeries series, BaseEntity attributedTo, Date startDate, Date endDate)

Returns: BigDecimal

Finds the maximum sales record amount attributed to a single entity within a date range.

ParameterDescription
seriesthe sales data series to aggregate
attributedTothe entity to filter records by
startDatethe earliest record date to include; may be null for no lower bound
endDatethe latest record date to include; may be null for no upper bound

createSeries(String name, String title, Group salesByGroup)

Returns: SalesDataSeries

Creates a profile-attributed sales data series, with no website and no default aggregation type or auto-calculation.

ParameterDescription
namethe series' unique, path-safe name
titlethe series' display title
salesByGroupthe group whose members can log sales against the series

createSeries(String name, String title, Group salesByGroup, Website website, String defaultAgg, boolean autoCalculation)

Returns: SalesDataSeries

Creates a profile-attributed sales data series.

ParameterDescription
namethe series' unique, path-safe name
titlethe series' display title
salesByGroupthe group whose members can log sales against the series
websitethe website the series belongs to; may be null
defaultAggthe default aggregation type name (e.g. "SUM"); may be null or blank to leave unset
autoCalculationif true, the series automatically calculates points allocations for new records

createSeries(String name, String title, Group salesByGroup, Website website, String defaultAgg, boolean autoCalculation, SalesType salesType)

Returns: SalesDataSeries

Creates a sales data series, attributed to profiles or organisations depending on the given sales type.

ParameterDescription
namethe series' unique, path-safe name
titlethe series' display title
salesByGroupthe group whose members can log sales against the series
websitethe website the series belongs to; may be null
defaultAggthe default aggregation type name (e.g. "SUM"); may be null or blank to leave unset
autoCalculationif true, the series automatically calculates points allocations for new records
salesTypewhether the series is attributed to profiles or organisations

findAggregationType(String aggregationType)

Returns: AggregationType

Parses an aggregation type name (e.g. "sum", "AVERAGE") into its enum value, case-insensitively.

ParameterDescription
aggregationTypethe aggregation type name; may be null or blank

findSeriesByName(String name)

Returns: SalesDataSeries

Alias for dataSeries(String) - finds a sales data series by name.

ParameterDescription
namethe series' unique name

dataSeries(String name)

Returns: SalesDataSeries

Finds a sales data series by name, for the current tenant.

ParameterDescription
namethe series' unique name

getAllSeries()

Returns: List<SalesDataSeries>

Finds all sales data series for the current tenant.

getAllCategories()

Returns: List<SalesDataSeriesCategory>

Finds all sales data series categories for the current tenant.

findCategoryByName(String name)

Returns: SalesDataSeriesCategory

Finds a sales data series category by name, for the current tenant.

ParameterDescription
namethe category's unique name

createCategory(String name, String title)

Returns: SalesDataSeriesCategory

Creates a sales data series category for the current tenant.

ParameterDescription
namethe category's unique, path-safe name
titlethe category's display title

dataSeriesSalesType(String name)

Returns: SalesType

Parses a sales type name (e.g. "SALES_ORG", "SALES_PROFILE") into its enum value.

ParameterDescription
namethe sales type name

dataSeriesFrequency(String name)

Returns: Frequency

Parses a series frequency name into its enum value.

ParameterDescription
namethe frequency name

dataSeriesAggregationType(String name)

Returns: AggregationType

Parses an aggregation type name into its enum value.

ParameterDescription
namethe aggregation type name

isOrgSaleType(SalesDataSeries series)

Returns: boolean

Checks whether a series is organisation-attributed.

ParameterDescription
seriesthe sales data series to check

findRecord(long id)

Returns: SalesDataRecord

Finds a sales data record by id, for the current tenant.

ParameterDescription
idthe sales data record id

findRecords(SalesDataSeries series, Date from, Date to, String orderByField, Boolean asc)

Returns: List<SalesDataRecord>

Finds a series' sales records within a date range, sorted by the given field.

ParameterDescription
seriesthe sales data series to find records in
fromthe earliest record date to include; may be null for no lower bound
tothe latest record date to include; may be null for no upper bound
orderByFieldthe record field to sort by
asctrue to sort ascending, false to sort descending

findRecords(SalesDataSeries series, BaseEntity baseEntity, Date from, Date to)

Returns: List<SalesDataRecord>

Finds a series' sales records attributed to a single entity within a date range.

ParameterDescription
seriesthe sales data series to find records in
baseEntitythe entity to filter records by
fromthe earliest record date to include; may be null for no lower bound
tothe latest record date to include; may be null for no upper bound

findRecords(SalesDataSeries series, List<BaseEntity> baseEntities, Date from, Date to, String orderByField, Boolean asc)

Returns: List<SalesDataRecord>

Finds a series' sales records attributed to any of a list of entities within a date range, sorted by the given field.

ParameterDescription
seriesthe series to filter by
baseEntitiesthe list of entities to match on
fromthe earliest record date to include; may be null for no lower bound
tothe latest record date to include; may be null for no upper bound
orderByFieldthe record field to sort by
asctrue to sort ascending, false to sort descending

sumRecords(SalesDataSeries series, BaseEntity baseEntity, Date from, Date to)

Returns: BigDecimal

Sums a series' sales record amounts attributed to a single entity within a date range.

ParameterDescription
seriesthe sales data series to aggregate
baseEntitythe entity to filter records by
fromthe earliest record date to include; may be null for no lower bound
tothe latest record date to include; may be null for no upper bound

averageRecords(SalesDataSeries series, BaseEntity baseEntity, Date from, Date to)

Returns: BigDecimal

Averages a series' sales record amounts attributed to a single entity within a date range.

ParameterDescription
seriesthe sales data series to aggregate
baseEntitythe entity to filter records by
fromthe earliest record date to include; may be null for no lower bound
tothe latest record date to include; may be null for no upper bound

countRecords(SalesDataSeries series, BaseEntity baseEntity, Date from, Date to)

Returns: long

Counts a series' sales records attributed to a single entity within a date range.

ParameterDescription
seriesthe sales data series to count records in
baseEntitythe entity to filter records by
fromthe earliest record date to include; may be null for no lower bound
tothe latest record date to include; may be null for no upper bound

findEntityForSeries(SalesDataSeries series, Profile user)

Returns: BaseEntity

Calls findEntitiesForSeries and, if there is only one match, returns it. If there are multiple entities (i.e. the user is associated with multiple orgs for the series) then tries to match the currently selected team org, and returns that; otherwise defaults to returning the first entity found.

ParameterDescription
seriesthe sales data series to resolve an entity for
userthe user to resolve an entity for

findEntitiesForSeries(SalesDataSeries series, Profile user)

Returns: List<BaseEntity>

Finds the entities a user can log or view sales data for a series as - the user themselves for a profile-attributed series, or the organisations they hold a matching group membership in for an org-attributed series.

ParameterDescription
seriesthe sales data series to find entities for
userthe user to find entities for

toRecordBeans(List<SalesDataRecord> recs)

Returns: List<RecordBean>

Converts sales data records to their display bean form.

ParameterDescription
recsthe records to convert; may be null

insertDataPoint(DataPoint dp)

Returns: SalesDataRecord

Creates and persists a sales data record from a configured DataPoint, obtained from newDataPoint(). Fires the sales record created and updated events unless the data point was configured to suppress events.

ParameterDescription
dpthe configured data point to insert; must have a series, an attributedTo entity and an amount set

salesDataRecordUpdated(SalesDataRecord sdr)

Returns: void

Call this after updating a sales record's properties to persist it, update its search index entry and fire the sales-data and indexed-item-updated events.

ParameterDescription
sdrthe sales record that was updated

deleteRecord(SalesDataRecord sdr)

Returns: void

Deletes a sales data record and fires the sales-data and indexed-item-updated events.

ParameterDescription
sdrthe sales record to delete

findDataRecords(SalesDataSeries series, BaseEntity attributedTo, Date from, Date to, Map<String,String> fields)

Returns: List<SalesDataRecord>

Finds a series' sales records attributed to a single entity within a date range, additionally matching the given extra field values.

ParameterDescription
seriesthe sales data series to find records in
attributedTothe entity to filter records by
fromthe earliest record date to include; may be null for no lower bound
tothe latest record date to include; may be null for no upper bound
fieldsextra field name/value pairs the record must match

findDataRecords(SalesDataSeries series, Set<BaseEntity> attributedTo, Date from, Date to)

Returns: List<SalesDataRecord>

Finds a series' sales records attributed to any of a set of entities within a date range.

ParameterDescription
seriesthe sales data series to find records in
attributedTothe entities to filter records by
fromthe earliest record date to include; may be null for no lower bound
tothe latest record date to include; may be null for no upper bound

findDataPoint(SalesDataSeries series, BaseEntity attributedTo, Date from, Date to, Map<String,String> fields)

Returns: SalesDataRecord

Finds the first (date-wise) sales record matching the given criteria.

ParameterDescription
seriesthe sales data series to find a record in
attributedTothe entity to filter records by
fromthe earliest record date to include; may be null for no lower bound
tothe latest record date to include; may be null for no upper bound
fieldsextra field name/value pairs the record must match

newDataPoint()

Returns: DataPoint

Creates a new, unattached DataPoint builder; configure it and call save() (or pass it to insertDataPoint) to create the sales data record.

createRandomTestData(SalesDataSeries series, BigDecimal avgAmount, Date startDate, Date endDate, long numRecords, OrgType orgType, Category skuCat)

Returns: long

Creates random test data for the given series, using the current Hibernate session.

ParameterDescription
seriesthe series to generate records for
avgAmountthe average record amount; individual record amounts are randomised around this average
startDatethe earliest date a generated record's period may fall on
endDatethe latest date a generated record's period may fall on
numRecordsthe number of records to create; values of zero or less create nothing
orgTypewhen the series is org-attributed, restricts new/found participants to this org type; may be null
skuCatwhen set, records are randomly attributed a SKU from products in this category; may be null

findById(Long id)

Returns: SalesDataSeries

Finds a sales data series by id, for the current tenant.

ParameterDescription
idthe series id; may be null

findByName(String name)

Returns: SalesDataSeries

Alias for dataSeries(String) - finds a sales data series by name.

ParameterDescription
namethe series' unique name

productPrice(SalesDataRecord rec, String storeName)

Returns: BigDecimal

Calculates the final unit price of a sales record's product SKU in a given store. Passes the record's salesBy property as the purchaser to the pricing manager, so this is not appropriate for team/org based calculations.

ParameterDescription
recthe sales record whose product SKU is priced
storeNamethe name of the store to price against

productItemisedPrice(SalesDataRecord rec, String storeName)

Returns: ItemisedPrice

Calculates the itemised unit price of a sales record's product SKU in a given store, for the record's salesBy entity as purchaser.

ParameterDescription
recthe sales record whose product SKU is priced
storeNamethe name of the store to price against

getAppliesToOrgs(Profile p, List<Group> appliesToGroups)

Returns: Set<Organisation>

Finds the organisations a profile holds a matching group membership in for every one of a list of groups.

ParameterDescription
pthe profile to check memberships for
appliesToGroupsthe groups the profile must hold a membership in, all within the same organisation

processPointsAllocationForParticipant(SalesDataSeries series, BaseEntity participant)

Returns: void

Runs the points allocation scan for a single participant of a series: processes their record matchers, finds their sales records not yet allocated points, then processes each of the series' points allocation sources against them, refreshing their points balance once done (unless the series is in dry-run mode).

ParameterDescription
seriesthe sales data series to process
participantthe entity to process points allocation for

submitPointsAllocationProcess()

Returns: void

Enqueues a background map/reduce task to process points allocation for every series' unprocessed sales records.

submitPointsAllocationProcessForSeries(SalesDataSeries series)

Returns: void

Enqueues a background map/reduce task to process points allocation for a single series' unprocessed sales records.

ParameterDescription
seriesthe sales data series to process

findSalesType(String salesType)

Returns: SalesType

Parses a sales type name into its enum value.

ParameterDescription
salesTypethe sales type name

findPointsSources(Reward promotion)

Returns: List<PointsAllocationSource>

Finds the points allocation sources connected to a promotion.

ParameterDescription
promotionthe promotion to find points allocation sources for

findPointsRules(Reward promotion)

Returns: List<PointsAllocationRule>

Finds the points allocation rules connected to a promotion.

ParameterDescription
promotionthe promotion to find points allocation rules for

validateExtraFieldName(String fieldName, Narrative validationMessage)

Returns: boolean

Validates a proposed extra field name, appending a reason to validationMessage if it is invalid.

ParameterDescription
fieldNamethe proposed extra field name
validationMessagea validation reason is appended here if the name is invalid

newDataSeriesExtraFieldBuilder()

Returns: DataSeriesExtraFieldBuilder

Creates a new fluent builder for adding a single extra field to a sales data series.

newDataSeriesExtraFieldBuilderV2(SalesDataSeries series)

Returns: DataSeriesExtraFieldBuilderV2

Creates a new builder for adding multiple extra fields to a sales data series in one fieldset update.

ParameterDescription
seriesthe sales data series to add extra fields to
To get full access to the Kademi Hub existing customers can login here, or new customers can register here.