Interface PayoutRecordManager


public interface PayoutRecordManager
API that can be accessed via the 'payoutRecords' binding (available in the RebateRecord calculation context — i.e., when calculating a RebateRecord in a RebateRecordCalculation task), or via the 'accrualRecords' binding (available in the CompensationRecord calculation context).

Example (payoutRecords):


 def rr = rebateRecords.get("Q1")               // api.currentItem()
 for (def i=0; i < 100000; i++) {
                payoutRecords.add("Accrual", "Q1-"+i, [attribute1: rr?.attribute1, attribute2: rr?.attribute2, attribute3: rr?.attribute3] )
                payoutRecords.add("Summary", "Q1-"+i, [attribute1: rr?.attribute1, attribute2: rr?.attribute2, attribute3: rr?.attribute3] )
 }
 
Payment records managed through this API are always associated with the current RebateRecord or, for accrualRecords, the current CompensationRecord.

Example (accrualRecords):


          if (api.isInputGenerationExecution()) return

          def cor = api.currentItem()
          def compensationId = cor?.uniqueName
          def compensationRecordId = cor?.sourceId

          accrualRecords.add("Accrual", compensationId+"-"+compensationRecordId, [attribute1: "A"] )
          accrualRecords.add("Summary", compensationId+"-"+compensationRecordId)
 

A type and a name identify each record of the current Rebate Record or Compensation Record. The logic creates, updates and deletes these records. Pricefx does not create them.

When the logic adds or updates a record, the record gets the start date, end date and payout date of the current record, unless the map sets them.

In a test run of the logic, the methods that add, update or delete records do nothing. No record is saved. The same applies to input generation.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(String type, String name, Map<?,?>... attributeValues)
    Adds a new PayoutRecord or AccrualRecord, specified by the type and name.
    void
    addOrUpdate(String type, String name, Map<?,?>... attributeValues)
    The convenience method, adds a PayoutRecord/AccrualRecord if no record with the given type and name exists.
    void
    Switches to the bulk-load mode.
    int
    delete(Filter... filters)
    Deletes PayoutRecords/AccrualRecords linked to the current RebateRecord/CompensationRecord that match one or more optional Filter criteria.
    Collection<CompensationAgreementPayoutRecord>
    find(Filter... filters)
    Retrieves PayoutRecords or AccrualRecords linked to the current RebateRecord/CompensationRecord that match one or more optional Filter criteria.
    void
    To be called when all records have been created and/or updated.
    CompensationAgreementPayoutRecord
    get(String type, String name)
    Retrieves the existing payout or accrual record with the given type and name, linked to the current RebateRecord/CompensationRecord.
    void
    update(String type, String name, Map<?,?>... attributeValues)
    Updates the existing PayoutRecord or AccrualRecord specified by the given type and name.
  • Method Details

    • get

      CompensationAgreementPayoutRecord get(String type, String name)
      Retrieves the existing payout or accrual record with the given type and name, linked to the current RebateRecord/CompensationRecord.

      Example:

      
       def accrual = payoutRecords.get("Accrual", "Q1-Store042")
       def amount = accrual?.attribute2
       
      Parameters:
      type - The type of the record.
      name - The name of the record.
      Returns:
      The payout or accrual record converted to its map representation, or null if no record has this type and name.
    • add

      void add(String type, String name, Map<?,?>... attributeValues) throws PersistenceServiceException
      Adds a new PayoutRecord or AccrualRecord, specified by the type and name.

      In the regular mode, the record must not exist yet. To change a record that may exist, use addOrUpdate(String, String, Map[]).

      Example:

      
       def rr = api.currentItem()
       payoutRecords.add("Payout", "${rr.uniqueName}-Store042", [
               payoutDate: rr.payoutDate,
               attribute1: "Store042",
               attribute2: 1250.0,
       ])
       
      Parameters:
      type - A free-text type of the record. While it can be freely set, the usual patterns is that there are few different payment record types.
      name - A free-text name of the record. Unique within the (RebateRecord/CompensationRecord,type) namespace.
      attributeValues - Maps of field names to values, for example [attribute1: "ABC"]. The fields can be built-in fields, such as payoutDate or status, and attribute1 to attribute100.
      Throws:
      PersistenceServiceException - In the regular mode, when a PayoutRecord.attribute cannot be set to the given value
    • update

      void update(String type, String name, Map<?,?>... attributeValues) throws PersistenceServiceException
      Updates the existing PayoutRecord or AccrualRecord specified by the given type and name. In the bulk-load mode, the method adds the record if it does not exist.

      Example:

      
       payoutRecords.update("Accrual", "Q1-Store042", [status: "Approved"])
       
      Parameters:
      type - A free-text type of the record. While it can be freely set, the usual patterns is that there are few different payment record types.
      name - A free-text name of the record you want to update.
      attributeValues - Attribute to value map (ex. {attribute1: "ABC", ...}). If an attribute is to be set to null, it needs to be included in the map as such.
      Throws:
      PersistenceServiceException - In the regular mode, when a PayoutRecord.attribute cannot be set to the given value
      IllegalArgumentException - In the regular mode, if no record with this type and name exists.
    • addOrUpdate

      void addOrUpdate(String type, String name, Map<?,?>... attributeValues) throws PersistenceServiceException
      The convenience method, adds a PayoutRecord/AccrualRecord if no record with the given type and name exists. Performs an update if the record with the given type and name already exists. Important note: in the bulk-load mode, there is no advantage from calling the addOrUpdate method because the bulk-load always performs an insert (for a new record) or replace (for an existing record), regardless of whether the record was added with add() or addOrUpdate().

      Example:

      
       payoutRecords.addOrUpdate("Summary", "Total", [attribute1: api.currentItem().attribute3])
       
      Parameters:
      type - A free-text type of the record. While it can be freely set, the usual patterns is that there are few different payment record types.
      name - A free-text name of the record.
      attributeValues - Attribute to value map (ex. {attribute1: "ABC", ...}). If an attribute is to be set to null, it needs to be included in the map as such.
      Throws:
      PersistenceServiceException - In the regular mode, when a PayoutRecord.attribute cannot be set to the given value
    • find

      Collection<CompensationAgreementPayoutRecord> find(Filter... filters)
      Retrieves PayoutRecords or AccrualRecords linked to the current RebateRecord/CompensationRecord that match one or more optional Filter criteria.
      Parameters:
      filters - Optional Filter criteria.
      Returns:
      Collection of PayoutRecords/AccrualRecords matching the above conditions, each in its map representation.
    • delete

      int delete(Filter... filters)
      Deletes PayoutRecords/AccrualRecords linked to the current RebateRecord/CompensationRecord that match one or more optional Filter criteria.

      Call it without a filter before you add the records again, when a recalculation can produce a different set of records.

      Example:

      
       payoutRecords.delete(Filter.equal("type", "Summary"))
       
      Parameters:
      filters - The Filter criteria that the records must match. Without a filter, the method deletes all records of the current Rebate Record or Compensation Record.
      Returns:
      The number of actually deleted records.
    • bulkLoadMode

      void bulkLoadMode()
      Switches to the bulk-load mode. It is recommended to use the bulk-load mode when the volume of records to be added or updated exceeds 100k (in regular mode, 100k records are created in around 10min).
      Important note: When existing records are bulk-loaded, the original records are fully overwritten. This is different from the regular mode where only the specified attributes/value pairs are updated. In both modes, the start date, end date and payout date are refreshed from the current record unless the map sets them.

      The switch is one-way: the logic cannot return to the regular mode. Records added or updated in the regular mode before the switch are saved first. In the bulk-load mode, call flush() after the last record.

      Example:

      
       def stores = ["Store041", "Store042"]
       payoutRecords.bulkLoadMode()
       stores.each { store ->
           payoutRecords.add("Accrual", store, [attribute1: store])
       }
       payoutRecords.flush()
       
    • flush

      void flush()
      To be called when all records have been created and/or updated. If skipped the more recent additions and updates will not be persisted in the database.

      This applies to the bulk-load mode (see bulkLoadMode()). In the regular mode, Pricefx saves the records when it commits the calculation, so a call is optional.