feat: add invoice and alternative_componen management functionality

This commit is contained in:
Tran Anh Tuan
2026-05-12 11:57:11 +07:00
parent c39b010e5e
commit e81a248a61
23 changed files with 3325 additions and 2 deletions

40
db/queries/invoice.sql Normal file
View File

@@ -0,0 +1,40 @@
-- name: GetInvoiceByID :one
SELECT * FROM invoices
WHERE id = sqlc.arg(id);
-- name: ListInvoices :many
SELECT * FROM invoices
ORDER BY created_at DESC;
-- name: CreateInvoice :one
INSERT INTO invoices (type, status, invoice_config_id, total_items, note, created_by, approved_by, created_at, metadata)
VALUES (
sqlc.arg(type),
sqlc.arg(status),
sqlc.arg(invoice_config_id),
sqlc.arg(total_items),
sqlc.arg(note),
sqlc.arg(created_by),
sqlc.arg(approved_by),
sqlc.arg(created_at),
sqlc.arg(metadata)
)
RETURNING *;
-- name: UpdateInvoice :one
UPDATE invoices
SET type = coalesce(sqlc.arg(type), type),
status = coalesce(sqlc.arg(status), status),
invoice_config_id = coalesce(sqlc.arg(invoice_config_id), invoice_config_id),
total_items = coalesce(sqlc.arg(total_items), total_items),
note = coalesce(sqlc.arg(note), note),
metadata = coalesce(sqlc.arg(metadata), metadata),
updated_at = sqlc.arg(updated_at)
WHERE id = sqlc.arg(id)
RETURNING *;
-- name: DeleteInvoice :execrows
DELETE FROM invoices
WHERE id = sqlc.arg(id);