Script blocks and other
AlchemerScriptClosure
This integration allows you to push records into Alchemer in order to add them to a survey. Create one integration
per survey you want to send and then use this scripting block:
alchemer {
contact myContact
template myTemplate
reply "info@acme.com"
}
Use the name option if you have more than one Alchemer integration and you want to push to only one.
alchemer {
name "name of integration"
contact myContact
template myTemplate
reply "info@acme.com"
}
AzureStorageScriptClosure
Use this script block to easily send documents into the Azure Storage Blob service. Note that this has nothing to do with the onCourse document storage system and simply stores the blob in the Azure service without tracking it.
def transactions = query {
entity "AccountTransaction"
query "createdOn is today"
}
def bytes = export {
template "ish.onCourse.accountTransactionMYOB.csv"
records transactions
}
azurestorage {
name "integration name"
blob bytes
fileName "transactions.csv"
}
If you pass the DocumentParam object as the blob attribute, you can skip the name.
azurestorage {
name "integration name"
blob fileData
}
CanvasExpireScriptClosure
This automation component will iterate through all currently unsuspended users in Canvas and match their
enrolments to enrolments in onCourse.Suspend the Canvas user if all their enrolments have completed.
canvas_expire { }
By default the enrolment will be deemed to have ended when the class is complete. If you want to specify a
different end date you can do that with a simple expression like this:
canvas_expire {
ends "enrolment.customFieldEndDate"
}
Or with an expression like this:
canvas_expire {
ends "enrolment.courseClass.endDateTime + 10"
}
CanvasScriptClosure
This integration allows you to link onCourse to the Canvas LMS.
Add enrolments to Enrolments automatically as they are enrolled in onCourse.
canvas {
enrolment e
course_code "My-Canvas-Course"
section_code "key." + e.courseClass.uniqueCode
create_section true
create_student true
}
You can specify:
- create_section: create a new Canvas section from the equivalent onCourse Class if one does not already exist
inside your Canvas instance. - create_student: create a new Canvas User profile for the enrolled student if one does not exist in your Canvas
instance. If this is false and the user does not exist in Canvas then nothing will happen.
Additional options are available:
canvas {
enrolment e
course_code "My-Canvas-Course"
section_code "key." + e.courseClass.uniqueCode
create_section true
create_student true
authentication_provider_id 1
create_password "myCustomField"
course_blueprint "ABC"
add_tutors true
}
- authentication_provider_id: this sets the auth provider in Canvas to a non standard value
- create_password: will generate random password for studento canvas and save to your nominated customField of the
onCourse student. Be aware this is not secure since the password is not encrypted in onCourse, however it can be
useful for supporting students who need help logging in, or if you want to send the student their login details
from inside onCourse. - course_blueprint: if the course does not already exist in Canvas with the code provided, will create a new course
from the blueprint specified. - add_tutors: will enrol tutors from the enrolment's class into the Canvas course as teachers.
Additional data can be sent to Canvas like this:
def student = [
user: [
name: "David Smith",
time_zone: "Hawaii"
],
communication_channel: [
skip_confirmation: true
],
enable_sis_reactivation: true
]
canvas {
enrolment e
course_code "My-Canvas-Course"
section_code "key." + e.courseClass.uniqueCode
create_section true
create_student true
student_attributes student
}
Consult the Cnavas manual for the fields you can send through to Canvas and how to use them. You can set any student/user attributes in Canvas.
CoassembleScriptClosure
Integration allows us to establish interaction between Coassemble (previously called E-coach) and onCourse enrol system.
Add enrolments to Enrolments automatically as they are enrolled in onCourse.
ecoach {
enrolment record
}
Use the name option if you have more than one coassemble integration and you want to push to only one.
ecoach {
name "name of integration"
enrolment record
}
CollegePreferenceService
Service for accessing college preferences.
get(prefName, defaultValue)
-
prefName: String name of preference @param defaultValue default value @return preference value if it is not null, otherwise returns default value
-
defaultValue: Object default value @return preference value if it is not null, otherwise returns default value
-
Returns: Object preference value if it is not null, otherwise returns default value
get(prefName)
-
prefName: String name of preference @return preference value if it is not null, otherwise returns empty string.
-
Returns: Object preference value if it is not null, otherwise returns empty string.
hasSurveyForm()
Check if default survey form foor enrolled students configured for ncourse.
See ish.email.enrolmentConfirmation email template
- Returns: boolean Documentation not yet available
CsvBuilder
This class is a simple wrapper to make exporting CSV and other formats really easy.
Use it like this within an export script:
csv << [
"first name": contact.firstName
"last name": contact.lastName
"student number": contact.student.studentNumber
]
If you want to change the delimiters, quote or end of line, you should do that before you call csv << []
Note that this builder is really flexible and isn't just for CSV. Use it for any output with consistent
separators between fields.
addRow(row)
Appends new row to builder's output. Instead of calling this method by name,
you can use the symbol "<<" as seen in the example above.
If you call this more than once, the header is automatically disabled for the second
and subsequent calls.
- row: Map mapping of column names to values
enableHeader(writeHeader)
Use this to disable the header line
csv.enableHeader = false
- writeHeader: boolean defaults to true @return
setDelimiter(delimiter)
Set the delimiter to something else.
csv.delimiter = ';'
- delimiter: int defaults to ,
setEndOfLine(endOfLine)
Set the end of line to something else.
csv.endOfLine = '\n'
- endOfLine: String defaults to a \r\n
setQuote(quote)
Set the quote to something else.
csv.quote = '|'
- quote: char defaults to a "
DocumentService
This class contains simple image closure which allow to put any images from document management system to email template.
The syntax is
${image 'picture_1'}.
'picture_1' is name of document in onCourse system.
If onCourse have more than one document with the same name then the first one will be chosen.
Make sure that required image has unique name to prevent such collision.
The image closure interpreted into simple img html tag like:
Document script block
Document creation API.
Simple usage example:
output = report {
records someList
keyCode ish.classReport
background myFile
}
d = document {
action "create"
content output
name "myreport"
mimeType "image/pdf"
permission AttachmentInfoVisibility.PUBLIC
attach tutor_1, tutor_1
}
Or just attach existing document to any attachable records
document {
action "attach"
document d
attach tutor_1, enrolment_1, certificate_1
}
action(action)
Create new document or attach existing document
- action: String list action string
attach(attach)
- attach: AttachableTrait existing records to attach a document
content(content)
- content: byte[] for newly created document
content(documentParam)
- documentParam: DocumentParam Documentation not yet available
document(document)
- document: Document existing document record to attach
mimeType(mimeType)
- mimeType: String for newly created document
name(name)
- name: String for newly created document
permission(permission)
- permission: AttachmentInfoVisibility for newly created document
Export script block
Use a script to generate an export.
Usage example:
export {
fileName "export.csv"
template "ish.contact.list"
record overdueDebtors
}
fileName(fileName)
Specify the filename with extension of the final file with a fulfilled export
- fileName: String fileName of the file with the export
record(records)
A list of records to export.
This is the same as 'records', but this needs to handling a export card which is added in Script API
-
records: List
-
Returns: def Documentation not yet available
record(record)
You can also pass one record to export.
-
record: Object
-
Returns: def Documentation not yet available
records(records)
A list of records to export. Obviously the export template needs to be
built to accept a list of this type of object and produce an export file from them.
-
records: List
-
Returns: def Documentation not yet available
records(records)
You can instead pass records as vargs if you only have a few to pass.
-
records: Object
-
Returns: def Documentation not yet available
template(templateKeyCode)
Pass the keycode of the export template you want to use
-
templateKeyCode: String Documentation not yet available
-
Returns: def Documentation not yet available
KronosCreateEditScriptClosure
Add TutorAttendances to Kronos Shift automatically as it is created/edited in onCourse.
Fields mapping from onCourse to Kronos:
Schedule name >> "Ish Schedules"
Date >> session date
Start Time >> session tutor rostered start time
End Time >> session tutor rostered end time
Employee ID >> tutor.payrollRef
Cost Center 0 >> First 3 digits of courseClass.incomeAccount
Cost Center 2 >> courseClassTutor.definedTutorRole.description
Skill >> courseClassTutor.definedTutorRole.name
Shift Note >> courseClasscode
kronosCreateEdit {
scheduleName "Weekly Test Schedule"
session record
}
scheduleName: add Shifts to Kronos Schedules with name 'scheduleName'. Kronos should have a Schedule with this name
and period on the date from the TutorAttendance
KronosDeleteScriptClosure
Delete TutorAttendances as Shift from Kronos automatically as it is deleted in onCourse.
kronosDelete {
session record
}
Get Schedule Id and Shift Id from TutorAttendance custom fields then call DELETE request with these ids,
that delete Shift from Kronos
KronosDeleteWrongCustomFieldClosure
Delete TutorAttendance Custom Fields for deleted Kronos Schedules.
kronosDeleteWrongCustomFields {
}
Get all TutorAttendances with CustomFields 'shiftIdCustomField' and 'scheduleIdCustomField' then check if one of its is null
or do a GET request to understand if Schedule is exist.
LearnDashScriptClosure
Export successful enrolment record to LearnDash system. This action will search for students matching the onCourse
email address against the LearnDash username, and creates them if not found.
That student will be enrolled in the Learndash course with slug matching the course code in onCourse
learndash {
action "enrol"
course enrolment.courseClass.course.code
student enrolment.student
}
MailchimpScriptClosure
Mailchimp integration groovy script API. Allows to subscribe/unsubscribe contact to/from Mailchimp list.
You can use 'subscribe' action for updating contacts in MailChimp.
'Unsubscribe' deletes permanently contact from the list.
Usage examples:
Subscribe person to Mailchimp list using onCourse contact record:
mailchimp {
name "List1"
action "subscribe"
contact enrolment.student.contact
}
Name property here is the name of Mailchimp integration which should be created in onCourse beforehand.
If the name isn't specified, script will execute it for all created 'MailChimp' integrations.
Subscribe person without onCourse contact record to Mailchimp list:
mailchimp {
name "List2"
action "subscribe"
email "student@example.com"
firstName "John"
lastName "Doe"
optIn false
}
Unsubscribe person from Mailchimp list:
mailchimp {
name "List1"
action "unsubscribe"
email "student@example.com"
}
The ability to create Mailchimp tags:
mailchimp {
action "subscribe"
contact enrolment.student.contact
tags enrolment.student.contact.tags
}
or any list of string
mailchimp {
action "subscribe"
contact enrolment.student.contact
tags 'art', 'IT', 'prhotoshop'
}
Pull unsubscribers and mark the email address in onCourse as not allowed for marketing. Since param support both: LocalDate or string literal.
mailchimp {
action "pull unsubscribes"
since "2020-09-04"
}
Don't pass 'since' param to get all unsubscribes
mailchimp {
action "pull unsubscribes"
}
Delete a user permanently from MailChimp by email, after this the user can be added again
mailchimp {
action "delete permanently"
email "student@example.com"
}
action(action)
Set Mailchimp list action: "subscribe" or "unsubscribe" or "pull unsubscribes".
- action: String list action string, can be one of "subscribe" or "unsubscribe" or "pull unsubscribes"
contact(contact)
Specify contact to take subscriber's email, first and last name from.
- contact: Contact subscriber contact
email(email)
Set subscriber's email.
- email: String subscriber's email
firstName(firstName)
Set subscriber's first name.
- firstName: String first name of the subscriber
lastName(lastName)
Set subscriber's last name.
- lastName: String last name of the subscriber
optIn(optIn)
A flag used to specify if a user must confirm via email before they are subscribed to a mailing list
'true' as default
- optIn: boolean for confirm email
postcode(postcode)
Set subscriber's postcode.
- postcode: String of the subscriber
since(since)
Pull all unsubscribers since certain timestamp
- since: String date time
since(since)
Pull all unsubscribers since certain timestamp
- since: LocalDate date time
tags(tags)
The ability to create Mailchimp tags. You can pass any list of tags to the integration.
If you want to map those in some way first, you can do that in the script you write.
- tags: List of Tag list
tags(tags)
The ability to create Mailchimp tags. You can pass any list of strings to the integration.
If you want to map those in some way first, you can do that in the script you write.
- tags: String list
Mask
For each access key, a role may be given certain access levels. This class is not an enum because
the values here can be added up to give layers of access. For example, VIEW (1) + EDIT (5) = 6.
Message script block
Message sending API. Allows to create email or SMS.
You can render email content from the templates which are stored into onCourse or a text string.
The recipients are generated from entity records which are specified in closure.
But you also can specify emails which will receive message with attachment or custom content.
If there is no attachment and specify template identifier and entity records, the message is stored inside the onCourse database.
Otherwise, no.
Simple usage example:
message {
template keyCodeOfMessageTemplate
record records
from "admin@example.com"
}
The above example will render the template with the specified keyCode and will pass the entity records to that template.
It will send that message to the contacts which will be get from the records.
You can optionally also pass a from address if you don't want to use the default email.from preference.
message {
template keyCodeOfMessageTemplate
record records
anyBinding_1 anyValue_1
anyBinding_2 anyValue_2
}
If the template has a variables they must be specified as a list of variables.
You can send emails with an attached file or pass your own content of message, without storing this data inside onCourse.
Usage example:
erolments = query {
entity "Enrolment"
query "status is SUCCESS "
}
def enrolments_pdf = report {
keycode "ish.onCourse.enrolmentConfirmation"
records erolments
}
def enrolments_csv = export {
template "ish.onCourse.enrolment.csv"
records erolments
}
def enrolments_xml = export {
template "ish.onCourse.enrolment.xml"
records erolments
}
def enrolments_file = new File("enrolments.txt")
erolments.each { e->
enrolments_file.append(e.student.fullName +'_'+ e.courseClass.uniqueCode +'\n')
}
message {
to "support@example.com"
cc "ccrecipient@example.com"
bcc "bccrecipient@example.com"
from "support@@example.com", "onCourse Support"
subject "Attachment example"
content "Look at attached files"
attachment "enrolments.pdf", "application/pdf", enrolments_pdf
attachment "enrolments.csv", "text/csv", enrolments_csv
attachment "enrolments.xml", "text/xml", enrolments_xml
attachment "text/plain", enrolments_file
}
message {
from "admin@example.com"
to "torecipient@example.com"
cc "ccrecipient@example.com"
bcc "bccrecipient@example.com"
subject "test email"
content "test email content"
attachment "accounts.csv", "text/csv", account_csv_data
}
The only lines which are required are "to", "subject" and "content" or "record", "template" and "bindings"
Message collision functionality. Allows to skip sending messages automatically if contact have already received message with specified key.
Usage example:
message {
template keyCodeOfMessageTemplate
record records
key "ABC", records
keyCollision "drop"
}
attachment(documentParam)
Add a documentParam as attachment to the email.
Using this method means that the message is not stored inside onCourse.
- documentParam: DocumentParam as DocumentParam
attachment(file)
Add a file as attachment to the email.
Using this method means that the message is not stored inside onCourse.
- file: File as File
attachment(contentType, content)
Add attachment to the email.
Using this method means that the message is not stored inside onCourse.
- contentType: String MIME type of the attachment @param content MIME type of the attachment
- content: Object Documentation not yet available
attachment(fileName, contentType, content)
Add attachment to the email.
Using this method means that the message is not stored inside onCourse.
- fileName: String attached file name which will appear in the email @param contentType MIME type of the attachment @param content attachment object
- contentType: String MIME type of the attachment @param content attachment object
- content: Object Documentation not yet available
attachment(attachment)
Add attachment to the email.
Using this method means that the message is not stored inside onCourse.
- attachment: Map of String, Object attachment properties map, e.g. [fileName: 'example.txt', type: 'text/plain', content: 'test text']
bcc(recipients)
Set BCC recipients emails for the message.
Using this method means that the message is not stored inside onCourse.
- recipients: String email address of the BCC recipients
cc(recipients)
Set CC recipients emails for the message.
Using this method means that the message is not stored inside onCourse.
- recipients: String email addresses of the CC recipients
content(content)
Set plain text content of the email.
Could be used only for SMTP email sending
Using this method means that the message is not stored inside onCourse.
- content: String plain text content of the email
createdBy(user)
Specify SystemUser who will be the linked to the resulting Message record in onCourse as its creator.
- user: SystemUser user who created the email
from(email)
Set "from" address for the email. Defaults to "email.from" preference if not set.
- email: String email from address
from(email, name)
Set "from" address for the email and name of the sender.
- email: String email from address @param name name of the sender
- name: String name of the sender
key(key, object)
Attach a string key to this message and link it to an object. This reference can be used to ensure duplicates
aren't sent for the same event.
- key: String a string key which identifies the script or event which creates this message @param object key is attached to a specific object (for example an enrolment or student)
- object: PersistentObject key is attached to a specific object (for example an enrolment or student)
keyCollision(collision)
Defines a rule to prevent duplicates being sent.
- collision: String check type. Can be 'accept' (this is the default and means the key is ignored), 'drop' (which will silently drop the message) and 'error' (which will drop the message and log an error to the audit log).
record(record)
A direct entity record to message.
- record: Object
record(records)
A list of records to message. Obviously the message template needs to be
built to accept a list of this type of object and produce a message from them.
- records: List
records(records)
A list of records to message. Obviously the message template needs to be
built to accept a list of this type of object and produce a message from them.
- records: List
subject(subject)
Set email subject.
Using this method means that the message is not stored inside onCourse.
- subject: String email subject
template(templateIdentifier)
Set message template to be used for rendering message body.
Could be used for Email and SMS sending
- templateIdentifier: String keyCode of the message template or name of the legacy message template
to(recipients)
Specify extra contacts which will receive email. By default email specified in contact record will be used,
however you can override the default email by using ">>" operator, e.g. contact1 >> "anotheremail@example.com"
Using this method means that the message is not stored inside onCourse.
- recipients: Contact contact records who will receive the email
to(recipients)
Specify extra emails which will receive email.
Using this method means that the message is not stored inside onCourse.
- recipients: String email addresses of the email recipients
MicropowerScriptClosure
Retrieves new and recently changed profiles from Micropower and adds them to onCourse. Automatically creates
memeberships and invoices for the specifiec MemberProduct sku
micropower {
name "Micropower"
}
Money
The Money
class provides a convenient way to work with monetary values,
ensuring accuracy and consistency in financial calculations.
This class supports standard ISO 4217 currency codes and handles rounding rules appropriately, making it suitable for various financial applications.
Key Features
- Automatically sets up the monetary currency according to your settings in the Financial section.
- Ensures accurate rounding of monetary values.
- Provides easy-to-use arithmetic operations.
Creating a Money Instance
To create a new monetary value, we recommend using one of the following methods:
- `of(Number num)`
- `of(String str)`
- `of(Money money)`
Example:
Money amount = Money.of(100.50); // $100.50 Money amountFromString = Money.of("75.25"); // $75.25 Money copy = Money.of(amount); // $100.50
Performing Calculations
You can perform common mathematical operations such as addition, subtraction, multiplication, and division:
Money price = Money.of(50); Money tax = Money.of(5.75);Money total = price.add(tax); // $55.75 Money discount = total.multiply(0.9); // $50.18 - Apply 10% discount
Money Behavior
Note that the {@link Money} type is immutable - a new instance of {@link Money} type is created after every operation. To compare values, use methods:
- `isEqualTo({@link Money amount`)}
- `isGreaterThan(@link Money amount)`}
- `isLessThan(@link Money amount)`
- `isGreaterThanOrEqualTo(@link Money amount)`
- `isLessThanOrEqualTo(@link Money amount)`
If you want to obtain boolean values commonly used in conditions, we recommend using predefined constants:
Money zero = Money.ZERO; // the same as Money.of(BigDecimal.ZERO); Monet one = Money.ONE; // the same as Money.of(BigDecimal.ONE);
{@link Money} instance currrentcy it is automatically synchronized with the Angel Financial section settings.
Best Practices
- Use `Money` for all financial operations instead of raw `BigDecimal` to avoid rounding problems.
- Use predefined arithmetic methods (`add`, `subtract`, `multiply`, `divide`) for accurate calculations.
ConstructorMoney(amount)
Constructs a new Money
instance. If null
is passed as value,
a Money.ZERO
amount will be created.
- amount: Number the value to create the
Money
instance. Ifnull
,Money.ZERO
will be used. @deprecated This constructor is deprecated. Use {@link #of(Number)} instead.
ConstructorMoney(amount)
Constructs a new Money
instance. If null
or an empty string is passed,
a Money.ZERO
amount will be created.
- amount: String the value to create the
Money
instance. Ifnull
or empty,Money.ZERO
will be used. @deprecated This constructor is deprecated. Use {@link #of(String)} instead.
ConstructorMoney(majorAmountUnit,fractionalAmountUnit)
Constructs a new Money
instance using the specified major and fractional
amount units. The first argument represents the whole amount (like dollar), while the second
represents the fractional part(like cent).
Example:
Money value = Money.of(5, 25) <=> $5.25 Money value = Money.of(55, 120) <=> $56.20 Money value = Money.of(2, -50) <=> $1.50 Money value = Money.of(2, -250) <=> -$1.50
- majorAmountUnit: Integer the whole number value of the monetary amount. @param fractionalAmountUnit the fractional value of the monetary amount. If it exceeds 99, the excess will be converted and added into the major amount unit. Negative values are also supported and will be substracted from the major amount unit. @deprecated This constructor is deprecated. Use {@link #of(Integer, Integer)} instead.
- fractionalAmountUnit: Integer the fractional value of the monetary amount. If it exceeds 99, the excess will be converted and added into the major amount unit. Negative values are also supported and will be substracted from the major amount unit. @deprecated This constructor is deprecated. Use {@link #of(Integer, Integer)} instead.
abs()
Converts any negative monetary amount to its positive equivalent.
If the current instance is positive or zero, it will be returned as is.
- Returns: Money a new
Money
instance representing the absolute value of this instance.
add(amount)
Adds the specified amount and returning a new Money
object.
MonetaryAmount
represent the family of Money types.
However, for most users, the `Money` type will suffice for all financial operations.
Example:
<pre>
Money sum = Money.ONE.add(Money.of(4)); // $5.00
Money sum = Money.ONE.add(Money.of(2.442)); // $3.44
Money sum = Money.ONE.add(Money.of(2.445)); // $3.45
</pre>
If the provided amount is `null`, this method will return the current instance.
-
amount: MonetaryAmount the value to be added to this
Money
object. Ifnull
, the current instance will be returned. @return a newMoney
object representing the sum. -
Returns: Money a new
Money
object representing the sum.
add(amount)
Adds the specified amount and returning a new Money
object.
If the provided amount is `null`, this method will return the current instance.
Example:
<pre>
Money sum = Money.ONE.add(4); // $5.00
Money sum = Money.ONE.add(2.442); // $3.44
Money sum = Money.ONE.add(2.445); // $3.45
</pre>
-
amount: Number the value to be added to this
Money
object. Ifnull
, the current instance will be returned. @return a newMoney
object representing the sum. -
Returns: Money a new
Money
object representing the sum.
compareTo(o)
Compares this Money
instance with another MonetaryAmount
.
This method ensures that values are rounded before comparison to avoid precision issues.
Example usage:
Money value1 = Money.of(10, 50); // $10.50 Money value2 = Money.of(10, 75); // $10.75int result = value1.compareTo(value2); // result < 0 (10.50 < 10.75) Money value1 = Money.of(10.499); // $10.50 Money value2 = Money.of(10. 50); // $10.50 int result = value1.compareTo(value2); // result = 0
-
o: MonetaryAmount the
MonetaryAmount
to compare with. @return a negative integer, zero, or a positive integer as this amount is less than, equal to, or greater than the specified amount. @throws NullPointerException if the given argument is null. -
Returns: int a negative integer, zero, or a positive integer as this amount is less than, equal to, or greater than the specified amount. @throws NullPointerException if the given argument is null.
divide(amount)
Divides this Money
instance by the specified amount and returning a new Money
object.
MonetaryAmount
represent the family of Money types.
However, for most users, the `Money` type will suffice for all financial operations.
Example:
<pre>
Money result = Money.of(5).divide(Money.of("2.4")); // $2.08
Money result = Money.of(1.456).divide(Money.of(2)) // $0.73
</pre>
-
amount: MonetaryAmount the value to multiply with this
Money
object. Ifnull
, the current instance will be returned. @return a newMoney
object representing division result. -
Returns: Money a new
Money
object representing division result.
divide(amount)
Divides this Money
instance by the specified amount and returning a new Money
object.
To specify the amount as a particular type, you could use type qualifiers:
- For long values, use `l` - `1l`
- For double values, use `d` - `1.0d`
-
amount: Number the value to multiply with this
Money
object. Ifnull
, the current instance will be returned. @return a newMoney
object representing division result. -
Returns: Money a new
Money
object representing division result.
divide(amount, roundingUp)
Divides this Money
instance by the specified amount and returning a new Money
object.
This method provides an option to round up the result if needed. It is used for rounding any value with cents to a greater integer value.
MonetaryAmount
represent the family of Money types.
However, for most users, the `Money` type will suffice for all financial operations.
Example:
<pre>
Money sum = Money.of(5).divide(Money.of("2.4"), true); // $3.00
Money sum = Money.of(5).divide(Money.of("2.4"), false); // $2.08
</pre>
-
amount: MonetaryAmount the divisor used to divide this
Money
object. Ifnull
, the current instance will be returned. @param roundingUp iftrue
, the result will be rounded up. @return a newMoney
object representing division result. @throws ArithmeticException if the specified amount is zero. -
roundingUp: boolean if
true
, the result will be rounded up. @return a newMoney
object representing division result. @throws ArithmeticException if the specified amount is zero. -
Returns: Money a new
Money
object representing division result. @throws ArithmeticException if the specified amount is zero.
divide(amount, roundingUp)
Divides this Money
instance by the specified amount and returning a new Money
object.
This method provides an option to round up the result if needed. It is used for rounding any value with cents to a greater integer value.
To specify the amount as a particular type, you could use type qualifiers:
- For long values, use `l` - `1l`
- For double values, use `d` - `1.0d`
Example:
<pre>
Money sum = Money.of(5).divide(2.4d, true); // $3.00
Money sum = Money.of(5).divide(2.4d, false); // $2.08
</pre>
-
amount: Number the divisor used to divide this
Money
object. Ifnull
, the current instance will be returned. @param roundingUp iftrue
, the result will be rounded up. @return a newMoney
object representing division result. @throws ArithmeticException if the specified amount is zero. -
roundingUp: boolean if
true
, the result will be rounded up. @return a newMoney
object representing division result. @throws ArithmeticException if the specified amount is zero. -
Returns: Money a new
Money
object representing division result. @throws ArithmeticException if the specified amount is zero.
doubleValue()
Returns the monetary value as a {@link Double}.
@deprecated use {@link #toDouble()}
- Returns: double Documentation not yet available
floatValue()
Returns the monetary value as a {@link Float}.
@deprecated use {@link #toFloat()}
- Returns: float Documentation not yet available
intValue()
Returns the monetary value as a {@link Integer}.
@deprecated use {@link #toInteger()}
- Returns: int Documentation not yet available
isEqualTo(amount)
Checks if this Money
instance is equal to the specified MonetaryAmount
.
MonetaryAmount
represent the family of Money types.
However, for most users, the `Money` type will suffice for all financial operations.
If the provided amount is `null`, this method will return `false`.
-
amount: MonetaryAmount the
MonetaryAmount
to compare with. @returntrue
if this instance is equal to the specified amount,false
otherwise. -
Returns: boolean
true
if this instance is equal to the specified amount,false
otherwise.
isGreaterThan(amount)
Checks if this Money
instance is greater than the specified MonetaryAmount
.
MonetaryAmount
represent the family of Money types.
However, for most users, the `Money` type will suffice for all financial operations.
If the provided amount is `null`, this method will return `true`.
-
amount: MonetaryAmount the
MonetaryAmount
to compare with. @returntrue
if this instance is greater than the specified amount,false
otherwise. -
Returns: boolean
true
if this instance is greater than the specified amount,false
otherwise.
isGreaterThanOrEqualTo(amount)
Checks if this Money
instance is greater or equal to the specified MonetaryAmount
.
MonetaryAmount
represent the family of Money types.
However, for most users, the `Money` type will suffice for all financial operations.
If the provided amount is `null`, this method will return `true`.
-
amount: MonetaryAmount the
MonetaryAmount
to compare with. @returntrue
if this instance is greater or equal to the specified amount,false
otherwise. -
Returns: boolean
true
if this instance is greater or equal to the specified amount,false
otherwise.
isLessThan(amount)
Checks if this Money
instance is less than the specified MonetaryAmount
.
MonetaryAmount
represent the family of Money types.
However, for most users, the `Money` type will suffice for all financial operations.
If the provided amount is `null`, this method will return `false`.
-
amount: MonetaryAmount the
MonetaryAmount
to compare with. @returntrue
if this instance is less than the specified amount,false
otherwise. -
Returns: boolean
true
if this instance is less than the specified amount,false
otherwise.
isLessThanOrEqualTo(amount)
Checks if this Money
instance is less or equal to the specified MonetaryAmount
.
MonetaryAmount
represent the family of Money types.
However, for most users, the `Money` type will suffice for all financial operations.
If the provided amount is `null`, this method will return `false`.
-
amount: MonetaryAmount the
MonetaryAmount
to compare with. @returntrue
if this instance is less or equal to the specified amount,false
otherwise. -
Returns: boolean
true
if this instance is less or equal to the specified amount,false
otherwise.
longValue()
Returns the monetary value as a {@link Long}.
@deprecated use {@link #toLong()}
- Returns: long Documentation not yet available
max(amount)
Returns the maximum of this Money
instance and the specified MonetaryAmount
.
MonetaryAmount
represent the family of Money types.
However, for most users, the `Money` type will suffice for all financial operations.
If the provided amount is `null` or greater than or equal to this instance, the current instance will be returned. Otherwise, the specified amount.
-
amount: MonetaryAmount Documentation not yet available
-
Returns: Money the maximum
Money
instance between this instance and the specified amount.
min(amount)
Returns the minimum of this Money
instance and the specified MonetaryAmount
.
MonetaryAmount
represent the family of Money types.
However, for most users, the `Money` type will suffice for all financial operations.
If the provided amount is `null` or less than or equal to this instance, the current instance will be returned. Otherwise, the specified amount.
-
amount: MonetaryAmount Documentation not yet available
-
Returns: Money the maximum
Money
instance between this instance and the specified amount.
multiply(amount)
Multiplies this Money
instance by the specified amount and returning a new Money
object.
If the provided amount is `null`, this method will return the current instance.
To specify the amount as a particular type, you could use type qualifiers:
- For long values, use `l` - `1l`
- For double values, use `d` - `1.0d`
Example:
Money result = Money.of(5).multiply(2l); // $10.00 Money result = Money.of(2.445).multiply(Money.of("1")) // $2.45
-
amount: Number the value to multiply with this
Money
object. Ifnull
, the current instance will be returned. @return a newMoney
object representing multiplication result. -
Returns: Money a new
Money
object representing multiplication result.
multiply(amount)
Multiplies this Money
instance by the specified amount and returning a new Money
object.
MonetaryAmount
represent the family of Money types.
However, for most users, the `Money` type will suffice for all financial operations.
Example:
Money result = Money.of(5).multiply(2l); // $10.00 Money result = Money.of(2, 445).multiply(Money.of("1")) // $2.45
-
amount: MonetaryAmount the value to multiply with this
Money
object. Ifnull
, the current instance will be returned. @return a newMoney
object representing multiplication result. -
Returns: Money a new
Money
object representing multiplication result.
of(amount)
Constructs a new Money
instance. If null
is passed as value,
a Money.ZERO
amount will be created.
-
amount: Number the value to create the
Money
instance. Ifnull
,Money.ZERO
will be used. -
Returns: Money Documentation not yet available
of(amount)
Constructs a new Money
instance. If null
or an empty string is passed,
a Money.ZERO
amount will be created.
-
amount: String the value to create the
Money
instance. Ifnull
or empty,Money.ZERO
will be used. -
Returns: Money Documentation not yet available
of(amount)
Constructs a new Money
instance as a copy of the provided MonetaryAmount
.
MonetaryAmount
represent the family of Money types.
However, for most users, the `Money` type will suffice for all financial operations.
If the provided `MonetaryAmount` is `null`, a `Money.of(0.00)` will be created. This method ensures that any monetary value is accurately represented as a `Money` instance.
-
amount: MonetaryAmount the
MonetaryAmount
to create newMoney
instance. Ifnull
, aMoney.of(0.00)
instance will be returned. @return a newMoney
instance that representing the specifiedMonetaryAmount
, orMoney.of(0.00)
if the provided amount isnull
. -
Returns: Money a new
Money
instance that representing the specifiedMonetaryAmount
, orMoney.of(0.00)
if the provided amount isnull
.
of(majorAmountUnit, fractionalAmountUnit)
Constructs a new Money
instance using the specified major and fractional
amount units. The first argument represents the whole amount (like dollar), while the second
represents the fractional part(like cent).
Example:
Money value = Money.of(5, 25) <=> $5.25 Money value = Money.of(55, 120) <=> $56.20 Money value = Money.of(2, -50) <=> $1.50 Money value = Money.of(2, -250) <=> -$1.50
-
majorAmountUnit: Integer the whole number value of the monetary amount. @param fractionalAmountUnit the fractional value of the monetary amount. If it exceeds 99, the excess will be converted and added into the major amount unit. Negative values are also supported and will be substracted from the major amount unit.
-
fractionalAmountUnit: Integer the fractional value of the monetary amount. If it exceeds 99, the excess will be converted and added into the major amount unit. Negative values are also supported and will be substracted from the major amount unit.
-
Returns: Money Documentation not yet available
subtract(amount)
Subtract the specified amount and returning a new Money
object.
MonetaryAmount
represent the family of Money types.
However, for most users, the `Money` type will suffice for all financial operations.
Example:
<pre>
Money sum = Money.of(4).subtract(Money.ONE); // $3.00
Money sum = Money.of(4).subtract(Money.of("1.44")); // $2.56
</pre>
If the provided amount is `null`, this method will return the current instance.
-
amount: MonetaryAmount the value to be subtracted from this
Money
object. Ifnull
, the current instance will be returned. @return a newMoney
object representing subtraction result. -
Returns: Money a new
Money
object representing subtraction result.
subtract(amount)
Subtract the specified amount and returning a new Money
object.
If the provided amount is `null`, this method will return the current instance.
Example:
<pre>
Money result = Money.of(4).subtract(1); // $3.00
Money result = Money.of(4).subtract(1.44); // $2.56
</pre>
-
amount: Number the value to be subtracted from this
Money
object. Ifnull
, the current instance will be returned. @return a newMoney
object representing subtraction result. -
Returns: Money a new
Money
object representing subtraction result.
toBigDecimal()
Returns the monetary value as a {@link BigDecimal}.
- Returns: BigDecimal Documentation not yet available
toDouble()
Returns the monetary value as a {@link Double}.
- Returns: Double Documentation not yet available
toFloat()
Returns the monetary value as a {@link Float}.
- Returns: float Documentation not yet available
toInteger()
Returns the monetary value as a {@link Integer}.
- Returns: Integer Documentation not yet available
toLong()
Returns the monetary value as a {@link Long}.
- Returns: long Documentation not yet available
toPlainString()
String representation of the monetary value, omitting the currency sign.
For example, a monetary amount of `$25.00` will be represented as `"25.00"`.
This method is useful for scenarios where the currency sign is not needed, and only the numerical value is required. (reports for example)
- Returns: String Documentation not yet available
MonitoringServiceImpl
Monitoring service which provides monitoring metrics: time, network, environment, license, systemRuntime, onCourse version
MoodleScriptClosure
Export successful enrolment record to moodle system. This action will search for students matching the onCourse
email address against the Moodle username, and creates them if not found.
moodle {
name 'Moodle integration'
enrolment record
}
The action finds courses in Moodle by 'shortname' field against the course name in onCourse. You can use
the 'courseReference' option to select a different field in Moodle and map it against any value from onCourse.
moodle {
name "Moodle integration"
enrolment record
courseReference 'courseId': record.courseClass.course.code
}
PaymentInterface
Interface to host both payment in and out, for both client and server side.
@author marcin, ldeck
Preferences
List of all preferences which can be accessed in the system. You can access the values most easily as direct attributes:
but you can also use the string key:
Report script block
Run a report and create a PDF file. This file can then be stored in the document management system or sent attached to an email.
Simple example to produce a single certificate PDF:
report {
fileName "certificate.pdf"
keycode "ish.onCourse.certificate"
record records
}
Usage example with sending an email:
email {
to preference.email.admin
subject "onCourse transaction summary ${startDate.format("dd/MM/yy")} to ${endDate.format("dd/MM/yy")}"
content "'Trial Balance' report for the previous 7 days."
attachment "Trial_Balance.pdf", "application/pdf", report {
keycode "ish.onCourse.trialBalance"
records accounts
param 'localdateRange_from' : startDate, 'localdateRange_to' : endDate
}
}
background(background)
The name of the background the report engine will use to render the output PDF file. The background sits behind
the components printed on the report. This is useful for a header or certificate background.
- background: String name of background. You can skip this option for a white background.
fileName(fileName)
Specify the filename with extension of the final file with a fulfilled report
- fileName: String fileName of the file with the report
generatePreview(generatePreview)
- generatePreview: Boolean Documentation not yet available
keycode(keyCode)
Pass the keycode of the report template in onCourse you want to run.
- keyCode: String keyCode of the report passed to the report engine
param(param)
Additional optional parameters passed to the report engine.
Reports must be provided with the correct number and types they accept to run. For example:
report {
keycode "ish.onCourse.trialBalance"
records accounts
param 'localdateRange_from' : startDate, 'localdateRange_to' : endDate
}
- param: Map parameters passed to the report
record(record)
Pass a record to the report engine. This record will be iterated through in the report engine
to produce the report output.
- record: Object record which is included in the report
record(records)
Pass a record to the report engine. This record will be iterated through in the report engine
to produce the report output.
- records: List Documentation not yet available
records(records)
Pass a list of records to the report engine. These records will be iterated through in the report engine
to produce the report output.
- records: List records which are included in the report
records(records)
Pass a record to the report engine.
- records: Object Documentation not yet available
S3ScriptClosure
Use this script block to easily send documents into the S3 service. Note that this has nothing to do with the onCourse document storage system and simply stores the blob in the S3 service without tracking it.
def transactions = query {
entity "AccountTransaction"
query "createdOn is today"
}
def bytes = export {
template "ish.onCourse.accountTransactionMYOB.csv"
records transactions
}
s3 {
name "integration name"
blob bytes
fileName "transactions.csv"
}
If you pass the DocumentParam object as the blob attribute, you can skip the name.
s3 {
name "integration name"
blob documentParam
}
Sms script block
SMS message sending API.
Usage example:
sms {
to contact1, contact2
text "test SMS text"
}
text(text)
Set SMS message text.
-
text: String message text
-
Returns: def Documentation not yet available
to(recipients)
Set recipients for the SMS message.
-
recipients: Contact recipients of the message
-
Returns: def Documentation not yet available
to(recipients)
Set list of recipients for the SMS message.
-
recipients: List of Contact list of recipients of the message
-
Returns: def Documentation not yet available
SurveyMonkeyScriptClosure
This integration allows you to push records into SurveyMonkey in order to add them to a survey. Create one integration
per survey you want to send and then use this scripting block:
surveyMonkey {
contact myContact
}
Use the name option if you have more than one SurveyMonkey integration and you want to push to only one.
surveyMonkey {
name "name of integration"
contact myContact
}
SystemUserService
systemUsersByRole(name)
-
name: String of role @return a list of all system users with certain access role
-
Returns: List of SystemUser a list of all system users with certain access role
Taggable
Entities which implement this interface may have TagRequirement, for example Student, Tutor but real TagRelation always created for Contact entity
TalentLMSScriptClosure
Export successful enrolment record to Talent LMS system. This action will search for students matching the onCourse
email address against the Talent LMS email, and creates them if not found.
That student will be enrolled in the Learndash course with code matching the course code in onCourse
talentLMS {
action "enrol"
course enrolment.courseClass.course.code
student enrolment.student
}
Updated 22 days ago