60 lines
1.3 KiB
SQL
60 lines
1.3 KiB
SQL
-- name: CreateInvoice :one
|
|
INSERT INTO billing.invoices (
|
|
billing_account_id, subscription_id, status,
|
|
amount_due, amount_paid, currency,
|
|
period_start, period_end, due_date
|
|
)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
RETURNING *;
|
|
|
|
-- name: GetInvoiceByID :one
|
|
SELECT * FROM billing.invoices
|
|
WHERE invoice_id = $1;
|
|
|
|
-- name: GetInvoicesByBillingAccountID :many
|
|
SELECT * FROM billing.invoices
|
|
WHERE billing_account_id = $1
|
|
ORDER BY created_at DESC;
|
|
|
|
-- name: UpdateInvoiceStatus :one
|
|
UPDATE billing.invoices
|
|
SET status = $2
|
|
WHERE invoice_id = $1
|
|
RETURNING *;
|
|
|
|
-- name: UpdateInvoicePaid :one
|
|
UPDATE billing.invoices
|
|
SET status = 'paid',
|
|
amount_paid = $2,
|
|
paid_at = $3
|
|
WHERE invoice_id = $1
|
|
RETURNING *;
|
|
|
|
-- name: UpdateInvoiceVoided :one
|
|
UPDATE billing.invoices
|
|
SET status = 'void',
|
|
voided_at = $2
|
|
WHERE invoice_id = $1
|
|
RETURNING *;
|
|
|
|
-- name: ListInvoices :many
|
|
SELECT
|
|
i.invoice_id,
|
|
i.billing_account_id,
|
|
i.subscription_id,
|
|
i.status,
|
|
i.amount_due,
|
|
i.amount_paid,
|
|
i.currency,
|
|
i.period_start,
|
|
i.period_end,
|
|
i.due_date,
|
|
i.paid_at,
|
|
i.voided_at,
|
|
i.created_at,
|
|
i.updated_at,
|
|
ba.name as billing_account_name
|
|
FROM billing.invoices i
|
|
JOIN billing.accounts ba ON i.billing_account_id = ba.billing_account_id
|
|
ORDER BY i.created_at DESC;
|