1060 lines
34 KiB
Go
1060 lines
34 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: enquiries.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"time"
|
|
)
|
|
|
|
const archiveEnquiry = `-- name: ArchiveEnquiry :exec
|
|
UPDATE enquiries SET archived = 1 WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) ArchiveEnquiry(ctx context.Context, id int32) error {
|
|
_, err := q.db.ExecContext(ctx, archiveEnquiry, id)
|
|
return err
|
|
}
|
|
|
|
const countEnquiries = `-- name: CountEnquiries :one
|
|
SELECT COUNT(*) FROM enquiries WHERE archived = 0
|
|
`
|
|
|
|
func (q *Queries) CountEnquiries(ctx context.Context) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, countEnquiries)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const countEnquiriesByPrinciple = `-- name: CountEnquiriesByPrinciple :one
|
|
SELECT COUNT(*) FROM enquiries WHERE principle_code = ?
|
|
`
|
|
|
|
func (q *Queries) CountEnquiriesByPrinciple(ctx context.Context, principleCode int32) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, countEnquiriesByPrinciple, principleCode)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const countEnquiriesByPrincipleAndState = `-- name: CountEnquiriesByPrincipleAndState :one
|
|
SELECT COUNT(*) FROM enquiries WHERE principle_code = ? AND state_id = ?
|
|
`
|
|
|
|
type CountEnquiriesByPrincipleAndStateParams struct {
|
|
PrincipleCode int32 `json:"principle_code"`
|
|
StateID int32 `json:"state_id"`
|
|
}
|
|
|
|
func (q *Queries) CountEnquiriesByPrincipleAndState(ctx context.Context, arg CountEnquiriesByPrincipleAndStateParams) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, countEnquiriesByPrincipleAndState, arg.PrincipleCode, arg.StateID)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const countEnquiriesByStatus = `-- name: CountEnquiriesByStatus :one
|
|
SELECT COUNT(*) FROM enquiries WHERE status_id = ? AND archived = 0
|
|
`
|
|
|
|
func (q *Queries) CountEnquiriesByStatus(ctx context.Context, statusID int32) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, countEnquiriesByStatus, statusID)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createEnquiry = `-- name: CreateEnquiry :execresult
|
|
INSERT INTO enquiries (
|
|
created, title, user_id, customer_id, contact_id, contact_user_id,
|
|
state_id, country_id, principle_id, status_id, comments,
|
|
principle_code, gst, billing_address_id, shipping_address_id,
|
|
posted, archived
|
|
) VALUES (
|
|
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
|
)
|
|
`
|
|
|
|
type CreateEnquiryParams struct {
|
|
Created time.Time `json:"created"`
|
|
Title string `json:"title"`
|
|
UserID int32 `json:"user_id"`
|
|
CustomerID int32 `json:"customer_id"`
|
|
ContactID int32 `json:"contact_id"`
|
|
ContactUserID int32 `json:"contact_user_id"`
|
|
StateID int32 `json:"state_id"`
|
|
CountryID int32 `json:"country_id"`
|
|
PrincipleID int32 `json:"principle_id"`
|
|
StatusID int32 `json:"status_id"`
|
|
Comments string `json:"comments"`
|
|
PrincipleCode int32 `json:"principle_code"`
|
|
Gst bool `json:"gst"`
|
|
BillingAddressID sql.NullInt32 `json:"billing_address_id"`
|
|
ShippingAddressID sql.NullInt32 `json:"shipping_address_id"`
|
|
Posted bool `json:"posted"`
|
|
Archived int8 `json:"archived"`
|
|
}
|
|
|
|
func (q *Queries) CreateEnquiry(ctx context.Context, arg CreateEnquiryParams) (sql.Result, error) {
|
|
return q.db.ExecContext(ctx, createEnquiry,
|
|
arg.Created,
|
|
arg.Title,
|
|
arg.UserID,
|
|
arg.CustomerID,
|
|
arg.ContactID,
|
|
arg.ContactUserID,
|
|
arg.StateID,
|
|
arg.CountryID,
|
|
arg.PrincipleID,
|
|
arg.StatusID,
|
|
arg.Comments,
|
|
arg.PrincipleCode,
|
|
arg.Gst,
|
|
arg.BillingAddressID,
|
|
arg.ShippingAddressID,
|
|
arg.Posted,
|
|
arg.Archived,
|
|
)
|
|
}
|
|
|
|
const getAllCountries = `-- name: GetAllCountries :many
|
|
SELECT id, name FROM countries ORDER BY name
|
|
`
|
|
|
|
func (q *Queries) GetAllCountries(ctx context.Context) ([]Country, error) {
|
|
rows, err := q.db.QueryContext(ctx, getAllCountries)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Country{}
|
|
for rows.Next() {
|
|
var i Country
|
|
if err := rows.Scan(&i.ID, &i.Name); 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 getAllPrinciples = `-- name: GetAllPrinciples :many
|
|
SELECT id, name, short_name, code FROM principles ORDER BY name
|
|
`
|
|
|
|
func (q *Queries) GetAllPrinciples(ctx context.Context) ([]Principle, error) {
|
|
rows, err := q.db.QueryContext(ctx, getAllPrinciples)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Principle{}
|
|
for rows.Next() {
|
|
var i Principle
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.ShortName,
|
|
&i.Code,
|
|
); 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 getAllStates = `-- name: GetAllStates :many
|
|
SELECT id, name, shortform, enqform FROM states ORDER BY name
|
|
`
|
|
|
|
func (q *Queries) GetAllStates(ctx context.Context) ([]State, error) {
|
|
rows, err := q.db.QueryContext(ctx, getAllStates)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []State{}
|
|
for rows.Next() {
|
|
var i State
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Shortform,
|
|
&i.Enqform,
|
|
); 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 getAllStatuses = `-- name: GetAllStatuses :many
|
|
SELECT id, name FROM statuses ORDER BY name
|
|
`
|
|
|
|
type GetAllStatusesRow struct {
|
|
ID int32 `json:"id"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
func (q *Queries) GetAllStatuses(ctx context.Context) ([]GetAllStatusesRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, getAllStatuses)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []GetAllStatusesRow{}
|
|
for rows.Next() {
|
|
var i GetAllStatusesRow
|
|
if err := rows.Scan(&i.ID, &i.Name); 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 getEnquiriesByCustomer = `-- name: GetEnquiriesByCustomer :many
|
|
SELECT e.id, e.created, e.submitted, e.title, e.user_id, e.customer_id, e.contact_id, e.contact_user_id, e.state_id, e.country_id, e.principle_id, e.status_id, e.comments, e.principle_code, e.gst, e.billing_address_id, e.shipping_address_id, e.posted, e.email_count, e.invoice_count, e.job_count, e.quote_count, e.archived,
|
|
u.first_name as user_first_name,
|
|
u.last_name as user_last_name,
|
|
c.name as customer_name,
|
|
contact.first_name as contact_first_name,
|
|
contact.last_name as contact_last_name,
|
|
s.name as status_name,
|
|
p.name as principle_name,
|
|
p.short_name as principle_short_name
|
|
FROM enquiries e
|
|
LEFT JOIN users u ON e.user_id = u.id
|
|
LEFT JOIN customers c ON e.customer_id = c.id
|
|
LEFT JOIN users contact ON e.contact_user_id = contact.id
|
|
LEFT JOIN statuses s ON e.status_id = s.id
|
|
LEFT JOIN principles p ON e.principle_id = p.id
|
|
WHERE e.customer_id = ? AND e.archived = 0
|
|
ORDER BY e.id DESC
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type GetEnquiriesByCustomerParams struct {
|
|
CustomerID int32 `json:"customer_id"`
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
type GetEnquiriesByCustomerRow struct {
|
|
ID int32 `json:"id"`
|
|
Created time.Time `json:"created"`
|
|
Submitted sql.NullTime `json:"submitted"`
|
|
Title string `json:"title"`
|
|
UserID int32 `json:"user_id"`
|
|
CustomerID int32 `json:"customer_id"`
|
|
ContactID int32 `json:"contact_id"`
|
|
ContactUserID int32 `json:"contact_user_id"`
|
|
StateID int32 `json:"state_id"`
|
|
CountryID int32 `json:"country_id"`
|
|
PrincipleID int32 `json:"principle_id"`
|
|
StatusID int32 `json:"status_id"`
|
|
Comments string `json:"comments"`
|
|
PrincipleCode int32 `json:"principle_code"`
|
|
Gst bool `json:"gst"`
|
|
BillingAddressID sql.NullInt32 `json:"billing_address_id"`
|
|
ShippingAddressID sql.NullInt32 `json:"shipping_address_id"`
|
|
Posted bool `json:"posted"`
|
|
EmailCount int32 `json:"email_count"`
|
|
InvoiceCount int32 `json:"invoice_count"`
|
|
JobCount int32 `json:"job_count"`
|
|
QuoteCount int32 `json:"quote_count"`
|
|
Archived int8 `json:"archived"`
|
|
UserFirstName sql.NullString `json:"user_first_name"`
|
|
UserLastName sql.NullString `json:"user_last_name"`
|
|
CustomerName sql.NullString `json:"customer_name"`
|
|
ContactFirstName sql.NullString `json:"contact_first_name"`
|
|
ContactLastName sql.NullString `json:"contact_last_name"`
|
|
StatusName sql.NullString `json:"status_name"`
|
|
PrincipleName sql.NullString `json:"principle_name"`
|
|
PrincipleShortName sql.NullString `json:"principle_short_name"`
|
|
}
|
|
|
|
func (q *Queries) GetEnquiriesByCustomer(ctx context.Context, arg GetEnquiriesByCustomerParams) ([]GetEnquiriesByCustomerRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, getEnquiriesByCustomer, arg.CustomerID, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []GetEnquiriesByCustomerRow{}
|
|
for rows.Next() {
|
|
var i GetEnquiriesByCustomerRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Created,
|
|
&i.Submitted,
|
|
&i.Title,
|
|
&i.UserID,
|
|
&i.CustomerID,
|
|
&i.ContactID,
|
|
&i.ContactUserID,
|
|
&i.StateID,
|
|
&i.CountryID,
|
|
&i.PrincipleID,
|
|
&i.StatusID,
|
|
&i.Comments,
|
|
&i.PrincipleCode,
|
|
&i.Gst,
|
|
&i.BillingAddressID,
|
|
&i.ShippingAddressID,
|
|
&i.Posted,
|
|
&i.EmailCount,
|
|
&i.InvoiceCount,
|
|
&i.JobCount,
|
|
&i.QuoteCount,
|
|
&i.Archived,
|
|
&i.UserFirstName,
|
|
&i.UserLastName,
|
|
&i.CustomerName,
|
|
&i.ContactFirstName,
|
|
&i.ContactLastName,
|
|
&i.StatusName,
|
|
&i.PrincipleName,
|
|
&i.PrincipleShortName,
|
|
); 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 getEnquiriesByUser = `-- name: GetEnquiriesByUser :many
|
|
SELECT e.id, e.created, e.submitted, e.title, e.user_id, e.customer_id, e.contact_id, e.contact_user_id, e.state_id, e.country_id, e.principle_id, e.status_id, e.comments, e.principle_code, e.gst, e.billing_address_id, e.shipping_address_id, e.posted, e.email_count, e.invoice_count, e.job_count, e.quote_count, e.archived,
|
|
u.first_name as user_first_name,
|
|
u.last_name as user_last_name,
|
|
c.name as customer_name,
|
|
contact.first_name as contact_first_name,
|
|
contact.last_name as contact_last_name,
|
|
s.name as status_name,
|
|
p.name as principle_name,
|
|
p.short_name as principle_short_name
|
|
FROM enquiries e
|
|
LEFT JOIN users u ON e.user_id = u.id
|
|
LEFT JOIN customers c ON e.customer_id = c.id
|
|
LEFT JOIN users contact ON e.contact_user_id = contact.id
|
|
LEFT JOIN statuses s ON e.status_id = s.id
|
|
LEFT JOIN principles p ON e.principle_id = p.id
|
|
WHERE e.user_id = ? AND e.archived = 0
|
|
ORDER BY e.id DESC
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type GetEnquiriesByUserParams struct {
|
|
UserID int32 `json:"user_id"`
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
type GetEnquiriesByUserRow struct {
|
|
ID int32 `json:"id"`
|
|
Created time.Time `json:"created"`
|
|
Submitted sql.NullTime `json:"submitted"`
|
|
Title string `json:"title"`
|
|
UserID int32 `json:"user_id"`
|
|
CustomerID int32 `json:"customer_id"`
|
|
ContactID int32 `json:"contact_id"`
|
|
ContactUserID int32 `json:"contact_user_id"`
|
|
StateID int32 `json:"state_id"`
|
|
CountryID int32 `json:"country_id"`
|
|
PrincipleID int32 `json:"principle_id"`
|
|
StatusID int32 `json:"status_id"`
|
|
Comments string `json:"comments"`
|
|
PrincipleCode int32 `json:"principle_code"`
|
|
Gst bool `json:"gst"`
|
|
BillingAddressID sql.NullInt32 `json:"billing_address_id"`
|
|
ShippingAddressID sql.NullInt32 `json:"shipping_address_id"`
|
|
Posted bool `json:"posted"`
|
|
EmailCount int32 `json:"email_count"`
|
|
InvoiceCount int32 `json:"invoice_count"`
|
|
JobCount int32 `json:"job_count"`
|
|
QuoteCount int32 `json:"quote_count"`
|
|
Archived int8 `json:"archived"`
|
|
UserFirstName sql.NullString `json:"user_first_name"`
|
|
UserLastName sql.NullString `json:"user_last_name"`
|
|
CustomerName sql.NullString `json:"customer_name"`
|
|
ContactFirstName sql.NullString `json:"contact_first_name"`
|
|
ContactLastName sql.NullString `json:"contact_last_name"`
|
|
StatusName sql.NullString `json:"status_name"`
|
|
PrincipleName sql.NullString `json:"principle_name"`
|
|
PrincipleShortName sql.NullString `json:"principle_short_name"`
|
|
}
|
|
|
|
func (q *Queries) GetEnquiriesByUser(ctx context.Context, arg GetEnquiriesByUserParams) ([]GetEnquiriesByUserRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, getEnquiriesByUser, arg.UserID, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []GetEnquiriesByUserRow{}
|
|
for rows.Next() {
|
|
var i GetEnquiriesByUserRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Created,
|
|
&i.Submitted,
|
|
&i.Title,
|
|
&i.UserID,
|
|
&i.CustomerID,
|
|
&i.ContactID,
|
|
&i.ContactUserID,
|
|
&i.StateID,
|
|
&i.CountryID,
|
|
&i.PrincipleID,
|
|
&i.StatusID,
|
|
&i.Comments,
|
|
&i.PrincipleCode,
|
|
&i.Gst,
|
|
&i.BillingAddressID,
|
|
&i.ShippingAddressID,
|
|
&i.Posted,
|
|
&i.EmailCount,
|
|
&i.InvoiceCount,
|
|
&i.JobCount,
|
|
&i.QuoteCount,
|
|
&i.Archived,
|
|
&i.UserFirstName,
|
|
&i.UserLastName,
|
|
&i.CustomerName,
|
|
&i.ContactFirstName,
|
|
&i.ContactLastName,
|
|
&i.StatusName,
|
|
&i.PrincipleName,
|
|
&i.PrincipleShortName,
|
|
); 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 getEnquiry = `-- name: GetEnquiry :one
|
|
SELECT e.id, e.created, e.submitted, e.title, e.user_id, e.customer_id, e.contact_id, e.contact_user_id, e.state_id, e.country_id, e.principle_id, e.status_id, e.comments, e.principle_code, e.gst, e.billing_address_id, e.shipping_address_id, e.posted, e.email_count, e.invoice_count, e.job_count, e.quote_count, e.archived,
|
|
u.first_name as user_first_name,
|
|
u.last_name as user_last_name,
|
|
c.name as customer_name,
|
|
contact.first_name as contact_first_name,
|
|
contact.last_name as contact_last_name,
|
|
contact.email as contact_email,
|
|
contact.mobile as contact_mobile,
|
|
contact.direct_phone as contact_direct_phone,
|
|
contact.phone as contact_phone,
|
|
contact.phone_extension as contact_phone_extension,
|
|
s.name as status_name,
|
|
p.name as principle_name,
|
|
p.short_name as principle_short_name,
|
|
st.name as state_name,
|
|
st.shortform as state_shortform,
|
|
co.name as country_name
|
|
FROM enquiries e
|
|
LEFT JOIN users u ON e.user_id = u.id
|
|
LEFT JOIN customers c ON e.customer_id = c.id
|
|
LEFT JOIN users contact ON e.contact_user_id = contact.id
|
|
LEFT JOIN statuses s ON e.status_id = s.id
|
|
LEFT JOIN principles p ON e.principle_id = p.id
|
|
LEFT JOIN states st ON e.state_id = st.id
|
|
LEFT JOIN countries co ON e.country_id = co.id
|
|
WHERE e.id = ?
|
|
`
|
|
|
|
type GetEnquiryRow struct {
|
|
ID int32 `json:"id"`
|
|
Created time.Time `json:"created"`
|
|
Submitted sql.NullTime `json:"submitted"`
|
|
Title string `json:"title"`
|
|
UserID int32 `json:"user_id"`
|
|
CustomerID int32 `json:"customer_id"`
|
|
ContactID int32 `json:"contact_id"`
|
|
ContactUserID int32 `json:"contact_user_id"`
|
|
StateID int32 `json:"state_id"`
|
|
CountryID int32 `json:"country_id"`
|
|
PrincipleID int32 `json:"principle_id"`
|
|
StatusID int32 `json:"status_id"`
|
|
Comments string `json:"comments"`
|
|
PrincipleCode int32 `json:"principle_code"`
|
|
Gst bool `json:"gst"`
|
|
BillingAddressID sql.NullInt32 `json:"billing_address_id"`
|
|
ShippingAddressID sql.NullInt32 `json:"shipping_address_id"`
|
|
Posted bool `json:"posted"`
|
|
EmailCount int32 `json:"email_count"`
|
|
InvoiceCount int32 `json:"invoice_count"`
|
|
JobCount int32 `json:"job_count"`
|
|
QuoteCount int32 `json:"quote_count"`
|
|
Archived int8 `json:"archived"`
|
|
UserFirstName sql.NullString `json:"user_first_name"`
|
|
UserLastName sql.NullString `json:"user_last_name"`
|
|
CustomerName sql.NullString `json:"customer_name"`
|
|
ContactFirstName sql.NullString `json:"contact_first_name"`
|
|
ContactLastName sql.NullString `json:"contact_last_name"`
|
|
ContactEmail sql.NullString `json:"contact_email"`
|
|
ContactMobile sql.NullString `json:"contact_mobile"`
|
|
ContactDirectPhone sql.NullString `json:"contact_direct_phone"`
|
|
ContactPhone sql.NullString `json:"contact_phone"`
|
|
ContactPhoneExtension sql.NullString `json:"contact_phone_extension"`
|
|
StatusName sql.NullString `json:"status_name"`
|
|
PrincipleName sql.NullString `json:"principle_name"`
|
|
PrincipleShortName sql.NullString `json:"principle_short_name"`
|
|
StateName sql.NullString `json:"state_name"`
|
|
StateShortform sql.NullString `json:"state_shortform"`
|
|
CountryName sql.NullString `json:"country_name"`
|
|
}
|
|
|
|
func (q *Queries) GetEnquiry(ctx context.Context, id int32) (GetEnquiryRow, error) {
|
|
row := q.db.QueryRowContext(ctx, getEnquiry, id)
|
|
var i GetEnquiryRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Created,
|
|
&i.Submitted,
|
|
&i.Title,
|
|
&i.UserID,
|
|
&i.CustomerID,
|
|
&i.ContactID,
|
|
&i.ContactUserID,
|
|
&i.StateID,
|
|
&i.CountryID,
|
|
&i.PrincipleID,
|
|
&i.StatusID,
|
|
&i.Comments,
|
|
&i.PrincipleCode,
|
|
&i.Gst,
|
|
&i.BillingAddressID,
|
|
&i.ShippingAddressID,
|
|
&i.Posted,
|
|
&i.EmailCount,
|
|
&i.InvoiceCount,
|
|
&i.JobCount,
|
|
&i.QuoteCount,
|
|
&i.Archived,
|
|
&i.UserFirstName,
|
|
&i.UserLastName,
|
|
&i.CustomerName,
|
|
&i.ContactFirstName,
|
|
&i.ContactLastName,
|
|
&i.ContactEmail,
|
|
&i.ContactMobile,
|
|
&i.ContactDirectPhone,
|
|
&i.ContactPhone,
|
|
&i.ContactPhoneExtension,
|
|
&i.StatusName,
|
|
&i.PrincipleName,
|
|
&i.PrincipleShortName,
|
|
&i.StateName,
|
|
&i.StateShortform,
|
|
&i.CountryName,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listArchivedEnquiries = `-- name: ListArchivedEnquiries :many
|
|
SELECT e.id, e.created, e.submitted, e.title, e.user_id, e.customer_id, e.contact_id, e.contact_user_id, e.state_id, e.country_id, e.principle_id, e.status_id, e.comments, e.principle_code, e.gst, e.billing_address_id, e.shipping_address_id, e.posted, e.email_count, e.invoice_count, e.job_count, e.quote_count, e.archived,
|
|
u.first_name as user_first_name,
|
|
u.last_name as user_last_name,
|
|
c.name as customer_name,
|
|
contact.first_name as contact_first_name,
|
|
contact.last_name as contact_last_name,
|
|
s.name as status_name,
|
|
p.name as principle_name,
|
|
p.short_name as principle_short_name
|
|
FROM enquiries e
|
|
LEFT JOIN users u ON e.user_id = u.id
|
|
LEFT JOIN customers c ON e.customer_id = c.id
|
|
LEFT JOIN users contact ON e.contact_user_id = contact.id
|
|
LEFT JOIN statuses s ON e.status_id = s.id
|
|
LEFT JOIN principles p ON e.principle_id = p.id
|
|
WHERE e.archived = 1
|
|
ORDER BY e.id DESC
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type ListArchivedEnquiriesParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
type ListArchivedEnquiriesRow struct {
|
|
ID int32 `json:"id"`
|
|
Created time.Time `json:"created"`
|
|
Submitted sql.NullTime `json:"submitted"`
|
|
Title string `json:"title"`
|
|
UserID int32 `json:"user_id"`
|
|
CustomerID int32 `json:"customer_id"`
|
|
ContactID int32 `json:"contact_id"`
|
|
ContactUserID int32 `json:"contact_user_id"`
|
|
StateID int32 `json:"state_id"`
|
|
CountryID int32 `json:"country_id"`
|
|
PrincipleID int32 `json:"principle_id"`
|
|
StatusID int32 `json:"status_id"`
|
|
Comments string `json:"comments"`
|
|
PrincipleCode int32 `json:"principle_code"`
|
|
Gst bool `json:"gst"`
|
|
BillingAddressID sql.NullInt32 `json:"billing_address_id"`
|
|
ShippingAddressID sql.NullInt32 `json:"shipping_address_id"`
|
|
Posted bool `json:"posted"`
|
|
EmailCount int32 `json:"email_count"`
|
|
InvoiceCount int32 `json:"invoice_count"`
|
|
JobCount int32 `json:"job_count"`
|
|
QuoteCount int32 `json:"quote_count"`
|
|
Archived int8 `json:"archived"`
|
|
UserFirstName sql.NullString `json:"user_first_name"`
|
|
UserLastName sql.NullString `json:"user_last_name"`
|
|
CustomerName sql.NullString `json:"customer_name"`
|
|
ContactFirstName sql.NullString `json:"contact_first_name"`
|
|
ContactLastName sql.NullString `json:"contact_last_name"`
|
|
StatusName sql.NullString `json:"status_name"`
|
|
PrincipleName sql.NullString `json:"principle_name"`
|
|
PrincipleShortName sql.NullString `json:"principle_short_name"`
|
|
}
|
|
|
|
func (q *Queries) ListArchivedEnquiries(ctx context.Context, arg ListArchivedEnquiriesParams) ([]ListArchivedEnquiriesRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, listArchivedEnquiries, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListArchivedEnquiriesRow{}
|
|
for rows.Next() {
|
|
var i ListArchivedEnquiriesRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Created,
|
|
&i.Submitted,
|
|
&i.Title,
|
|
&i.UserID,
|
|
&i.CustomerID,
|
|
&i.ContactID,
|
|
&i.ContactUserID,
|
|
&i.StateID,
|
|
&i.CountryID,
|
|
&i.PrincipleID,
|
|
&i.StatusID,
|
|
&i.Comments,
|
|
&i.PrincipleCode,
|
|
&i.Gst,
|
|
&i.BillingAddressID,
|
|
&i.ShippingAddressID,
|
|
&i.Posted,
|
|
&i.EmailCount,
|
|
&i.InvoiceCount,
|
|
&i.JobCount,
|
|
&i.QuoteCount,
|
|
&i.Archived,
|
|
&i.UserFirstName,
|
|
&i.UserLastName,
|
|
&i.CustomerName,
|
|
&i.ContactFirstName,
|
|
&i.ContactLastName,
|
|
&i.StatusName,
|
|
&i.PrincipleName,
|
|
&i.PrincipleShortName,
|
|
); 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 listEnquiries = `-- name: ListEnquiries :many
|
|
SELECT e.id, e.created, e.submitted, e.title, e.user_id, e.customer_id, e.contact_id, e.contact_user_id, e.state_id, e.country_id, e.principle_id, e.status_id, e.comments, e.principle_code, e.gst, e.billing_address_id, e.shipping_address_id, e.posted, e.email_count, e.invoice_count, e.job_count, e.quote_count, e.archived,
|
|
u.first_name as user_first_name,
|
|
u.last_name as user_last_name,
|
|
c.name as customer_name,
|
|
contact.first_name as contact_first_name,
|
|
contact.last_name as contact_last_name,
|
|
contact.email as contact_email,
|
|
contact.mobile as contact_mobile,
|
|
contact.direct_phone as contact_direct_phone,
|
|
contact.phone as contact_phone,
|
|
contact.phone_extension as contact_phone_extension,
|
|
s.name as status_name,
|
|
p.name as principle_name,
|
|
p.short_name as principle_short_name
|
|
FROM enquiries e
|
|
LEFT JOIN users u ON e.user_id = u.id
|
|
LEFT JOIN customers c ON e.customer_id = c.id
|
|
LEFT JOIN users contact ON e.contact_user_id = contact.id
|
|
LEFT JOIN statuses s ON e.status_id = s.id
|
|
LEFT JOIN principles p ON e.principle_id = p.id
|
|
WHERE e.archived = 0
|
|
ORDER BY e.id DESC
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type ListEnquiriesParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
type ListEnquiriesRow struct {
|
|
ID int32 `json:"id"`
|
|
Created time.Time `json:"created"`
|
|
Submitted sql.NullTime `json:"submitted"`
|
|
Title string `json:"title"`
|
|
UserID int32 `json:"user_id"`
|
|
CustomerID int32 `json:"customer_id"`
|
|
ContactID int32 `json:"contact_id"`
|
|
ContactUserID int32 `json:"contact_user_id"`
|
|
StateID int32 `json:"state_id"`
|
|
CountryID int32 `json:"country_id"`
|
|
PrincipleID int32 `json:"principle_id"`
|
|
StatusID int32 `json:"status_id"`
|
|
Comments string `json:"comments"`
|
|
PrincipleCode int32 `json:"principle_code"`
|
|
Gst bool `json:"gst"`
|
|
BillingAddressID sql.NullInt32 `json:"billing_address_id"`
|
|
ShippingAddressID sql.NullInt32 `json:"shipping_address_id"`
|
|
Posted bool `json:"posted"`
|
|
EmailCount int32 `json:"email_count"`
|
|
InvoiceCount int32 `json:"invoice_count"`
|
|
JobCount int32 `json:"job_count"`
|
|
QuoteCount int32 `json:"quote_count"`
|
|
Archived int8 `json:"archived"`
|
|
UserFirstName sql.NullString `json:"user_first_name"`
|
|
UserLastName sql.NullString `json:"user_last_name"`
|
|
CustomerName sql.NullString `json:"customer_name"`
|
|
ContactFirstName sql.NullString `json:"contact_first_name"`
|
|
ContactLastName sql.NullString `json:"contact_last_name"`
|
|
ContactEmail sql.NullString `json:"contact_email"`
|
|
ContactMobile sql.NullString `json:"contact_mobile"`
|
|
ContactDirectPhone sql.NullString `json:"contact_direct_phone"`
|
|
ContactPhone sql.NullString `json:"contact_phone"`
|
|
ContactPhoneExtension sql.NullString `json:"contact_phone_extension"`
|
|
StatusName sql.NullString `json:"status_name"`
|
|
PrincipleName sql.NullString `json:"principle_name"`
|
|
PrincipleShortName sql.NullString `json:"principle_short_name"`
|
|
}
|
|
|
|
func (q *Queries) ListEnquiries(ctx context.Context, arg ListEnquiriesParams) ([]ListEnquiriesRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, listEnquiries, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListEnquiriesRow{}
|
|
for rows.Next() {
|
|
var i ListEnquiriesRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Created,
|
|
&i.Submitted,
|
|
&i.Title,
|
|
&i.UserID,
|
|
&i.CustomerID,
|
|
&i.ContactID,
|
|
&i.ContactUserID,
|
|
&i.StateID,
|
|
&i.CountryID,
|
|
&i.PrincipleID,
|
|
&i.StatusID,
|
|
&i.Comments,
|
|
&i.PrincipleCode,
|
|
&i.Gst,
|
|
&i.BillingAddressID,
|
|
&i.ShippingAddressID,
|
|
&i.Posted,
|
|
&i.EmailCount,
|
|
&i.InvoiceCount,
|
|
&i.JobCount,
|
|
&i.QuoteCount,
|
|
&i.Archived,
|
|
&i.UserFirstName,
|
|
&i.UserLastName,
|
|
&i.CustomerName,
|
|
&i.ContactFirstName,
|
|
&i.ContactLastName,
|
|
&i.ContactEmail,
|
|
&i.ContactMobile,
|
|
&i.ContactDirectPhone,
|
|
&i.ContactPhone,
|
|
&i.ContactPhoneExtension,
|
|
&i.StatusName,
|
|
&i.PrincipleName,
|
|
&i.PrincipleShortName,
|
|
); 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 markEnquirySubmitted = `-- name: MarkEnquirySubmitted :exec
|
|
UPDATE enquiries SET submitted = ? WHERE id = ?
|
|
`
|
|
|
|
type MarkEnquirySubmittedParams struct {
|
|
Submitted sql.NullTime `json:"submitted"`
|
|
ID int32 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) MarkEnquirySubmitted(ctx context.Context, arg MarkEnquirySubmittedParams) error {
|
|
_, err := q.db.ExecContext(ctx, markEnquirySubmitted, arg.Submitted, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const searchEnquiries = `-- name: SearchEnquiries :many
|
|
SELECT e.id, e.created, e.submitted, e.title, e.user_id, e.customer_id, e.contact_id, e.contact_user_id, e.state_id, e.country_id, e.principle_id, e.status_id, e.comments, e.principle_code, e.gst, e.billing_address_id, e.shipping_address_id, e.posted, e.email_count, e.invoice_count, e.job_count, e.quote_count, e.archived,
|
|
u.first_name as user_first_name,
|
|
u.last_name as user_last_name,
|
|
c.name as customer_name,
|
|
contact.first_name as contact_first_name,
|
|
contact.last_name as contact_last_name,
|
|
s.name as status_name,
|
|
p.name as principle_name,
|
|
p.short_name as principle_short_name
|
|
FROM enquiries e
|
|
LEFT JOIN users u ON e.user_id = u.id
|
|
LEFT JOIN customers c ON e.customer_id = c.id
|
|
LEFT JOIN users contact ON e.contact_user_id = contact.id
|
|
LEFT JOIN statuses s ON e.status_id = s.id
|
|
LEFT JOIN principles p ON e.principle_id = p.id
|
|
WHERE e.archived = 0
|
|
AND (
|
|
e.title LIKE CONCAT('%', ?, '%') OR
|
|
c.name LIKE CONCAT('%', ?, '%') OR
|
|
CONCAT(contact.first_name, ' ', contact.last_name) LIKE CONCAT('%', ?, '%')
|
|
)
|
|
ORDER BY e.id DESC
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type SearchEnquiriesParams struct {
|
|
CONCAT interface{} `json:"CONCAT"`
|
|
CONCAT_2 interface{} `json:"CONCAT_2"`
|
|
CONCAT_3 interface{} `json:"CONCAT_3"`
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
type SearchEnquiriesRow struct {
|
|
ID int32 `json:"id"`
|
|
Created time.Time `json:"created"`
|
|
Submitted sql.NullTime `json:"submitted"`
|
|
Title string `json:"title"`
|
|
UserID int32 `json:"user_id"`
|
|
CustomerID int32 `json:"customer_id"`
|
|
ContactID int32 `json:"contact_id"`
|
|
ContactUserID int32 `json:"contact_user_id"`
|
|
StateID int32 `json:"state_id"`
|
|
CountryID int32 `json:"country_id"`
|
|
PrincipleID int32 `json:"principle_id"`
|
|
StatusID int32 `json:"status_id"`
|
|
Comments string `json:"comments"`
|
|
PrincipleCode int32 `json:"principle_code"`
|
|
Gst bool `json:"gst"`
|
|
BillingAddressID sql.NullInt32 `json:"billing_address_id"`
|
|
ShippingAddressID sql.NullInt32 `json:"shipping_address_id"`
|
|
Posted bool `json:"posted"`
|
|
EmailCount int32 `json:"email_count"`
|
|
InvoiceCount int32 `json:"invoice_count"`
|
|
JobCount int32 `json:"job_count"`
|
|
QuoteCount int32 `json:"quote_count"`
|
|
Archived int8 `json:"archived"`
|
|
UserFirstName sql.NullString `json:"user_first_name"`
|
|
UserLastName sql.NullString `json:"user_last_name"`
|
|
CustomerName sql.NullString `json:"customer_name"`
|
|
ContactFirstName sql.NullString `json:"contact_first_name"`
|
|
ContactLastName sql.NullString `json:"contact_last_name"`
|
|
StatusName sql.NullString `json:"status_name"`
|
|
PrincipleName sql.NullString `json:"principle_name"`
|
|
PrincipleShortName sql.NullString `json:"principle_short_name"`
|
|
}
|
|
|
|
func (q *Queries) SearchEnquiries(ctx context.Context, arg SearchEnquiriesParams) ([]SearchEnquiriesRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, searchEnquiries,
|
|
arg.CONCAT,
|
|
arg.CONCAT_2,
|
|
arg.CONCAT_3,
|
|
arg.Limit,
|
|
arg.Offset,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []SearchEnquiriesRow{}
|
|
for rows.Next() {
|
|
var i SearchEnquiriesRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Created,
|
|
&i.Submitted,
|
|
&i.Title,
|
|
&i.UserID,
|
|
&i.CustomerID,
|
|
&i.ContactID,
|
|
&i.ContactUserID,
|
|
&i.StateID,
|
|
&i.CountryID,
|
|
&i.PrincipleID,
|
|
&i.StatusID,
|
|
&i.Comments,
|
|
&i.PrincipleCode,
|
|
&i.Gst,
|
|
&i.BillingAddressID,
|
|
&i.ShippingAddressID,
|
|
&i.Posted,
|
|
&i.EmailCount,
|
|
&i.InvoiceCount,
|
|
&i.JobCount,
|
|
&i.QuoteCount,
|
|
&i.Archived,
|
|
&i.UserFirstName,
|
|
&i.UserLastName,
|
|
&i.CustomerName,
|
|
&i.ContactFirstName,
|
|
&i.ContactLastName,
|
|
&i.StatusName,
|
|
&i.PrincipleName,
|
|
&i.PrincipleShortName,
|
|
); 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 unarchiveEnquiry = `-- name: UnarchiveEnquiry :exec
|
|
UPDATE enquiries SET archived = 0 WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) UnarchiveEnquiry(ctx context.Context, id int32) error {
|
|
_, err := q.db.ExecContext(ctx, unarchiveEnquiry, id)
|
|
return err
|
|
}
|
|
|
|
const updateEnquiry = `-- name: UpdateEnquiry :exec
|
|
UPDATE enquiries
|
|
SET title = ?, user_id = ?, customer_id = ?, contact_id = ?, contact_user_id = ?,
|
|
state_id = ?, country_id = ?, principle_id = ?, status_id = ?, comments = ?,
|
|
principle_code = ?, gst = ?, billing_address_id = ?, shipping_address_id = ?,
|
|
posted = ?, submitted = ?
|
|
WHERE id = ?
|
|
`
|
|
|
|
type UpdateEnquiryParams struct {
|
|
Title string `json:"title"`
|
|
UserID int32 `json:"user_id"`
|
|
CustomerID int32 `json:"customer_id"`
|
|
ContactID int32 `json:"contact_id"`
|
|
ContactUserID int32 `json:"contact_user_id"`
|
|
StateID int32 `json:"state_id"`
|
|
CountryID int32 `json:"country_id"`
|
|
PrincipleID int32 `json:"principle_id"`
|
|
StatusID int32 `json:"status_id"`
|
|
Comments string `json:"comments"`
|
|
PrincipleCode int32 `json:"principle_code"`
|
|
Gst bool `json:"gst"`
|
|
BillingAddressID sql.NullInt32 `json:"billing_address_id"`
|
|
ShippingAddressID sql.NullInt32 `json:"shipping_address_id"`
|
|
Posted bool `json:"posted"`
|
|
Submitted sql.NullTime `json:"submitted"`
|
|
ID int32 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateEnquiry(ctx context.Context, arg UpdateEnquiryParams) error {
|
|
_, err := q.db.ExecContext(ctx, updateEnquiry,
|
|
arg.Title,
|
|
arg.UserID,
|
|
arg.CustomerID,
|
|
arg.ContactID,
|
|
arg.ContactUserID,
|
|
arg.StateID,
|
|
arg.CountryID,
|
|
arg.PrincipleID,
|
|
arg.StatusID,
|
|
arg.Comments,
|
|
arg.PrincipleCode,
|
|
arg.Gst,
|
|
arg.BillingAddressID,
|
|
arg.ShippingAddressID,
|
|
arg.Posted,
|
|
arg.Submitted,
|
|
arg.ID,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const updateEnquiryStatus = `-- name: UpdateEnquiryStatus :exec
|
|
UPDATE enquiries SET status_id = ? WHERE id = ?
|
|
`
|
|
|
|
type UpdateEnquiryStatusParams struct {
|
|
StatusID int32 `json:"status_id"`
|
|
ID int32 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateEnquiryStatus(ctx context.Context, arg UpdateEnquiryStatusParams) error {
|
|
_, err := q.db.ExecContext(ctx, updateEnquiryStatus, arg.StatusID, arg.ID)
|
|
return err
|
|
}
|