2023-03-05 23:35:41 +07:00
|
|
|
// Code generated by sqlc. DO NOT EDIT.
|
|
|
|
// versions:
|
|
|
|
// sqlc v1.17.2
|
|
|
|
// source: purchase_order.sql
|
|
|
|
|
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"database/sql"
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
const createPurchaseOrder = `-- name: CreatePurchaseOrder :one
|
|
|
|
INSERT INTO purchase_order (
|
|
|
|
merchant_id,
|
|
|
|
supplier_id,
|
|
|
|
code,
|
|
|
|
is_paid,
|
|
|
|
total,
|
|
|
|
paid_nominal,
|
2023-03-21 13:15:14 +07:00
|
|
|
note,
|
|
|
|
created_by
|
2023-03-05 23:35:41 +07:00
|
|
|
) VALUES (
|
2023-03-21 13:15:14 +07:00
|
|
|
$1, $2, $3, $4, $5, $6, $7, $8
|
2023-03-05 23:35:41 +07:00
|
|
|
)
|
2023-03-21 13:15:14 +07:00
|
|
|
RETURNING id, supplier_id, merchant_id, index_id, created_by, code, is_paid, total, paid_nominal, note, created_at, updated_at
|
2023-03-05 23:35:41 +07:00
|
|
|
`
|
|
|
|
|
|
|
|
type CreatePurchaseOrderParams struct {
|
|
|
|
MerchantID uuid.UUID `json:"merchant_id"`
|
|
|
|
SupplierID uuid.UUID `json:"supplier_id"`
|
|
|
|
Code sql.NullString `json:"code"`
|
|
|
|
IsPaid bool `json:"is_paid"`
|
|
|
|
Total float64 `json:"total"`
|
|
|
|
PaidNominal float64 `json:"paid_nominal"`
|
|
|
|
Note sql.NullString `json:"note"`
|
2023-03-21 13:15:14 +07:00
|
|
|
CreatedBy uuid.UUID `json:"created_by"`
|
2023-03-05 23:35:41 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) CreatePurchaseOrder(ctx context.Context, arg CreatePurchaseOrderParams) (PurchaseOrder, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, createPurchaseOrder,
|
|
|
|
arg.MerchantID,
|
|
|
|
arg.SupplierID,
|
|
|
|
arg.Code,
|
|
|
|
arg.IsPaid,
|
|
|
|
arg.Total,
|
|
|
|
arg.PaidNominal,
|
|
|
|
arg.Note,
|
2023-03-21 13:15:14 +07:00
|
|
|
arg.CreatedBy,
|
2023-03-05 23:35:41 +07:00
|
|
|
)
|
|
|
|
var i PurchaseOrder
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.SupplierID,
|
|
|
|
&i.MerchantID,
|
|
|
|
&i.IndexID,
|
2023-03-21 13:15:14 +07:00
|
|
|
&i.CreatedBy,
|
2023-03-05 23:35:41 +07:00
|
|
|
&i.Code,
|
|
|
|
&i.IsPaid,
|
|
|
|
&i.Total,
|
|
|
|
&i.PaidNominal,
|
|
|
|
&i.Note,
|
|
|
|
&i.CreatedAt,
|
|
|
|
&i.UpdatedAt,
|
|
|
|
)
|
|
|
|
return i, err
|
|
|
|
}
|
2023-03-16 16:55:45 +07:00
|
|
|
|
|
|
|
const getPurchaseOrderById = `-- name: GetPurchaseOrderById :one
|
2023-03-21 13:15:14 +07:00
|
|
|
SELECT id, supplier_id, merchant_id, index_id, created_by, code, is_paid, total, paid_nominal, note, created_at, updated_at
|
2023-03-16 16:55:45 +07:00
|
|
|
FROM purchase_order
|
|
|
|
WHERE id = $1
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) GetPurchaseOrderById(ctx context.Context, id uuid.UUID) (PurchaseOrder, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, getPurchaseOrderById, id)
|
|
|
|
var i PurchaseOrder
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.SupplierID,
|
|
|
|
&i.MerchantID,
|
|
|
|
&i.IndexID,
|
2023-03-21 13:15:14 +07:00
|
|
|
&i.CreatedBy,
|
2023-03-16 16:55:45 +07:00
|
|
|
&i.Code,
|
|
|
|
&i.IsPaid,
|
|
|
|
&i.Total,
|
|
|
|
&i.PaidNominal,
|
|
|
|
&i.Note,
|
|
|
|
&i.CreatedAt,
|
|
|
|
&i.UpdatedAt,
|
|
|
|
)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
|
|
|
const listPurchaseOrderByMerchantId = `-- name: ListPurchaseOrderByMerchantId :many
|
2023-03-21 13:15:14 +07:00
|
|
|
SELECT id, supplier_id, merchant_id, index_id, created_by, code, is_paid, total, paid_nominal, note, created_at, updated_at
|
2023-03-16 16:55:45 +07:00
|
|
|
FROM purchase_order
|
|
|
|
WHERE merchant_id = $1
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) ListPurchaseOrderByMerchantId(ctx context.Context, merchantID uuid.UUID) ([]PurchaseOrder, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, listPurchaseOrderByMerchantId, merchantID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
items := []PurchaseOrder{}
|
|
|
|
for rows.Next() {
|
|
|
|
var i PurchaseOrder
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.SupplierID,
|
|
|
|
&i.MerchantID,
|
|
|
|
&i.IndexID,
|
2023-03-21 13:15:14 +07:00
|
|
|
&i.CreatedBy,
|
2023-03-16 16:55:45 +07:00
|
|
|
&i.Code,
|
|
|
|
&i.IsPaid,
|
|
|
|
&i.Total,
|
|
|
|
&i.PaidNominal,
|
|
|
|
&i.Note,
|
|
|
|
&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
|
|
|
|
}
|