Skip to content

Using accumulator with a custom function #503

@adeojo

Description

@adeojo

I have the following custom function

(defn calculate-trading-dates
  [effective-date terminate-date billing-dates ]
  (let [effective-date-to-use (if (.isBefore effective-date (.getStartOfMonth billing-dates))
                                (.getStartOfMonth billing-dates)
                                effective-date)
        terminate-date-to-use (if (nil? terminate-date)
                                (.getEndOfMonth billing-dates)
                                terminate-date)
        numerator (double (.getNumberOfTradingDates billing-dates effective-date-to-use terminate-date-to-use true))
        denominator (double (.getNumberOfTradingDates billing-dates))
        final-value (/ numerator denominator)]
    final-value))

The above function is used in a rule as below

(defrule my-rule
    "Sample Rule"
  
    [?billingDates <- BillingDates]
    [?sumCalcTradingDates <- (acc/sum #((calculate-trading-dates (.getEffectiveDate %) (.getTerminateDate %) ?billingDates ) % )) :from [DlpFirm
                                                                                                                               (= mpid ?accountId)
                                                                                                                               (= portId "PrimaryDLP")
                                                                                                                               (= ?effectiveDate effectiveDate )
                                                                                                                               (= ?terminateDate terminateDate )]]
  
    [:test (>= (.doubleValue ?sumCalcTradingDates) 25) ]
  

  
    =>
    (when (true? (get (.getFlags ?item) "baseChargeApplied"))
      (insert! (Map/of "$transactionalBillingChargeWriter" (TransactionalBillingCharge. ^EquityTransactionalBillableItem ?item (.getChargeTypeDTO ?charge-types "ABC100"))))
 ))     

When I test the above rule, I get the error:

    Unable to resolve symbol: ?billingDates in this context

FYI :The DLPFirm POJO does not have BillingDates

Any ideas how I can use the the function with an accumulator ?

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions