// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.29.0 // source: report.sql package dbgen import ( "context" "github.com/jackc/pgx/v5/pgtype" ) const GetBranchWiseReport = `-- name: GetBranchWiseReport :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 b.cashed_out THEN b.amount 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 bets b JOIN branches br ON b.branch_id = br.id WHERE b.created_at BETWEEN $1 AND $2 GROUP BY b.branch_id, br.name, br.company_id ` type GetBranchWiseReportParams struct { From pgtype.Timestamp `json:"from"` To pgtype.Timestamp `json:"to"` } type GetBranchWiseReportRow struct { BranchID pgtype.Int8 `json:"branch_id"` BranchName string `json:"branch_name"` CompanyID int64 `json:"company_id"` TotalBets int64 `json:"total_bets"` TotalCashMade interface{} `json:"total_cash_made"` TotalCashOut interface{} `json:"total_cash_out"` TotalCashBacks interface{} `json:"total_cash_backs"` } func (q *Queries) GetBranchWiseReport(ctx context.Context, arg GetBranchWiseReportParams) ([]GetBranchWiseReportRow, error) { rows, err := q.db.Query(ctx, GetBranchWiseReport, arg.From, arg.To) if err != nil { return nil, err } defer rows.Close() var items []GetBranchWiseReportRow for rows.Next() { var i GetBranchWiseReportRow if err := rows.Scan( &i.BranchID, &i.BranchName, &i.CompanyID, &i.TotalBets, &i.TotalCashMade, &i.TotalCashOut, &i.TotalCashBacks, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const GetCompanyWiseReport = `-- name: GetCompanyWiseReport :many SELECT b.company_id, c.name AS company_name, COUNT(*) AS total_bets, COALESCE(SUM(b.amount), 0) AS total_cash_made, COALESCE(SUM(CASE WHEN b.cashed_out THEN b.amount 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 bets b JOIN companies c ON b.company_id = c.id WHERE b.created_at BETWEEN $1 AND $2 GROUP BY b.company_id, c.name ` type GetCompanyWiseReportParams struct { From pgtype.Timestamp `json:"from"` To pgtype.Timestamp `json:"to"` } type GetCompanyWiseReportRow struct { CompanyID pgtype.Int8 `json:"company_id"` CompanyName string `json:"company_name"` TotalBets int64 `json:"total_bets"` TotalCashMade interface{} `json:"total_cash_made"` TotalCashOut interface{} `json:"total_cash_out"` TotalCashBacks interface{} `json:"total_cash_backs"` } func (q *Queries) GetCompanyWiseReport(ctx context.Context, arg GetCompanyWiseReportParams) ([]GetCompanyWiseReportRow, error) { rows, err := q.db.Query(ctx, GetCompanyWiseReport, arg.From, arg.To) if err != nil { return nil, err } defer rows.Close() var items []GetCompanyWiseReportRow for rows.Next() { var i GetCompanyWiseReportRow if err := rows.Scan( &i.CompanyID, &i.CompanyName, &i.TotalBets, &i.TotalCashMade, &i.TotalCashOut, &i.TotalCashBacks, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const GetTotalBetsMadeInRange = `-- name: GetTotalBetsMadeInRange :one SELECT COUNT(*) AS total_bets FROM bets WHERE created_at BETWEEN $1 AND $2 ` type GetTotalBetsMadeInRangeParams struct { From pgtype.Timestamp `json:"from"` To pgtype.Timestamp `json:"to"` } func (q *Queries) GetTotalBetsMadeInRange(ctx context.Context, arg GetTotalBetsMadeInRangeParams) (int64, error) { row := q.db.QueryRow(ctx, GetTotalBetsMadeInRange, arg.From, arg.To) var total_bets int64 err := row.Scan(&total_bets) return total_bets, err } const GetTotalCashBacksInRange = `-- name: GetTotalCashBacksInRange :one SELECT COALESCE(SUM(amount), 0) AS total_cash_backs FROM bets WHERE created_at BETWEEN $1 AND $2 AND status = 5 ` type GetTotalCashBacksInRangeParams struct { From pgtype.Timestamp `json:"from"` To pgtype.Timestamp `json:"to"` } func (q *Queries) GetTotalCashBacksInRange(ctx context.Context, arg GetTotalCashBacksInRangeParams) (interface{}, error) { row := q.db.QueryRow(ctx, GetTotalCashBacksInRange, arg.From, arg.To) var total_cash_backs interface{} err := row.Scan(&total_cash_backs) return total_cash_backs, err } const GetTotalCashMadeInRange = `-- name: GetTotalCashMadeInRange :one SELECT COALESCE(SUM(amount), 0) AS total_cash_made FROM bets WHERE created_at BETWEEN $1 AND $2 ` type GetTotalCashMadeInRangeParams struct { From pgtype.Timestamp `json:"from"` To pgtype.Timestamp `json:"to"` } func (q *Queries) GetTotalCashMadeInRange(ctx context.Context, arg GetTotalCashMadeInRangeParams) (interface{}, error) { row := q.db.QueryRow(ctx, GetTotalCashMadeInRange, arg.From, arg.To) var total_cash_made interface{} err := row.Scan(&total_cash_made) return total_cash_made, err } const GetTotalCashOutInRange = `-- name: GetTotalCashOutInRange :one SELECT COALESCE(SUM(amount), 0) AS total_cash_out FROM bets WHERE created_at BETWEEN $1 AND $2 AND cashed_out = true ` type GetTotalCashOutInRangeParams struct { From pgtype.Timestamp `json:"from"` To pgtype.Timestamp `json:"to"` } func (q *Queries) GetTotalCashOutInRange(ctx context.Context, arg GetTotalCashOutInRangeParams) (interface{}, error) { row := q.db.QueryRow(ctx, GetTotalCashOutInRange, arg.From, arg.To) var total_cash_out interface{} err := row.Scan(&total_cash_out) return total_cash_out, err }