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

View File

@@ -0,0 +1,166 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: alternative_component.sql
package db
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const createAlternativeComponent = `-- name: CreateAlternativeComponent :one
INSERT INTO alternative_components (invoice_config_item_id, alternative_component_id, conversion_ratio, priority, note, metadata)
VALUES (
$1,
$2,
$3,
$4,
$5,
$6
)
RETURNING id, invoice_config_item_id, alternative_component_id, conversion_ratio, priority, note, metadata
`
type CreateAlternativeComponentParams struct {
InvoiceConfigItemID int64 `db:"invoice_config_item_id" json:"invoiceConfigItemId"`
AlternativeComponentID int64 `db:"alternative_component_id" json:"alternativeComponentId"`
ConversionRatio pgtype.Numeric `db:"conversion_ratio" json:"conversionRatio"`
Priority int32 `db:"priority" json:"priority"`
Note pgtype.Text `db:"note" json:"note"`
Metadata []byte `db:"metadata" json:"metadata"`
}
func (q *Queries) CreateAlternativeComponent(ctx context.Context, arg CreateAlternativeComponentParams) (AlternativeComponent, error) {
row := q.db.QueryRow(ctx, createAlternativeComponent,
arg.InvoiceConfigItemID,
arg.AlternativeComponentID,
arg.ConversionRatio,
arg.Priority,
arg.Note,
arg.Metadata,
)
var i AlternativeComponent
err := row.Scan(
&i.ID,
&i.InvoiceConfigItemID,
&i.AlternativeComponentID,
&i.ConversionRatio,
&i.Priority,
&i.Note,
&i.Metadata,
)
return i, err
}
const deleteAlternativeComponent = `-- name: DeleteAlternativeComponent :execrows
DELETE FROM alternative_components
WHERE id = $1
`
func (q *Queries) DeleteAlternativeComponent(ctx context.Context, id int64) (int64, error) {
result, err := q.db.Exec(ctx, deleteAlternativeComponent, id)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const getAlternativeComponentByID = `-- name: GetAlternativeComponentByID :one
SELECT id, invoice_config_item_id, alternative_component_id, conversion_ratio, priority, note, metadata FROM alternative_components
WHERE id = $1
`
func (q *Queries) GetAlternativeComponentByID(ctx context.Context, id int64) (AlternativeComponent, error) {
row := q.db.QueryRow(ctx, getAlternativeComponentByID, id)
var i AlternativeComponent
err := row.Scan(
&i.ID,
&i.InvoiceConfigItemID,
&i.AlternativeComponentID,
&i.ConversionRatio,
&i.Priority,
&i.Note,
&i.Metadata,
)
return i, err
}
const listAlternativeComponents = `-- name: ListAlternativeComponents :many
SELECT id, invoice_config_item_id, alternative_component_id, conversion_ratio, priority, note, metadata FROM alternative_components
`
func (q *Queries) ListAlternativeComponents(ctx context.Context) ([]AlternativeComponent, error) {
rows, err := q.db.Query(ctx, listAlternativeComponents)
if err != nil {
return nil, err
}
defer rows.Close()
var items []AlternativeComponent
for rows.Next() {
var i AlternativeComponent
if err := rows.Scan(
&i.ID,
&i.InvoiceConfigItemID,
&i.AlternativeComponentID,
&i.ConversionRatio,
&i.Priority,
&i.Note,
&i.Metadata,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const updateAlternativeComponent = `-- name: UpdateAlternativeComponent :one
UPDATE alternative_components
SET invoice_config_item_id = coalesce($1, invoice_config_item_id),
alternative_component_id = coalesce($2, alternative_component_id),
conversion_ratio = coalesce($3, conversion_ratio),
priority = coalesce($4, priority),
note = coalesce($5, note),
metadata = coalesce($6, metadata)
WHERE id = $7
RETURNING id, invoice_config_item_id, alternative_component_id, conversion_ratio, priority, note, metadata
`
type UpdateAlternativeComponentParams struct {
InvoiceConfigItemID int64 `db:"invoice_config_item_id" json:"invoiceConfigItemId"`
AlternativeComponentID int64 `db:"alternative_component_id" json:"alternativeComponentId"`
ConversionRatio pgtype.Numeric `db:"conversion_ratio" json:"conversionRatio"`
Priority int32 `db:"priority" json:"priority"`
Note pgtype.Text `db:"note" json:"note"`
Metadata []byte `db:"metadata" json:"metadata"`
ID int64 `db:"id" json:"id"`
}
func (q *Queries) UpdateAlternativeComponent(ctx context.Context, arg UpdateAlternativeComponentParams) (AlternativeComponent, error) {
row := q.db.QueryRow(ctx, updateAlternativeComponent,
arg.InvoiceConfigItemID,
arg.AlternativeComponentID,
arg.ConversionRatio,
arg.Priority,
arg.Note,
arg.Metadata,
arg.ID,
)
var i AlternativeComponent
err := row.Scan(
&i.ID,
&i.InvoiceConfigItemID,
&i.AlternativeComponentID,
&i.ConversionRatio,
&i.Priority,
&i.Note,
&i.Metadata,
)
return i, err
}

204
sqlc_gen/invoice.sql.go Normal file
View File

@@ -0,0 +1,204 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: invoice.sql
package db
import (
"context"
"time"
"github.com/jackc/pgx/v5/pgtype"
)
const createInvoice = `-- name: CreateInvoice :one
INSERT INTO invoices (type, status, invoice_config_id, total_items, note, created_by, approved_by, created_at, metadata)
VALUES (
$1,
$2,
$3,
$4,
$5,
$6,
$7,
$8,
$9
)
RETURNING id, invoice_code, type, status, invoice_config_id, total_items, note, created_by, approved_by, completed_at, created_at, updated_at, metadata
`
type CreateInvoiceParams struct {
Type InvoiceTypeEnum `db:"type" json:"type"`
Status InvoiceStatusEnum `db:"status" json:"status"`
InvoiceConfigID pgtype.Int8 `db:"invoice_config_id" json:"invoiceConfigId"`
TotalItems int32 `db:"total_items" json:"totalItems"`
Note pgtype.Text `db:"note" json:"note"`
CreatedBy pgtype.Text `db:"created_by" json:"createdBy"`
ApprovedBy pgtype.Text `db:"approved_by" json:"approvedBy"`
CreatedAt time.Time `db:"created_at" json:"createdAt"`
Metadata []byte `db:"metadata" json:"metadata"`
}
func (q *Queries) CreateInvoice(ctx context.Context, arg CreateInvoiceParams) (Invoice, error) {
row := q.db.QueryRow(ctx, createInvoice,
arg.Type,
arg.Status,
arg.InvoiceConfigID,
arg.TotalItems,
arg.Note,
arg.CreatedBy,
arg.ApprovedBy,
arg.CreatedAt,
arg.Metadata,
)
var i Invoice
err := row.Scan(
&i.ID,
&i.InvoiceCode,
&i.Type,
&i.Status,
&i.InvoiceConfigID,
&i.TotalItems,
&i.Note,
&i.CreatedBy,
&i.ApprovedBy,
&i.CompletedAt,
&i.CreatedAt,
&i.UpdatedAt,
&i.Metadata,
)
return i, err
}
const deleteInvoice = `-- name: DeleteInvoice :execrows
DELETE FROM invoices
WHERE id = $1
`
func (q *Queries) DeleteInvoice(ctx context.Context, id int64) (int64, error) {
result, err := q.db.Exec(ctx, deleteInvoice, id)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const getInvoiceByID = `-- name: GetInvoiceByID :one
SELECT id, invoice_code, type, status, invoice_config_id, total_items, note, created_by, approved_by, completed_at, created_at, updated_at, metadata FROM invoices
WHERE id = $1
`
func (q *Queries) GetInvoiceByID(ctx context.Context, id int64) (Invoice, error) {
row := q.db.QueryRow(ctx, getInvoiceByID, id)
var i Invoice
err := row.Scan(
&i.ID,
&i.InvoiceCode,
&i.Type,
&i.Status,
&i.InvoiceConfigID,
&i.TotalItems,
&i.Note,
&i.CreatedBy,
&i.ApprovedBy,
&i.CompletedAt,
&i.CreatedAt,
&i.UpdatedAt,
&i.Metadata,
)
return i, err
}
const listInvoices = `-- name: ListInvoices :many
SELECT id, invoice_code, type, status, invoice_config_id, total_items, note, created_by, approved_by, completed_at, created_at, updated_at, metadata FROM invoices
ORDER BY created_at DESC
`
func (q *Queries) ListInvoices(ctx context.Context) ([]Invoice, error) {
rows, err := q.db.Query(ctx, listInvoices)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Invoice
for rows.Next() {
var i Invoice
if err := rows.Scan(
&i.ID,
&i.InvoiceCode,
&i.Type,
&i.Status,
&i.InvoiceConfigID,
&i.TotalItems,
&i.Note,
&i.CreatedBy,
&i.ApprovedBy,
&i.CompletedAt,
&i.CreatedAt,
&i.UpdatedAt,
&i.Metadata,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const updateInvoice = `-- name: UpdateInvoice :one
UPDATE invoices
SET type = coalesce($1, type),
status = coalesce($2, status),
invoice_config_id = coalesce($3, invoice_config_id),
total_items = coalesce($4, total_items),
note = coalesce($5, note),
metadata = coalesce($6, metadata),
updated_at = $7
WHERE id = $8
RETURNING id, invoice_code, type, status, invoice_config_id, total_items, note, created_by, approved_by, completed_at, created_at, updated_at, metadata
`
type UpdateInvoiceParams struct {
Type InvoiceTypeEnum `db:"type" json:"type"`
Status InvoiceStatusEnum `db:"status" json:"status"`
InvoiceConfigID pgtype.Int8 `db:"invoice_config_id" json:"invoiceConfigId"`
TotalItems int32 `db:"total_items" json:"totalItems"`
Note pgtype.Text `db:"note" json:"note"`
Metadata []byte `db:"metadata" json:"metadata"`
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
ID int64 `db:"id" json:"id"`
}
func (q *Queries) UpdateInvoice(ctx context.Context, arg UpdateInvoiceParams) (Invoice, error) {
row := q.db.QueryRow(ctx, updateInvoice,
arg.Type,
arg.Status,
arg.InvoiceConfigID,
arg.TotalItems,
arg.Note,
arg.Metadata,
arg.UpdatedAt,
arg.ID,
)
var i Invoice
err := row.Scan(
&i.ID,
&i.InvoiceCode,
&i.Type,
&i.Status,
&i.InvoiceConfigID,
&i.TotalItems,
&i.Note,
&i.CreatedBy,
&i.ApprovedBy,
&i.CompletedAt,
&i.CreatedAt,
&i.UpdatedAt,
&i.Metadata,
)
return i, err
}

View File

@@ -13,6 +13,7 @@ import (
type Querier interface {
AssignRoleToUser(ctx context.Context, arg AssignRoleToUserParams) (UserRole, error)
CountUsersByRoleID(ctx context.Context, roleID uuid.UUID) (int64, error)
CreateAlternativeComponent(ctx context.Context, arg CreateAlternativeComponentParams) (AlternativeComponent, error)
CreateCabinet(ctx context.Context, arg CreateCabinetParams) (Cabinet, error)
CreateComponent(ctx context.Context, arg CreateComponentParams) (Component, error)
CreateComponentCode(ctx context.Context, arg CreateComponentCodeParams) (ComponentCode, error)
@@ -20,6 +21,7 @@ type Querier interface {
CreateComponentStatusHistory(ctx context.Context, arg CreateComponentStatusHistoryParams) (ComponentStatusHistory, error)
CreateComponentType(ctx context.Context, arg CreateComponentTypeParams) (ComponentType, error)
CreateContainer(ctx context.Context, arg CreateContainerParams) (Container, error)
CreateInvoice(ctx context.Context, arg CreateInvoiceParams) (Invoice, error)
CreateInvoiceConfig(ctx context.Context, arg CreateInvoiceConfigParams) (InvoiceConfig, error)
CreateInvoiceConfigItem(ctx context.Context, arg CreateInvoiceConfigItemParams) (InvoiceConfigItem, error)
CreateRole(ctx context.Context, arg CreateRoleParams) (Role, error)
@@ -27,12 +29,14 @@ type Querier interface {
CreateShelve(ctx context.Context, arg CreateShelveParams) (Shelf, error)
CreateUser(ctx context.Context, arg CreateUserParams) (uuid.UUID, error)
CreateWarehouse(ctx context.Context, arg CreateWarehouseParams) (Warehouse, error)
DeleteAlternativeComponent(ctx context.Context, id int64) (int64, error)
DeleteCabinet(ctx context.Context, id int64) (int64, error)
DeleteComponent(ctx context.Context, id int64) (int64, error)
DeleteComponentCode(ctx context.Context, id int64) (int64, error)
DeleteComponentItem(ctx context.Context, id int64) (int64, error)
DeleteComponentType(ctx context.Context, id int64) (int64, error)
DeleteContainer(ctx context.Context, id int64) (int64, error)
DeleteInvoice(ctx context.Context, id int64) (int64, error)
DeleteInvoiceConfig(ctx context.Context, id int64) (int64, error)
DeleteInvoiceConfigItem(ctx context.Context, id int64) (int64, error)
DeleteRole(ctx context.Context, id uuid.UUID) (int64, error)
@@ -40,6 +44,7 @@ type Querier interface {
DeleteShelve(ctx context.Context, id int64) (int64, error)
DeleteWarehouse(ctx context.Context, id int64) (int64, error)
FindComponentItem(ctx context.Context, componentid int64) ([]FindComponentItemRow, error)
GetAlternativeComponentByID(ctx context.Context, id int64) (AlternativeComponent, error)
GetCabinetByID(ctx context.Context, id int64) (Cabinet, error)
GetComponentByID(ctx context.Context, id int64) (Component, error)
GetComponentCodeByID(ctx context.Context, id int64) (ComponentCode, error)
@@ -47,6 +52,7 @@ type Querier interface {
GetComponentItemByID(ctx context.Context, id int64) (ComponentItem, error)
GetComponentTypeByID(ctx context.Context, id int64) (ComponentType, error)
GetContainerByID(ctx context.Context, id int64) (Container, error)
GetInvoiceByID(ctx context.Context, id int64) (Invoice, error)
GetInvoiceConfigByID(ctx context.Context, id int64) (InvoiceConfig, error)
GetInvoiceConfigItemByID(ctx context.Context, id int64) (InvoiceConfigItem, error)
GetRoleByID(ctx context.Context, id uuid.UUID) (Role, error)
@@ -59,6 +65,7 @@ type Querier interface {
GetUserRolesByRoleID(ctx context.Context, roleID uuid.UUID) ([]GetUserRolesByRoleIDRow, error)
GetUserRolesByUserID(ctx context.Context, userID uuid.UUID) ([]GetUserRolesByUserIDRow, error)
GetWarehouseByID(ctx context.Context, id int64) (Warehouse, error)
ListAlternativeComponents(ctx context.Context) ([]AlternativeComponent, error)
ListCabinets(ctx context.Context) ([]Cabinet, error)
ListComponentCodes(ctx context.Context) ([]ComponentCode, error)
ListComponentItems(ctx context.Context) ([]ComponentItem, error)
@@ -67,12 +74,14 @@ type Querier interface {
ListContainers(ctx context.Context) ([]Container, error)
ListInvoiceConfigItems(ctx context.Context) ([]InvoiceConfigItem, error)
ListInvoiceConfigs(ctx context.Context) ([]InvoiceConfig, error)
ListInvoices(ctx context.Context) ([]Invoice, error)
ListRoles(ctx context.Context) ([]Role, error)
ListRooms(ctx context.Context) ([]Room, error)
ListShelves(ctx context.Context) ([]Shelf, error)
ListWarehouses(ctx context.Context) ([]Warehouse, error)
RemoveAllRolesFromUser(ctx context.Context, userID uuid.UUID) error
RemoveRoleFromUser(ctx context.Context, arg RemoveRoleFromUserParams) error
UpdateAlternativeComponent(ctx context.Context, arg UpdateAlternativeComponentParams) (AlternativeComponent, error)
UpdateCabinet(ctx context.Context, arg UpdateCabinetParams) (Cabinet, error)
UpdateComponent(ctx context.Context, arg UpdateComponentParams) (Component, error)
UpdateComponentCode(ctx context.Context, arg UpdateComponentCodeParams) (ComponentCode, error)
@@ -81,6 +90,7 @@ type Querier interface {
UpdateComponentItemStatus(ctx context.Context, arg UpdateComponentItemStatusParams) (ComponentItem, error)
UpdateComponentType(ctx context.Context, arg UpdateComponentTypeParams) (ComponentType, error)
UpdateContainer(ctx context.Context, arg UpdateContainerParams) (Container, error)
UpdateInvoice(ctx context.Context, arg UpdateInvoiceParams) (Invoice, error)
UpdateInvoiceConfig(ctx context.Context, arg UpdateInvoiceConfigParams) (InvoiceConfig, error)
UpdateInvoiceConfigItem(ctx context.Context, arg UpdateInvoiceConfigItemParams) (InvoiceConfigItem, error)
UpdateRole(ctx context.Context, arg UpdateRoleParams) (Role, error)