// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.30.0 // source: dashboard.sql package db import ( "context" "time" "github.com/jackc/pgx/v5/pgtype" ) const countLowStockComponents = `-- name: CountLowStockComponents :one SELECT COUNT(*) FROM components WHERE total_quantity <= min_quantity ` func (q *Queries) CountLowStockComponents(ctx context.Context) (int64, error) { row := q.db.QueryRow(ctx, countLowStockComponents) var count int64 err := row.Scan(&count) return count, err } const countPendingInvoices = `-- name: CountPendingInvoices :one SELECT COUNT(*) FROM invoices WHERE status IN ('draft', 'pending') ` func (q *Queries) CountPendingInvoices(ctx context.Context) (int64, error) { row := q.db.QueryRow(ctx, countPendingInvoices) var count int64 err := row.Scan(&count) return count, err } const getAbnormalItemCounts = `-- name: GetAbnormalItemCounts :many SELECT ci.status, COUNT(*) AS count FROM component_items ci JOIN containers con ON ci.container_id = con.id JOIN shelves s ON con.shelf_id = s.id JOIN cabinets cab ON s.cabinet_id = cab.id JOIN rooms r ON cab.room_id = r.id WHERE ci.status != 'normal' AND ($1::bigint IS NULL OR r.warehouse_id = $1::bigint) GROUP BY ci.status ` type GetAbnormalItemCountsRow struct { Status ComponentItemStatusEnum `db:"status" json:"status"` Count int64 `db:"count" json:"count"` } func (q *Queries) GetAbnormalItemCounts(ctx context.Context, warehouseID pgtype.Int8) ([]GetAbnormalItemCountsRow, error) { rows, err := q.db.Query(ctx, getAbnormalItemCounts, warehouseID) if err != nil { return nil, err } defer rows.Close() var items []GetAbnormalItemCountsRow for rows.Next() { var i GetAbnormalItemCountsRow if err := rows.Scan(&i.Status, &i.Count); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const getAnomalyItems = `-- name: GetAnomalyItems :many SELECT ci.id, ci.component_id, ci.container_id, ci.quantity, ci.status, ci.created_at, ci.updated_at, c.name AS component_name, c.unit AS component_unit FROM component_items ci JOIN components c ON ci.component_id = c.id JOIN containers con ON ci.container_id = con.id JOIN shelves s ON con.shelf_id = s.id JOIN cabinets cab ON s.cabinet_id = cab.id JOIN rooms r ON cab.room_id = r.id WHERE ci.status != 'normal' AND ($1::bigint IS NULL OR r.warehouse_id = $1::bigint) ORDER BY ci.updated_at DESC ` type GetAnomalyItemsRow struct { ID int64 `db:"id" json:"id"` ComponentID int64 `db:"component_id" json:"componentId"` ContainerID int64 `db:"container_id" json:"containerId"` Quantity int32 `db:"quantity" json:"quantity"` Status ComponentItemStatusEnum `db:"status" json:"status"` CreatedAt time.Time `db:"created_at" json:"createdAt"` UpdatedAt time.Time `db:"updated_at" json:"updatedAt"` ComponentName string `db:"component_name" json:"componentName"` ComponentUnit string `db:"component_unit" json:"componentUnit"` } func (q *Queries) GetAnomalyItems(ctx context.Context, warehouseID pgtype.Int8) ([]GetAnomalyItemsRow, error) { rows, err := q.db.Query(ctx, getAnomalyItems, warehouseID) if err != nil { return nil, err } defer rows.Close() var items []GetAnomalyItemsRow for rows.Next() { var i GetAnomalyItemsRow if err := rows.Scan( &i.ID, &i.ComponentID, &i.ContainerID, &i.Quantity, &i.Status, &i.CreatedAt, &i.UpdatedAt, &i.ComponentName, &i.ComponentUnit, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const getContainerStats = `-- name: GetContainerStats :one SELECT COUNT(*) AS total_containers, COUNT(*) - COUNT(DISTINCT ci.container_id) AS empty_containers FROM containers c JOIN shelves s ON c.shelf_id = s.id JOIN cabinets cab ON s.cabinet_id = cab.id JOIN rooms r ON cab.room_id = r.id LEFT JOIN component_items ci ON c.id = ci.container_id WHERE $1::bigint IS NULL OR r.warehouse_id = $1::bigint ` type GetContainerStatsRow struct { TotalContainers int64 `db:"total_containers" json:"totalContainers"` EmptyContainers int32 `db:"empty_containers" json:"emptyContainers"` } func (q *Queries) GetContainerStats(ctx context.Context, warehouseID pgtype.Int8) (GetContainerStatsRow, error) { row := q.db.QueryRow(ctx, getContainerStats, warehouseID) var i GetContainerStatsRow err := row.Scan(&i.TotalContainers, &i.EmptyContainers) return i, err } const getStockAlerts = `-- name: GetStockAlerts :many SELECT c.id, c.name, c.unit, c.total_quantity, c.min_quantity, c.component_type_id, ct.name AS component_type_name FROM components c LEFT JOIN component_types ct ON c.component_type_id = ct.id WHERE c.total_quantity <= c.min_quantity ORDER BY (c.total_quantity - c.min_quantity) ASC ` type GetStockAlertsRow struct { ID int64 `db:"id" json:"id"` Name string `db:"name" json:"name"` Unit string `db:"unit" json:"unit"` TotalQuantity int32 `db:"total_quantity" json:"totalQuantity"` MinQuantity int32 `db:"min_quantity" json:"minQuantity"` ComponentTypeID int64 `db:"component_type_id" json:"componentTypeId"` ComponentTypeName pgtype.Text `db:"component_type_name" json:"componentTypeName"` } func (q *Queries) GetStockAlerts(ctx context.Context) ([]GetStockAlertsRow, error) { rows, err := q.db.Query(ctx, getStockAlerts) if err != nil { return nil, err } defer rows.Close() var items []GetStockAlertsRow for rows.Next() { var i GetStockAlertsRow if err := rows.Scan( &i.ID, &i.Name, &i.Unit, &i.TotalQuantity, &i.MinQuantity, &i.ComponentTypeID, &i.ComponentTypeName, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const getTodayInvoiceCounts = `-- name: GetTodayInvoiceCounts :many SELECT type, COUNT(*) AS count FROM invoices WHERE created_at::date = CURRENT_DATE GROUP BY type ` type GetTodayInvoiceCountsRow struct { Type InvoiceTypeEnum `db:"type" json:"type"` Count int64 `db:"count" json:"count"` } func (q *Queries) GetTodayInvoiceCounts(ctx context.Context) ([]GetTodayInvoiceCountsRow, error) { rows, err := q.db.Query(ctx, getTodayInvoiceCounts) if err != nil { return nil, err } defer rows.Close() var items []GetTodayInvoiceCountsRow for rows.Next() { var i GetTodayInvoiceCountsRow if err := rows.Scan(&i.Type, &i.Count); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const getTotalComponentStats = `-- name: GetTotalComponentStats :one SELECT COUNT(DISTINCT ci.component_id) AS total_types, COALESCE(SUM(ci.quantity), 0)::bigint AS total_quantity FROM component_items ci JOIN containers con ON ci.container_id = con.id JOIN shelves s ON con.shelf_id = s.id JOIN cabinets cab ON s.cabinet_id = cab.id JOIN rooms r ON cab.room_id = r.id WHERE $1::bigint IS NULL OR r.warehouse_id = $1::bigint ` type GetTotalComponentStatsRow struct { TotalTypes int64 `db:"total_types" json:"totalTypes"` TotalQuantity int64 `db:"total_quantity" json:"totalQuantity"` } func (q *Queries) GetTotalComponentStats(ctx context.Context, warehouseID pgtype.Int8) (GetTotalComponentStatsRow, error) { row := q.db.QueryRow(ctx, getTotalComponentStats, warehouseID) var i GetTotalComponentStatsRow err := row.Scan(&i.TotalTypes, &i.TotalQuantity) return i, err }