- Introduced EventWithSettings and EventWithSettingsRes structs for enhanced event data handling. - Implemented conversion functions for creating and updating event settings. - Added support for fetching events with settings from the database. - Created new report data structures for comprehensive reporting capabilities. - Implemented event statistics retrieval and filtering by league and sport. - Added handlers for event statistics endpoints in the web server. - Introduced DateInterval type for managing time intervals in reports.
31 lines
812 B
SQL
31 lines
812 B
SQL
-- name: GetBranchStats :many
|
|
SELECT b.branch_id,
|
|
br.name AS branch_name,
|
|
br.company_id,
|
|
COUNT(*) AS total_bets,
|
|
COALESCE(SUM(b.amount), 0) AS total_cash_made,
|
|
COALESCE(
|
|
SUM(
|
|
CASE
|
|
WHEN sb.cashed_out THEN b.amount -- use cashed_out from shop_bets
|
|
ELSE 0
|
|
END
|
|
),
|
|
0
|
|
) AS total_cash_out,
|
|
COALESCE(
|
|
SUM(
|
|
CASE
|
|
WHEN b.status = 5 THEN b.amount
|
|
ELSE 0
|
|
END
|
|
),
|
|
0
|
|
) AS total_cash_backs
|
|
FROM shop_bet_detail b
|
|
JOIN branches br ON b.branch_id = br.id
|
|
JOIN shop_bets sb ON sb.id = b.id -- join to get cashed_out
|
|
WHERE b.created_at BETWEEN sqlc.arg('from') AND sqlc.arg('to')
|
|
GROUP BY b.branch_id,
|
|
br.name,
|
|
br.company_id; |