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.
addAppendixPage (async)
Appends one or more appendix pages to pdfDoc listing every individual guest-fee and onsite-sale transaction. Automatically creates additional pages when rows would overflow the bottom margin.
Parameters:
pdfDoc:run: - Run summary fromrunInfo.financialData: - Aggregated financial data fromfetchFinancialData.layout: - Page dimension and font constants.
addReportPage (async)
Appends the main cash-flow summary page to pdfDoc, including cash-collection, subscription, expense, and balance sections.
Parameters:
pdfDoc:run: - Run summary fromrunInfo.financialData: - Aggregated financial data fromfetchFinancialData.layout: - Page dimension and font constants.
hexToRgbNormalized
Converts a CSS hex colour string to normalised RGB components (0–1 range).
Parameters:
hex: - e.g."#AD1457"
Returns:
createCashCollectionList
Merges guest-fee and drinks-sales data into a padded row list for the Cash Collections section. Pads to a minimum of 4 entries so the report layout stays consistent.
Parameters:
guestsPerFee: - Aggregated guest-fee buckets.drinksSalesSummary: - Aggregated drink-sales rows.
Returns:
createSubscriptionsCollection
Converts aggregated subscription-sales data into a padded row list for the Subscriptions section. Pads to a minimum of 5 entries so the report layout stays consistent.
Parameters:
subsSalesSummary: - Aggregated subscription-sales rows.
Returns:
createCashExpenseCollection
Converts cash-expense records into a padded row list for the Cash Expenses section. Pads to a minimum of 5 entries so the report layout stays consistent.
Parameters:
cashExpenses: - Raw cash-expense records from the database.
Returns:
createAppendixCollection
Combines guest-fee sign-ins and onsite-sale records into a single flat row list for the appendix table. Guest entries are tagged with type "G"; member entries with type "M".
Parameters:
guestFees: - Guest sign-in records (populated withguest).onsiteSales: - Onsite-sale records (populated withguest,member,sales_item).
Returns:
drawHeader
Draws the club logo image into the header rectangle at the top of a report page.
Parameters:
page:image: - Pre-embedded PNG header image.layout: - Page dimension constants.
drawTitleBar
Draws a coloured title bar with centred or left-indented text, returning the y-coordinate immediately below it.
Parameters:
page:layout: - Page dimension and font constants.startY: - Top y-coordinate for the bar.options:options.titleText:options.backgroundColorHex:options.textColorHex:options.borderColorHex:options.bold:options.fontSize:options.rowHeight:options.indent:
Returns:
- below the bar.
drawHeaderInfoBoxes
Draws the four info boxes (Run Date, Runsite, Run No, Hare) directly below the title bar.
Parameters:
page:run: - Run summary fromrunInfo.layout: - Page dimension and font constants.
drawTableHeader
Draws the two-row column-header row (Statement Item / Cash In / Cash Out / To Bank) for the main report table.
Parameters:
page:layout: - Page dimension and font constants.
Returns:
- below the header row.
drawTableHeaderAppendix
Draws the single-row column-header row (T / Name / Sales Item / Qty / Price / Cash / DuitNow) for the appendix table.
Parameters:
page:layout: - Page dimension and font constants.
Returns:
- of the top of the first data row.
drawFinancialRow
Draws a single data row in the main cash-flow report table and returns the y-coordinate below it.
Parameters:
page:layout: - Page dimension and font constants.startY: - Top y-coordinate of the row.options:options.statementItem:options.cashIn:options.cashOut:options.toBank:options.backgroundColorHex:options.drawBottomLine:options.bold:options.fontSize:options.rowHeight:
Returns:
- below the row.
drawAppendixRow
Draws a single data row in the appendix table and returns the y-coordinate below it.
Parameters:
page:layout: - Page dimension and font constants.rowData: - Row values:{ type, buyer_name, sales_item, quantity, item_price, cash, duit_now }.yPosition: - Top y-coordinate of the row.options:options.rowHeight:options.fontSize:options.backgroundColor:
Returns:
- below the row.
fetchFinancialData (async)
Fetches and aggregates all financial data for a given run date from the database. Returns guest fees, onsite sales, cash expenses, and pre-computed totals used by the PDF report.
Parameters:
runDate: - ISO date string (YYYY-MM-DD).
Returns:
- financial data object.
