Onsite Sales
singularName: onsite-salepluralName: onsite-sales
Table to store the sales activities at the runsite related to a run. Decision was taken to have all sales in one table members and guest records can be related to a sales item
Schema
| Name | Type | Details |
|---|---|---|
| run | relation | manyToOne → Hareline |
| guest | relation | manyToOne → Guests |
| member | relation | manyToOne → Members |
| sales_item | relation | manyToOne → Sales Items |
| quantity | integer | |
| total_amount | integer | |
| payment_type | enumeration | one of [Cash, DuitNow] |
Lifecycles
beforeCreate (async)
Before creating a new onsite sale entry, this method checks:
- Either Guest or Member must be present
- An entry can only be for a Member OR a Guest
- Sales item must be present
- Sales item must be valid
- Members can only buy a subscription if it is of the same type as the member
- Payment type defaults to Cash if not provided
- Total amount spent is calculated as the item price multiplied by the quantity
Throws an error if the checks fail.
Parameters:
event: - The event object containing the parameters for the new onsite sale entry.
Services
generatePDF (async)
Generates a PDF report document for a specific run date.
This function creates a PDF document consisting of a financial report page and an appendix page containing the transaction details. The document is formatted with specific layout dimensions and includes headers, tables, and fonts. Financial data is fetched based on the provided run date, and the resulting PDF is returned as a buffer.
Parameters:
runDate: - The date of the run for which the report is generated.
Returns:
- A buffer containing the bytes of the generated PDF document.
