325 lines
8.3 KiB
Go
325 lines
8.3 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: invoices.sql
|
|
|
|
package billing
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const createInvoice = `-- 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 invoice_id, billing_account_id, subscription_id, status, amount_due, amount_paid, currency, period_start, period_end, due_date, paid_at, voided_at, created_at, updated_at
|
|
`
|
|
|
|
type CreateInvoiceParams struct {
|
|
BillingAccountID string `json:"billing_account_id"`
|
|
SubscriptionID uuid.NullUUID `json:"subscription_id"`
|
|
Status string `json:"status"`
|
|
AmountDue int32 `json:"amount_due"`
|
|
AmountPaid int32 `json:"amount_paid"`
|
|
Currency string `json:"currency"`
|
|
PeriodStart sql.NullTime `json:"period_start"`
|
|
PeriodEnd sql.NullTime `json:"period_end"`
|
|
DueDate sql.NullTime `json:"due_date"`
|
|
}
|
|
|
|
func (q *Queries) CreateInvoice(ctx context.Context, arg CreateInvoiceParams) (Invoice, error) {
|
|
row := q.db.QueryRowContext(ctx, createInvoice,
|
|
arg.BillingAccountID,
|
|
arg.SubscriptionID,
|
|
arg.Status,
|
|
arg.AmountDue,
|
|
arg.AmountPaid,
|
|
arg.Currency,
|
|
arg.PeriodStart,
|
|
arg.PeriodEnd,
|
|
arg.DueDate,
|
|
)
|
|
var i Invoice
|
|
err := row.Scan(
|
|
&i.InvoiceID,
|
|
&i.BillingAccountID,
|
|
&i.SubscriptionID,
|
|
&i.Status,
|
|
&i.AmountDue,
|
|
&i.AmountPaid,
|
|
&i.Currency,
|
|
&i.PeriodStart,
|
|
&i.PeriodEnd,
|
|
&i.DueDate,
|
|
&i.PaidAt,
|
|
&i.VoidedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getInvoiceByID = `-- name: GetInvoiceByID :one
|
|
SELECT invoice_id, billing_account_id, subscription_id, status, amount_due, amount_paid, currency, period_start, period_end, due_date, paid_at, voided_at, created_at, updated_at FROM billing.invoices
|
|
WHERE invoice_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetInvoiceByID(ctx context.Context, invoiceID string) (Invoice, error) {
|
|
row := q.db.QueryRowContext(ctx, getInvoiceByID, invoiceID)
|
|
var i Invoice
|
|
err := row.Scan(
|
|
&i.InvoiceID,
|
|
&i.BillingAccountID,
|
|
&i.SubscriptionID,
|
|
&i.Status,
|
|
&i.AmountDue,
|
|
&i.AmountPaid,
|
|
&i.Currency,
|
|
&i.PeriodStart,
|
|
&i.PeriodEnd,
|
|
&i.DueDate,
|
|
&i.PaidAt,
|
|
&i.VoidedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getInvoicesByBillingAccountID = `-- name: GetInvoicesByBillingAccountID :many
|
|
SELECT invoice_id, billing_account_id, subscription_id, status, amount_due, amount_paid, currency, period_start, period_end, due_date, paid_at, voided_at, created_at, updated_at FROM billing.invoices
|
|
WHERE billing_account_id = $1
|
|
ORDER BY created_at DESC
|
|
`
|
|
|
|
func (q *Queries) GetInvoicesByBillingAccountID(ctx context.Context, billingAccountID string) ([]Invoice, error) {
|
|
rows, err := q.db.QueryContext(ctx, getInvoicesByBillingAccountID, billingAccountID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Invoice{}
|
|
for rows.Next() {
|
|
var i Invoice
|
|
if err := rows.Scan(
|
|
&i.InvoiceID,
|
|
&i.BillingAccountID,
|
|
&i.SubscriptionID,
|
|
&i.Status,
|
|
&i.AmountDue,
|
|
&i.AmountPaid,
|
|
&i.Currency,
|
|
&i.PeriodStart,
|
|
&i.PeriodEnd,
|
|
&i.DueDate,
|
|
&i.PaidAt,
|
|
&i.VoidedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listInvoices = `-- 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
|
|
`
|
|
|
|
type ListInvoicesRow struct {
|
|
InvoiceID string `json:"invoice_id"`
|
|
BillingAccountID string `json:"billing_account_id"`
|
|
SubscriptionID uuid.NullUUID `json:"subscription_id"`
|
|
Status string `json:"status"`
|
|
AmountDue int32 `json:"amount_due"`
|
|
AmountPaid int32 `json:"amount_paid"`
|
|
Currency string `json:"currency"`
|
|
PeriodStart sql.NullTime `json:"period_start"`
|
|
PeriodEnd sql.NullTime `json:"period_end"`
|
|
DueDate sql.NullTime `json:"due_date"`
|
|
PaidAt sql.NullTime `json:"paid_at"`
|
|
VoidedAt sql.NullTime `json:"voided_at"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
BillingAccountName string `json:"billing_account_name"`
|
|
}
|
|
|
|
func (q *Queries) ListInvoices(ctx context.Context) ([]ListInvoicesRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, listInvoices)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListInvoicesRow{}
|
|
for rows.Next() {
|
|
var i ListInvoicesRow
|
|
if err := rows.Scan(
|
|
&i.InvoiceID,
|
|
&i.BillingAccountID,
|
|
&i.SubscriptionID,
|
|
&i.Status,
|
|
&i.AmountDue,
|
|
&i.AmountPaid,
|
|
&i.Currency,
|
|
&i.PeriodStart,
|
|
&i.PeriodEnd,
|
|
&i.DueDate,
|
|
&i.PaidAt,
|
|
&i.VoidedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.BillingAccountName,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateInvoicePaid = `-- name: UpdateInvoicePaid :one
|
|
UPDATE billing.invoices
|
|
SET status = 'paid',
|
|
amount_paid = $2,
|
|
paid_at = $3
|
|
WHERE invoice_id = $1
|
|
RETURNING invoice_id, billing_account_id, subscription_id, status, amount_due, amount_paid, currency, period_start, period_end, due_date, paid_at, voided_at, created_at, updated_at
|
|
`
|
|
|
|
type UpdateInvoicePaidParams struct {
|
|
InvoiceID string `json:"invoice_id"`
|
|
AmountPaid int32 `json:"amount_paid"`
|
|
PaidAt sql.NullTime `json:"paid_at"`
|
|
}
|
|
|
|
func (q *Queries) UpdateInvoicePaid(ctx context.Context, arg UpdateInvoicePaidParams) (Invoice, error) {
|
|
row := q.db.QueryRowContext(ctx, updateInvoicePaid, arg.InvoiceID, arg.AmountPaid, arg.PaidAt)
|
|
var i Invoice
|
|
err := row.Scan(
|
|
&i.InvoiceID,
|
|
&i.BillingAccountID,
|
|
&i.SubscriptionID,
|
|
&i.Status,
|
|
&i.AmountDue,
|
|
&i.AmountPaid,
|
|
&i.Currency,
|
|
&i.PeriodStart,
|
|
&i.PeriodEnd,
|
|
&i.DueDate,
|
|
&i.PaidAt,
|
|
&i.VoidedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updateInvoiceStatus = `-- name: UpdateInvoiceStatus :one
|
|
UPDATE billing.invoices
|
|
SET status = $2
|
|
WHERE invoice_id = $1
|
|
RETURNING invoice_id, billing_account_id, subscription_id, status, amount_due, amount_paid, currency, period_start, period_end, due_date, paid_at, voided_at, created_at, updated_at
|
|
`
|
|
|
|
type UpdateInvoiceStatusParams struct {
|
|
InvoiceID string `json:"invoice_id"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
func (q *Queries) UpdateInvoiceStatus(ctx context.Context, arg UpdateInvoiceStatusParams) (Invoice, error) {
|
|
row := q.db.QueryRowContext(ctx, updateInvoiceStatus, arg.InvoiceID, arg.Status)
|
|
var i Invoice
|
|
err := row.Scan(
|
|
&i.InvoiceID,
|
|
&i.BillingAccountID,
|
|
&i.SubscriptionID,
|
|
&i.Status,
|
|
&i.AmountDue,
|
|
&i.AmountPaid,
|
|
&i.Currency,
|
|
&i.PeriodStart,
|
|
&i.PeriodEnd,
|
|
&i.DueDate,
|
|
&i.PaidAt,
|
|
&i.VoidedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updateInvoiceVoided = `-- name: UpdateInvoiceVoided :one
|
|
UPDATE billing.invoices
|
|
SET status = 'void',
|
|
voided_at = $2
|
|
WHERE invoice_id = $1
|
|
RETURNING invoice_id, billing_account_id, subscription_id, status, amount_due, amount_paid, currency, period_start, period_end, due_date, paid_at, voided_at, created_at, updated_at
|
|
`
|
|
|
|
type UpdateInvoiceVoidedParams struct {
|
|
InvoiceID string `json:"invoice_id"`
|
|
VoidedAt sql.NullTime `json:"voided_at"`
|
|
}
|
|
|
|
func (q *Queries) UpdateInvoiceVoided(ctx context.Context, arg UpdateInvoiceVoidedParams) (Invoice, error) {
|
|
row := q.db.QueryRowContext(ctx, updateInvoiceVoided, arg.InvoiceID, arg.VoidedAt)
|
|
var i Invoice
|
|
err := row.Scan(
|
|
&i.InvoiceID,
|
|
&i.BillingAccountID,
|
|
&i.SubscriptionID,
|
|
&i.Status,
|
|
&i.AmountDue,
|
|
&i.AmountPaid,
|
|
&i.Currency,
|
|
&i.PeriodStart,
|
|
&i.PeriodEnd,
|
|
&i.DueDate,
|
|
&i.PaidAt,
|
|
&i.VoidedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|