173 lines
4.0 KiB
SQL
173 lines
4.0 KiB
SQL
-- name: CreateShopTransaction :one
|
|
INSERT INTO shop_transactions (
|
|
amount,
|
|
branch_id,
|
|
company_id,
|
|
user_id,
|
|
type,
|
|
full_name,
|
|
phone_number,
|
|
payment_option,
|
|
bank_code,
|
|
beneficiary_name,
|
|
account_name,
|
|
account_number,
|
|
reference_number
|
|
)
|
|
VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
$6,
|
|
$7,
|
|
$8,
|
|
$9,
|
|
$10,
|
|
$11,
|
|
$12,
|
|
$13
|
|
)
|
|
RETURNING *;
|
|
-- name: GetAllShopTransactions :many
|
|
SELECT *
|
|
FROM shop_transaction_detail
|
|
wHERE (
|
|
branch_id = sqlc.narg('branch_id')
|
|
OR sqlc.narg('branch_id') IS NULL
|
|
)
|
|
AND (
|
|
company_id = sqlc.narg('company_id')
|
|
OR sqlc.narg('company_id') IS NULL
|
|
)
|
|
AND (
|
|
user_id = sqlc.narg('user_id')
|
|
OR sqlc.narg('user_id') IS NULL
|
|
)
|
|
AND (
|
|
full_name ILIKE '%' || sqlc.narg('query') || '%'
|
|
OR phone_number ILIKE '%' || sqlc.narg('query') || '%'
|
|
OR sqlc.narg('query') IS NULL
|
|
)
|
|
AND (
|
|
created_at > sqlc.narg('created_before')
|
|
OR sqlc.narg('created_before') IS NULL
|
|
)
|
|
AND (
|
|
created_at < sqlc.narg('created_after')
|
|
OR sqlc.narg('created_after') IS NULL
|
|
);
|
|
-- name: GetShopTransactionByID :one
|
|
SELECT *
|
|
FROM shop_transaction_detail
|
|
WHERE id = $1;
|
|
-- name: GetShopTransactionByBranch :many
|
|
SELECT *
|
|
FROM shop_transaction_detail
|
|
WHERE branch_id = $1;
|
|
-- name: UpdateShopTransactionVerified :exec
|
|
UPDATE shop_transactions
|
|
SET verified = $2,
|
|
approved_by = $3,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $1;
|
|
-- name: CreateShopBet :one
|
|
INSERT INTO shop_bets (
|
|
shop_transaction_id,
|
|
cashout_id,
|
|
bet_id,
|
|
number_of_outcomes
|
|
)
|
|
VALUES ($1, $2, $3, $4)
|
|
RETURNING *;
|
|
-- name: GetAllShopBets :many
|
|
SELECT *
|
|
FROM shop_bet_detail
|
|
WHERE (
|
|
full_name ILIKE '%' || sqlc.narg('query') || '%'
|
|
OR phone_number ILIKE '%' || sqlc.narg('query') || '%'
|
|
OR sqlc.narg('query') IS NULL
|
|
)
|
|
AND (
|
|
branch_id = sqlc.narg('branch_id')
|
|
OR sqlc.narg('branch_id') IS NULL
|
|
)
|
|
AND (
|
|
company_id = sqlc.narg('company_id')
|
|
OR sqlc.narg('company_id') IS NULL
|
|
)
|
|
AND (
|
|
created_at > sqlc.narg('created_before')
|
|
OR sqlc.narg('created_before') IS NULL
|
|
)
|
|
AND (
|
|
created_at < sqlc.narg('created_after')
|
|
OR sqlc.narg('created_after') IS NULL
|
|
);
|
|
-- name: GetShopBetByID :one
|
|
SELECT *
|
|
FROM shop_bet_detail
|
|
WHERE id = $1;
|
|
-- name: GetShopBetByBetID :one
|
|
SELECT *
|
|
FROM shop_bet_detail
|
|
WHERE bet_id = $1;
|
|
-- name: GetShopBetByCashoutID :one
|
|
SELECT *
|
|
FROM shop_bet_detail
|
|
WHERE cashout_id = $1;
|
|
-- name: GetShopBetByShopTransactionID :one
|
|
SELECT *
|
|
FROM shop_bet_detail
|
|
WHERE shop_transaction_id = $1;
|
|
-- name: UpdateShopBetCashOut :exec
|
|
UPDATE shop_bets
|
|
SET cashed_out = $2,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $1;
|
|
-- name: UpdateShopBetCashoutID :exec
|
|
UPDATE shop_bets
|
|
SET cashout_id = $2,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $1;
|
|
-- name: CreateShopDeposit :one
|
|
INSERT INTO shop_deposits (
|
|
shop_transaction_id,
|
|
customer_id,
|
|
wallet_transfer_id
|
|
)
|
|
VALUES ($1, $2, $3)
|
|
RETURNING *;
|
|
-- name: GetAllShopDeposit :many
|
|
SELECT *
|
|
FROM shop_deposit_detail
|
|
WHERE (
|
|
full_name ILIKE '%' || sqlc.narg('query') || '%'
|
|
OR phone_number ILIKE '%' || sqlc.narg('query') || '%'
|
|
OR sqlc.narg('query') IS NULL
|
|
)
|
|
AND (
|
|
branch_id = sqlc.narg('branch_id')
|
|
OR sqlc.narg('branch_id') IS NULL
|
|
)
|
|
AND (
|
|
company_id = sqlc.narg('company_id')
|
|
OR sqlc.narg('company_id') IS NULL
|
|
)
|
|
AND (
|
|
created_at > sqlc.narg('created_before')
|
|
OR sqlc.narg('created_before') IS NULL
|
|
)
|
|
AND (
|
|
created_at < sqlc.narg('created_after')
|
|
OR sqlc.narg('created_after') IS NULL
|
|
);
|
|
-- name: GetShopDepositByID :one
|
|
SELECT *
|
|
FROM shop_deposit_detail
|
|
WHERE id = $1;
|
|
-- name: GetShopDepositByShopTransactionID :one
|
|
SELECT *
|
|
FROM shop_deposit_detail
|
|
WHERE shop_transaction_id = $1; |