85 lines
1.8 KiB
SQL
85 lines
1.8 KiB
SQL
-- name: CreateTransaction :one
|
|
INSERT INTO transactions (
|
|
amount,
|
|
branch_id,
|
|
cashier_id,
|
|
bet_id,
|
|
type,
|
|
payment_option,
|
|
full_name,
|
|
phone_number,
|
|
bank_code,
|
|
beneficiary_name,
|
|
account_name,
|
|
account_number,
|
|
reference_number,
|
|
number_of_outcomes,
|
|
branch_name,
|
|
branch_location,
|
|
company_id,
|
|
cashier_name
|
|
)
|
|
VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
$6,
|
|
$7,
|
|
$8,
|
|
$9,
|
|
$10,
|
|
$11,
|
|
$12,
|
|
$13,
|
|
$14,
|
|
$15,
|
|
$16,
|
|
$17,
|
|
$18
|
|
)
|
|
RETURNING *;
|
|
-- name: GetAllTransactions :many
|
|
SELECT *
|
|
FROM transactions
|
|
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 (
|
|
cashier_id = sqlc.narg('cashier_id')
|
|
OR sqlc.narg('cashier_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: GetTransactionByID :one
|
|
SELECT *
|
|
FROM transactions
|
|
WHERE id = $1;
|
|
-- name: GetTransactionByBranch :many
|
|
SELECT *
|
|
FROM transactions
|
|
WHERE branch_id = $1;
|
|
-- name: UpdateTransactionVerified :exec
|
|
UPDATE transactions
|
|
SET verified = $2,
|
|
approved_by = $3,
|
|
approver_name = $4,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $1; |