// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.28.0
// source: qcp3.sql

package db

import (
	"context"
	"database/sql"
	"time"

	"github.com/lib/pq"
)

const allQcP3Attributes = `-- name: AllQcP3Attributes :many
SELECT qualityattribute_id,qtyremoved qty_removed,crops.cropname,
qtytaken qty_taken,other,qcp3.batchno,qcp3.id,receptionform.traceability_code, qualityattributes.description FROM qcp3_attributes
LEFT JOIN  qcp3 on qcp3.id = qcp3_attributes.qcp3_id
LEFT JOIN  receptionform on receptionform.id = qcp3.reception_id
LEFT JOIN  qualityattributes on qualityattributes.id = qcp3_attributes.qualityattribute_id
LEFT JOIN  crops on crops.id = receptionform.crop_id
WHERE qcp3_attributes.qcp3_id = $1
`

type AllQcP3AttributesRow struct {
	QualityattributeID int32          `json:"qualityattribute_id"`
	QtyRemoved         float64        `json:"qty_removed"`
	Cropname           sql.NullString `json:"cropname"`
	QtyTaken           float64        `json:"qty_taken"`
	Other              sql.NullString `json:"other"`
	Batchno            sql.NullString `json:"batchno"`
	ID                 sql.NullInt64  `json:"id"`
	TraceabilityCode   sql.NullString `json:"traceability_code"`
	Description        sql.NullString `json:"description"`
}

func (q *Queries) AllQcP3Attributes(ctx context.Context, qcp3ID int32) ([]AllQcP3AttributesRow, error) {
	rows, err := q.db.QueryContext(ctx, allQcP3Attributes, qcp3ID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []AllQcP3AttributesRow{}
	for rows.Next() {
		var i AllQcP3AttributesRow
		if err := rows.Scan(
			&i.QualityattributeID,
			&i.QtyRemoved,
			&i.Cropname,
			&i.QtyTaken,
			&i.Other,
			&i.Batchno,
			&i.ID,
			&i.TraceabilityCode,
			&i.Description,
		); 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 checkQcp3ID = `-- name: CheckQcp3ID :many
SELECT id, qcp3_id, qualityattribute_id, qtyremoved, qtytaken, percentage, other, created_at FROM qcp3_attributes
where qcp3_id = $1
`

func (q *Queries) CheckQcp3ID(ctx context.Context, qcp3ID int32) ([]Qcp3Attribute, error) {
	rows, err := q.db.QueryContext(ctx, checkQcp3ID, qcp3ID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp3Attribute{}
	for rows.Next() {
		var i Qcp3Attribute
		if err := rows.Scan(
			&i.ID,
			&i.Qcp3ID,
			&i.QualityattributeID,
			&i.Qtyremoved,
			&i.Qtytaken,
			&i.Percentage,
			&i.Other,
			&i.CreatedAt,
		); 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 companyPendingQcp3s = `-- name: CompanyPendingQcp3s :many
SELECT crops.cropname,crops.id as crop_id,qcp3.batchno,receptionform.order_id,farmers.fmname,
qcp3.user_id,users.fullname,qcp3.created_at,qcp3.status,countries.countryname country, clients.companyname client_name,
orders.consignment_no,qcp3.id qcp3_id,receptionform.traceability_code, qcp3.status qcp3_status from qcp3
LEFT JOIN receptionform on receptionform.id = qcp3.reception_id
LEFT JOIN orders        on orders.id  = receptionform.order_id
LEFT JOIN clients       on clients.id = orders.client_id
LEFT JOIN countries     on countries.id = clients.country_id
LEFT JOIN crops         on crops.id   = receptionform.crop_id
LEFT JOIN users         on users.id   = qcp3.user_id
LEFT JOIN farmers       on farmers.id  = receptionform.supplier_id
WHERE qcp3.exportcompany_id = $3
ORDER BY qcp3.created_at DESC
LIMIT $1 OFFSET $2
`

type CompanyPendingQcp3sParams struct {
	Limit           int32 `json:"limit"`
	Offset          int32 `json:"offset"`
	ExportcompanyID int32 `json:"exportcompany_id"`
}

type CompanyPendingQcp3sRow struct {
	Cropname         sql.NullString `json:"cropname"`
	CropID           sql.NullInt64  `json:"crop_id"`
	Batchno          string         `json:"batchno"`
	OrderID          sql.NullInt32  `json:"order_id"`
	Fmname           sql.NullString `json:"fmname"`
	UserID           int32          `json:"user_id"`
	Fullname         sql.NullString `json:"fullname"`
	CreatedAt        time.Time      `json:"created_at"`
	Status           string         `json:"status"`
	Country          sql.NullString `json:"country"`
	ClientName       sql.NullString `json:"client_name"`
	ConsignmentNo    sql.NullString `json:"consignment_no"`
	Qcp3ID           int64          `json:"qcp3_id"`
	TraceabilityCode sql.NullString `json:"traceability_code"`
	Qcp3Status       string         `json:"qcp3_status"`
}

func (q *Queries) CompanyPendingQcp3s(ctx context.Context, arg CompanyPendingQcp3sParams) ([]CompanyPendingQcp3sRow, error) {
	rows, err := q.db.QueryContext(ctx, companyPendingQcp3s, arg.Limit, arg.Offset, arg.ExportcompanyID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []CompanyPendingQcp3sRow{}
	for rows.Next() {
		var i CompanyPendingQcp3sRow
		if err := rows.Scan(
			&i.Cropname,
			&i.CropID,
			&i.Batchno,
			&i.OrderID,
			&i.Fmname,
			&i.UserID,
			&i.Fullname,
			&i.CreatedAt,
			&i.Status,
			&i.Country,
			&i.ClientName,
			&i.ConsignmentNo,
			&i.Qcp3ID,
			&i.TraceabilityCode,
			&i.Qcp3Status,
		); 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 companyQcp3DateRanges = `-- name: CompanyQcp3DateRanges :many
SELECT crops.cropname,crops.id as crop_id,qcp3.batchno,receptionform.order_id,farmers.fmname,
qcp3.user_id,users.fullname,qcp3.created_at,qcp3.status,countries.countryname country, clients.companyname client_name,
orders.consignment_no,qcp3.id qcp3_id,receptionform.traceability_code, qcp3.status qcp3_status from qcp3
LEFT JOIN receptionform on receptionform.id = qcp3.reception_id
LEFT JOIN orders        on orders.id  = receptionform.order_id
LEFT JOIN clients       on clients.id = orders.client_id
LEFT JOIN countries     on countries.id = clients.country_id
LEFT JOIN crops         on crops.id   = receptionform.crop_id
LEFT JOIN users         on users.id   = qcp3.user_id
LEFT JOIN farmers       on farmers.id  = receptionform.supplier_id
WHERE   qcp3.exportcompany_id = $5
AND     qcp3.created_at
BETWEEN TO_TIMESTAMP($3, 'YYYY-MM-DD HH24:MI:SS')
AND     TO_TIMESTAMP($4, 'YYYY-MM-DD HH24:MI:SS')
ORDER BY qcp3.created_at DESC
LIMIT   $1 OFFSET $2
`

type CompanyQcp3DateRangesParams struct {
	Limit           int32  `json:"limit"`
	Offset          int32  `json:"offset"`
	ToTimestamp     string `json:"to_timestamp"`
	ToTimestamp_2   string `json:"to_timestamp_2"`
	ExportcompanyID int32  `json:"exportcompany_id"`
}

type CompanyQcp3DateRangesRow struct {
	Cropname         sql.NullString `json:"cropname"`
	CropID           sql.NullInt64  `json:"crop_id"`
	Batchno          string         `json:"batchno"`
	OrderID          sql.NullInt32  `json:"order_id"`
	Fmname           sql.NullString `json:"fmname"`
	UserID           int32          `json:"user_id"`
	Fullname         sql.NullString `json:"fullname"`
	CreatedAt        time.Time      `json:"created_at"`
	Status           string         `json:"status"`
	Country          sql.NullString `json:"country"`
	ClientName       sql.NullString `json:"client_name"`
	ConsignmentNo    sql.NullString `json:"consignment_no"`
	Qcp3ID           int64          `json:"qcp3_id"`
	TraceabilityCode sql.NullString `json:"traceability_code"`
	Qcp3Status       string         `json:"qcp3_status"`
}

func (q *Queries) CompanyQcp3DateRanges(ctx context.Context, arg CompanyQcp3DateRangesParams) ([]CompanyQcp3DateRangesRow, error) {
	rows, err := q.db.QueryContext(ctx, companyQcp3DateRanges,
		arg.Limit,
		arg.Offset,
		arg.ToTimestamp,
		arg.ToTimestamp_2,
		arg.ExportcompanyID,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []CompanyQcp3DateRangesRow{}
	for rows.Next() {
		var i CompanyQcp3DateRangesRow
		if err := rows.Scan(
			&i.Cropname,
			&i.CropID,
			&i.Batchno,
			&i.OrderID,
			&i.Fmname,
			&i.UserID,
			&i.Fullname,
			&i.CreatedAt,
			&i.Status,
			&i.Country,
			&i.ClientName,
			&i.ConsignmentNo,
			&i.Qcp3ID,
			&i.TraceabilityCode,
			&i.Qcp3Status,
		); 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 companyQcp3WithStatus = `-- name: CompanyQcp3WithStatus :many
SELECT crops.cropname,crops.id as crop_id,qcp3.batchno,receptionform.order_id,farmers.fmname,
qcp3.user_id,users.fullname,qcp3.created_at,qcp3.status,countries.countryname country, clients.companyname client_name,
orders.consignment_no,qcp3.id qcp3_id,receptionform.traceability_code, qcp3.status qcp3_status from qcp3
LEFT JOIN receptionform on receptionform.id = qcp3.reception_id
LEFT JOIN orders        on orders.id  = receptionform.order_id
LEFT JOIN clients       on clients.id = orders.client_id
LEFT JOIN countries     on countries.id = clients.country_id
LEFT JOIN crops         on crops.id   = receptionform.crop_id
LEFT JOIN users         on users.id   = qcp3.user_id
LEFT JOIN farmers       on farmers.id  = receptionform.supplier_id
WHERE   qcp3.exportcompany_id = $3
AND     qcp3.status  = ANY($4::text[])
ORDER BY qcp3.created_at DESC
LIMIT   $1 OFFSET $2
`

type CompanyQcp3WithStatusParams struct {
	Limit           int32    `json:"limit"`
	Offset          int32    `json:"offset"`
	ExportcompanyID int32    `json:"exportcompany_id"`
	Column4         []string `json:"column_4"`
}

type CompanyQcp3WithStatusRow struct {
	Cropname         sql.NullString `json:"cropname"`
	CropID           sql.NullInt64  `json:"crop_id"`
	Batchno          string         `json:"batchno"`
	OrderID          sql.NullInt32  `json:"order_id"`
	Fmname           sql.NullString `json:"fmname"`
	UserID           int32          `json:"user_id"`
	Fullname         sql.NullString `json:"fullname"`
	CreatedAt        time.Time      `json:"created_at"`
	Status           string         `json:"status"`
	Country          sql.NullString `json:"country"`
	ClientName       sql.NullString `json:"client_name"`
	ConsignmentNo    sql.NullString `json:"consignment_no"`
	Qcp3ID           int64          `json:"qcp3_id"`
	TraceabilityCode sql.NullString `json:"traceability_code"`
	Qcp3Status       string         `json:"qcp3_status"`
}

func (q *Queries) CompanyQcp3WithStatus(ctx context.Context, arg CompanyQcp3WithStatusParams) ([]CompanyQcp3WithStatusRow, error) {
	rows, err := q.db.QueryContext(ctx, companyQcp3WithStatus,
		arg.Limit,
		arg.Offset,
		arg.ExportcompanyID,
		pq.Array(arg.Column4),
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []CompanyQcp3WithStatusRow{}
	for rows.Next() {
		var i CompanyQcp3WithStatusRow
		if err := rows.Scan(
			&i.Cropname,
			&i.CropID,
			&i.Batchno,
			&i.OrderID,
			&i.Fmname,
			&i.UserID,
			&i.Fullname,
			&i.CreatedAt,
			&i.Status,
			&i.Country,
			&i.ClientName,
			&i.ConsignmentNo,
			&i.Qcp3ID,
			&i.TraceabilityCode,
			&i.Qcp3Status,
		); 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 companyQcp3WithStatusDateRanges = `-- name: CompanyQcp3WithStatusDateRanges :many
SELECT crops.cropname,crops.id as crop_id,qcp3.batchno,receptionform.order_id,farmers.fmname,
qcp3.user_id,users.fullname,qcp3.created_at,qcp3.status,countries.countryname country, clients.companyname client_name,
orders.consignment_no,qcp3.id qcp3_id,receptionform.traceability_code, qcp3.status qcp3_status from qcp3
LEFT JOIN receptionform on receptionform.id = qcp3.reception_id
LEFT JOIN orders        on orders.id  = receptionform.order_id
LEFT JOIN clients       on clients.id = orders.client_id
LEFT JOIN countries     on countries.id = clients.country_id
LEFT JOIN crops         on crops.id   = receptionform.crop_id
LEFT JOIN users         on users.id   = qcp3.user_id
LEFT JOIN farmers       on farmers.id  = receptionform.supplier_id
WHERE   qcp3.exportcompany_id = $6
AND     qcp3.status  = $3
AND     qcp3.created_at
BETWEEN TO_TIMESTAMP($4, 'YYYY-MM-DD HH24:MI:SS')
AND     TO_TIMESTAMP($5, 'YYYY-MM-DD HH24:MI:SS')
ORDER BY qcp3.created_at DESC
LIMIT   $1 OFFSET $2
`

type CompanyQcp3WithStatusDateRangesParams struct {
	Limit           int32  `json:"limit"`
	Offset          int32  `json:"offset"`
	Status          string `json:"status"`
	ToTimestamp     string `json:"to_timestamp"`
	ToTimestamp_2   string `json:"to_timestamp_2"`
	ExportcompanyID int32  `json:"exportcompany_id"`
}

type CompanyQcp3WithStatusDateRangesRow struct {
	Cropname         sql.NullString `json:"cropname"`
	CropID           sql.NullInt64  `json:"crop_id"`
	Batchno          string         `json:"batchno"`
	OrderID          sql.NullInt32  `json:"order_id"`
	Fmname           sql.NullString `json:"fmname"`
	UserID           int32          `json:"user_id"`
	Fullname         sql.NullString `json:"fullname"`
	CreatedAt        time.Time      `json:"created_at"`
	Status           string         `json:"status"`
	Country          sql.NullString `json:"country"`
	ClientName       sql.NullString `json:"client_name"`
	ConsignmentNo    sql.NullString `json:"consignment_no"`
	Qcp3ID           int64          `json:"qcp3_id"`
	TraceabilityCode sql.NullString `json:"traceability_code"`
	Qcp3Status       string         `json:"qcp3_status"`
}

func (q *Queries) CompanyQcp3WithStatusDateRanges(ctx context.Context, arg CompanyQcp3WithStatusDateRangesParams) ([]CompanyQcp3WithStatusDateRangesRow, error) {
	rows, err := q.db.QueryContext(ctx, companyQcp3WithStatusDateRanges,
		arg.Limit,
		arg.Offset,
		arg.Status,
		arg.ToTimestamp,
		arg.ToTimestamp_2,
		arg.ExportcompanyID,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []CompanyQcp3WithStatusDateRangesRow{}
	for rows.Next() {
		var i CompanyQcp3WithStatusDateRangesRow
		if err := rows.Scan(
			&i.Cropname,
			&i.CropID,
			&i.Batchno,
			&i.OrderID,
			&i.Fmname,
			&i.UserID,
			&i.Fullname,
			&i.CreatedAt,
			&i.Status,
			&i.Country,
			&i.ClientName,
			&i.ConsignmentNo,
			&i.Qcp3ID,
			&i.TraceabilityCode,
			&i.Qcp3Status,
		); 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 createQcp3 = `-- name: CreateQcp3 :one
INSERT INTO qcp3 (
      batchno,
      reception_id,
      exportcompany_id,
      user_id,
      weightpassed,
      status
 ) VALUES (
     $1,
     $2,
     $3,
     $4,
     $5,
     $6
    )
RETURNING id, batchno, reception_id, exportcompany_id, weightpassed, user_id, status, created_at
`

type CreateQcp3Params struct {
	Batchno         string  `json:"batchno"`
	ReceptionID     int32   `json:"reception_id"`
	ExportcompanyID int32   `json:"exportcompany_id"`
	UserID          int32   `json:"user_id"`
	Weightpassed    float64 `json:"weightpassed"`
	Status          string  `json:"status"`
}

func (q *Queries) CreateQcp3(ctx context.Context, arg CreateQcp3Params) (Qcp3, error) {
	row := q.db.QueryRowContext(ctx, createQcp3,
		arg.Batchno,
		arg.ReceptionID,
		arg.ExportcompanyID,
		arg.UserID,
		arg.Weightpassed,
		arg.Status,
	)
	var i Qcp3
	err := row.Scan(
		&i.ID,
		&i.Batchno,
		&i.ReceptionID,
		&i.ExportcompanyID,
		&i.Weightpassed,
		&i.UserID,
		&i.Status,
		&i.CreatedAt,
	)
	return i, err
}

const createQcp3Attributes = `-- name: CreateQcp3Attributes :one
INSERT INTO qcp3_attributes (
     qcp3_id,
     qualityattribute_id,
     percentage,
     other,
     qtyremoved,
     qtytaken
 ) VALUES (
     $1,
     $2,
     $3,
     $4,
     $5,
     $6
    )
RETURNING id, qcp3_id, qualityattribute_id, qtyremoved, qtytaken, percentage, other, created_at
`

type CreateQcp3AttributesParams struct {
	Qcp3ID             int32          `json:"qcp3_id"`
	QualityattributeID int32          `json:"qualityattribute_id"`
	Percentage         float64        `json:"percentage"`
	Other              sql.NullString `json:"other"`
	Qtyremoved         float64        `json:"qtyremoved"`
	Qtytaken           float64        `json:"qtytaken"`
}

func (q *Queries) CreateQcp3Attributes(ctx context.Context, arg CreateQcp3AttributesParams) (Qcp3Attribute, error) {
	row := q.db.QueryRowContext(ctx, createQcp3Attributes,
		arg.Qcp3ID,
		arg.QualityattributeID,
		arg.Percentage,
		arg.Other,
		arg.Qtyremoved,
		arg.Qtytaken,
	)
	var i Qcp3Attribute
	err := row.Scan(
		&i.ID,
		&i.Qcp3ID,
		&i.QualityattributeID,
		&i.Qtyremoved,
		&i.Qtytaken,
		&i.Percentage,
		&i.Other,
		&i.CreatedAt,
	)
	return i, err
}

const createQcp3Recommendation = `-- name: CreateQcp3Recommendation :one
INSERT INTO qcp3_recommendation (
    qcp3_id,
    status,
    netweightrejected,
    netweightpassed,
    other
 ) VALUES (
     $1,
     $2,
     $3,
     $4,
     $5
    )
RETURNING id, qcp3_id, status, netweightrejected, netweightpassed, reasonforrejection, other, created_at
`

type CreateQcp3RecommendationParams struct {
	Qcp3ID            int32           `json:"qcp3_id"`
	Status            string          `json:"status"`
	Netweightrejected float64         `json:"netweightrejected"`
	Netweightpassed   sql.NullFloat64 `json:"netweightpassed"`
	Other             sql.NullString  `json:"other"`
}

func (q *Queries) CreateQcp3Recommendation(ctx context.Context, arg CreateQcp3RecommendationParams) (Qcp3Recommendation, error) {
	row := q.db.QueryRowContext(ctx, createQcp3Recommendation,
		arg.Qcp3ID,
		arg.Status,
		arg.Netweightrejected,
		arg.Netweightpassed,
		arg.Other,
	)
	var i Qcp3Recommendation
	err := row.Scan(
		&i.ID,
		&i.Qcp3ID,
		&i.Status,
		&i.Netweightrejected,
		&i.Netweightpassed,
		&i.Reasonforrejection,
		&i.Other,
		&i.CreatedAt,
	)
	return i, err
}

const deleteQcp3 = `-- name: DeleteQcp3 :exec
DELETE FROM qcp3 WHERE id= $1
`

func (q *Queries) DeleteQcp3(ctx context.Context, id int64) error {
	_, err := q.db.ExecContext(ctx, deleteQcp3, id)
	return err
}

const deleteQcp3Attributes = `-- name: DeleteQcp3Attributes :exec
DELETE FROM qcp3_attributes WHERE qcp3_id= $1
`

func (q *Queries) DeleteQcp3Attributes(ctx context.Context, qcp3ID int32) error {
	_, err := q.db.ExecContext(ctx, deleteQcp3Attributes, qcp3ID)
	return err
}

const deleteQcp3Recommendation = `-- name: DeleteQcp3Recommendation :exec
DELETE FROM qcp3_recommendation WHERE id= $1
`

func (q *Queries) DeleteQcp3Recommendation(ctx context.Context, id int64) error {
	_, err := q.db.ExecContext(ctx, deleteQcp3Recommendation, id)
	return err
}

const getQcp3 = `-- name: GetQcp3 :one
SELECT id, batchno, reception_id, exportcompany_id, weightpassed, user_id, status, created_at FROM qcp3
WHERE id = $1 LIMIT 1
`

func (q *Queries) GetQcp3(ctx context.Context, id int64) (Qcp3, error) {
	row := q.db.QueryRowContext(ctx, getQcp3, id)
	var i Qcp3
	err := row.Scan(
		&i.ID,
		&i.Batchno,
		&i.ReceptionID,
		&i.ExportcompanyID,
		&i.Weightpassed,
		&i.UserID,
		&i.Status,
		&i.CreatedAt,
	)
	return i, err
}

const getQcp3Recommendation = `-- name: GetQcp3Recommendation :one
SELECT id, qcp3_id, status, netweightrejected, netweightpassed, reasonforrejection, other, created_at FROM qcp3_recommendation
WHERE qcp3_id = $1 LIMIT 1
`

func (q *Queries) GetQcp3Recommendation(ctx context.Context, qcp3ID int32) (Qcp3Recommendation, error) {
	row := q.db.QueryRowContext(ctx, getQcp3Recommendation, qcp3ID)
	var i Qcp3Recommendation
	err := row.Scan(
		&i.ID,
		&i.Qcp3ID,
		&i.Status,
		&i.Netweightrejected,
		&i.Netweightpassed,
		&i.Reasonforrejection,
		&i.Other,
		&i.CreatedAt,
	)
	return i, err
}

const globalCompanyPendingQcp3s = `-- name: GlobalCompanyPendingQcp3s :many
SELECT crops.cropname,crops.id as crop_id,qcp3.batchno,receptionform.order_id,farmers.fmname,
qcp3.user_id,users.fullname,qcp3.created_at,qcp3.status,countries.countryname country, clients.companyname client_name,
orders.consignment_no,qcp3.id qcp3_id,receptionform.traceability_code, qcp3.status qcp3_status from qcp3
LEFT JOIN receptionform on receptionform.id = qcp3.reception_id
LEFT JOIN orders        on orders.id  = receptionform.order_id
LEFT JOIN clients       on clients.id = orders.client_id
LEFT JOIN countries     on countries.id = clients.country_id
LEFT JOIN crops         on crops.id   = receptionform.crop_id
LEFT JOIN users         on users.id   = qcp3.user_id
LEFT JOIN farmers       on farmers.id  = receptionform.supplier_id
ORDER BY qcp3.created_at DESC
LIMIT $1 OFFSET $2
`

type GlobalCompanyPendingQcp3sParams struct {
	Limit  int32 `json:"limit"`
	Offset int32 `json:"offset"`
}

type GlobalCompanyPendingQcp3sRow struct {
	Cropname         sql.NullString `json:"cropname"`
	CropID           sql.NullInt64  `json:"crop_id"`
	Batchno          string         `json:"batchno"`
	OrderID          sql.NullInt32  `json:"order_id"`
	Fmname           sql.NullString `json:"fmname"`
	UserID           int32          `json:"user_id"`
	Fullname         sql.NullString `json:"fullname"`
	CreatedAt        time.Time      `json:"created_at"`
	Status           string         `json:"status"`
	Country          sql.NullString `json:"country"`
	ClientName       sql.NullString `json:"client_name"`
	ConsignmentNo    sql.NullString `json:"consignment_no"`
	Qcp3ID           int64          `json:"qcp3_id"`
	TraceabilityCode sql.NullString `json:"traceability_code"`
	Qcp3Status       string         `json:"qcp3_status"`
}

func (q *Queries) GlobalCompanyPendingQcp3s(ctx context.Context, arg GlobalCompanyPendingQcp3sParams) ([]GlobalCompanyPendingQcp3sRow, error) {
	rows, err := q.db.QueryContext(ctx, globalCompanyPendingQcp3s, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []GlobalCompanyPendingQcp3sRow{}
	for rows.Next() {
		var i GlobalCompanyPendingQcp3sRow
		if err := rows.Scan(
			&i.Cropname,
			&i.CropID,
			&i.Batchno,
			&i.OrderID,
			&i.Fmname,
			&i.UserID,
			&i.Fullname,
			&i.CreatedAt,
			&i.Status,
			&i.Country,
			&i.ClientName,
			&i.ConsignmentNo,
			&i.Qcp3ID,
			&i.TraceabilityCode,
			&i.Qcp3Status,
		); 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 listAllCompaniesQcp3Data = `-- name: ListAllCompaniesQcp3Data :many
SELECT crops.cropname,crops.id as crop_id,
qcp3.batchno,receptionform.order_id,farmers.fmname,
qcp3.user_id,users.fullname,qcp3.created_at,qcp3.status,
countries.countryname country, clients.companyname client_name,
orders.consignment_no,qcp3.id qcp3_id,farmers.fmcode,
exportcompanies.expname,receptionform.traceability_code,
qcp3.status qcp3_status,qcp3.weightpassed from qcp3
LEFT JOIN receptionform on receptionform.id = qcp3.reception_id
LEFT JOIN orders        on orders.id  = receptionform.order_id
LEFT JOIN clients       on clients.id = orders.client_id
LEFT JOIN countries     on countries.id = clients.country_id
LEFT JOIN crops         on crops.id   = receptionform.crop_id
LEFT JOIN users         on users.id   = qcp3.user_id
LEFT JOIN farmers       on farmers.id           = receptionform.supplier_id
LEFT JOIN exportcompanies on exportcompanies.id = qcp3.exportcompany_id
ORDER BY qcp3.created_at DESC
LIMIT $1 OFFSET $2
`

type ListAllCompaniesQcp3DataParams struct {
	Limit  int32 `json:"limit"`
	Offset int32 `json:"offset"`
}

type ListAllCompaniesQcp3DataRow struct {
	Cropname         sql.NullString `json:"cropname"`
	CropID           sql.NullInt64  `json:"crop_id"`
	Batchno          string         `json:"batchno"`
	OrderID          sql.NullInt32  `json:"order_id"`
	Fmname           sql.NullString `json:"fmname"`
	UserID           int32          `json:"user_id"`
	Fullname         sql.NullString `json:"fullname"`
	CreatedAt        time.Time      `json:"created_at"`
	Status           string         `json:"status"`
	Country          sql.NullString `json:"country"`
	ClientName       sql.NullString `json:"client_name"`
	ConsignmentNo    sql.NullString `json:"consignment_no"`
	Qcp3ID           int64          `json:"qcp3_id"`
	Fmcode           sql.NullString `json:"fmcode"`
	Expname          sql.NullString `json:"expname"`
	TraceabilityCode sql.NullString `json:"traceability_code"`
	Qcp3Status       string         `json:"qcp3_status"`
	Weightpassed     float64        `json:"weightpassed"`
}

func (q *Queries) ListAllCompaniesQcp3Data(ctx context.Context, arg ListAllCompaniesQcp3DataParams) ([]ListAllCompaniesQcp3DataRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesQcp3Data, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesQcp3DataRow{}
	for rows.Next() {
		var i ListAllCompaniesQcp3DataRow
		if err := rows.Scan(
			&i.Cropname,
			&i.CropID,
			&i.Batchno,
			&i.OrderID,
			&i.Fmname,
			&i.UserID,
			&i.Fullname,
			&i.CreatedAt,
			&i.Status,
			&i.Country,
			&i.ClientName,
			&i.ConsignmentNo,
			&i.Qcp3ID,
			&i.Fmcode,
			&i.Expname,
			&i.TraceabilityCode,
			&i.Qcp3Status,
			&i.Weightpassed,
		); 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 listAllCompaniesQcp3DataWithDate = `-- name: ListAllCompaniesQcp3DataWithDate :many
SELECT orders.consignment_no,clients.companyname as client,
countries.countryname as country,receptionform.traceability_code,
orders.id as order_id,receptionform.batches,qcp3.batchno,
qcp3.weightpassed,farmers.fmcode,farmers.fmname,exportcompanies.expname,
crops.cropname,qcp3.created_at,qcp3.id as qcp3_id,
qcp3.status,qcp3.user_id,users.fullname FROM qcp3
JOIN  receptionform on receptionform.id = qcp3.reception_id
JOIN  farmers   on farmers.id  = receptionform.supplier_id
JOIN  crops     on crops.id    = receptionform.crop_id
JOIN  exportcompanies on exportcompanies.id = qcp3.exportcompany_id
JOIN  orders    on  orders.id   = receptionform.order_id
JOIN  clients   on  clients.id  = orders.client_id
JOIN  countries on  countries.id = clients.country_id
JOIN  users     on  users.id = qcp3.user_id
WHERE    qcp3.created_at
BETWEEN  TO_TIMESTAMP($1, 'YYYY-MM-DD HH24:MI:SS')
AND      TO_TIMESTAMP($2, 'YYYY-MM-DD HH24:MI:SS')
ORDER BY qcp3.created_at DESC
LIMIT    $3 OFFSET $4
`

type ListAllCompaniesQcp3DataWithDateParams struct {
	ToTimestamp   string `json:"to_timestamp"`
	ToTimestamp_2 string `json:"to_timestamp_2"`
	Limit         int32  `json:"limit"`
	Offset        int32  `json:"offset"`
}

type ListAllCompaniesQcp3DataWithDateRow struct {
	ConsignmentNo    sql.NullString `json:"consignment_no"`
	Client           string         `json:"client"`
	Country          string         `json:"country"`
	TraceabilityCode string         `json:"traceability_code"`
	OrderID          int64          `json:"order_id"`
	Batches          int32          `json:"batches"`
	Batchno          string         `json:"batchno"`
	Weightpassed     float64        `json:"weightpassed"`
	Fmcode           sql.NullString `json:"fmcode"`
	Fmname           string         `json:"fmname"`
	Expname          string         `json:"expname"`
	Cropname         string         `json:"cropname"`
	CreatedAt        time.Time      `json:"created_at"`
	Qcp3ID           int64          `json:"qcp3_id"`
	Status           string         `json:"status"`
	UserID           int32          `json:"user_id"`
	Fullname         string         `json:"fullname"`
}

func (q *Queries) ListAllCompaniesQcp3DataWithDate(ctx context.Context, arg ListAllCompaniesQcp3DataWithDateParams) ([]ListAllCompaniesQcp3DataWithDateRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesQcp3DataWithDate,
		arg.ToTimestamp,
		arg.ToTimestamp_2,
		arg.Limit,
		arg.Offset,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesQcp3DataWithDateRow{}
	for rows.Next() {
		var i ListAllCompaniesQcp3DataWithDateRow
		if err := rows.Scan(
			&i.ConsignmentNo,
			&i.Client,
			&i.Country,
			&i.TraceabilityCode,
			&i.OrderID,
			&i.Batches,
			&i.Batchno,
			&i.Weightpassed,
			&i.Fmcode,
			&i.Fmname,
			&i.Expname,
			&i.Cropname,
			&i.CreatedAt,
			&i.Qcp3ID,
			&i.Status,
			&i.UserID,
			&i.Fullname,
		); 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 listAllCompaniesQcp3DataWithDateStatus = `-- name: ListAllCompaniesQcp3DataWithDateStatus :many
SELECT crops.cropname,crops.id as crop_id,
qcp3.batchno,receptionform.order_id,farmers.fmname,
qcp3.user_id,users.fullname,qcp3.created_at,qcp3.status,
countries.countryname country, clients.companyname client_name,
orders.consignment_no,qcp3.id qcp3_id,farmers.fmcode,
exportcompanies.expname,receptionform.traceability_code,
qcp3.status qcp3_status,qcp3.weightpassed from qcp3
LEFT JOIN receptionform on receptionform.id = qcp3.reception_id
LEFT JOIN orders        on orders.id  = receptionform.order_id
LEFT JOIN clients       on clients.id = orders.client_id
LEFT JOIN countries     on countries.id = clients.country_id
LEFT JOIN crops         on crops.id   = receptionform.crop_id
LEFT JOIN users         on users.id   = qcp3.user_id
LEFT JOIN farmers       on farmers.id           = receptionform.supplier_id
LEFT JOIN exportcompanies on exportcompanies.id = qcp3.exportcompany_id
WHERE    qcp3.status = ANY($1::text[])
AND      qcp3.created_at
BETWEEN  TO_TIMESTAMP($2, 'YYYY-MM-DD HH24:MI:SS')
AND      TO_TIMESTAMP($3, 'YYYY-MM-DD HH24:MI:SS')
ORDER BY qcp3.created_at DESC
LIMIT    $4 OFFSET $5
`

type ListAllCompaniesQcp3DataWithDateStatusParams struct {
	Column1       []string `json:"column_1"`
	ToTimestamp   string   `json:"to_timestamp"`
	ToTimestamp_2 string   `json:"to_timestamp_2"`
	Limit         int32    `json:"limit"`
	Offset        int32    `json:"offset"`
}

type ListAllCompaniesQcp3DataWithDateStatusRow struct {
	Cropname         sql.NullString `json:"cropname"`
	CropID           sql.NullInt64  `json:"crop_id"`
	Batchno          string         `json:"batchno"`
	OrderID          sql.NullInt32  `json:"order_id"`
	Fmname           sql.NullString `json:"fmname"`
	UserID           int32          `json:"user_id"`
	Fullname         sql.NullString `json:"fullname"`
	CreatedAt        time.Time      `json:"created_at"`
	Status           string         `json:"status"`
	Country          sql.NullString `json:"country"`
	ClientName       sql.NullString `json:"client_name"`
	ConsignmentNo    sql.NullString `json:"consignment_no"`
	Qcp3ID           int64          `json:"qcp3_id"`
	Fmcode           sql.NullString `json:"fmcode"`
	Expname          sql.NullString `json:"expname"`
	TraceabilityCode sql.NullString `json:"traceability_code"`
	Qcp3Status       string         `json:"qcp3_status"`
	Weightpassed     float64        `json:"weightpassed"`
}

func (q *Queries) ListAllCompaniesQcp3DataWithDateStatus(ctx context.Context, arg ListAllCompaniesQcp3DataWithDateStatusParams) ([]ListAllCompaniesQcp3DataWithDateStatusRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesQcp3DataWithDateStatus,
		pq.Array(arg.Column1),
		arg.ToTimestamp,
		arg.ToTimestamp_2,
		arg.Limit,
		arg.Offset,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesQcp3DataWithDateStatusRow{}
	for rows.Next() {
		var i ListAllCompaniesQcp3DataWithDateStatusRow
		if err := rows.Scan(
			&i.Cropname,
			&i.CropID,
			&i.Batchno,
			&i.OrderID,
			&i.Fmname,
			&i.UserID,
			&i.Fullname,
			&i.CreatedAt,
			&i.Status,
			&i.Country,
			&i.ClientName,
			&i.ConsignmentNo,
			&i.Qcp3ID,
			&i.Fmcode,
			&i.Expname,
			&i.TraceabilityCode,
			&i.Qcp3Status,
			&i.Weightpassed,
		); 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 listAllCompaniesQcp3DataWithStatus = `-- name: ListAllCompaniesQcp3DataWithStatus :many
SELECT orders.consignment_no,clients.companyname as client,
countries.countryname as country,receptionform.traceability_code,
orders.id as order_id,receptionform.batches,qcp3.batchno,
qcp3.weightpassed,farmers.fmcode,farmers.fmname,exportcompanies.expname,
crops.cropname,qcp3.created_at,qcp3.id as qcp3_id,
qcp3.status,qcp3.user_id,users.fullname FROM qcp3
JOIN     receptionform on receptionform.id = qcp3.reception_id
JOIN     farmers   on farmers.id  = receptionform.supplier_id
JOIN     crops     on crops.id    = receptionform.crop_id
JOIN     exportcompanies on exportcompanies.id = qcp3.exportcompany_id
JOIN     orders    on  orders.id   = receptionform.order_id
JOIN     clients   on  clients.id  = orders.client_id
JOIN     countries on  countries.id = clients.country_id
JOIN     users     on  users.id = qcp3.user_id
WHERE    qcp3.status = ANY($1::text[])
ORDER BY qcp3.created_at DESC
LIMIT    $2 OFFSET $3
`

type ListAllCompaniesQcp3DataWithStatusParams struct {
	Column1 []string `json:"column_1"`
	Limit   int32    `json:"limit"`
	Offset  int32    `json:"offset"`
}

type ListAllCompaniesQcp3DataWithStatusRow struct {
	ConsignmentNo    sql.NullString `json:"consignment_no"`
	Client           string         `json:"client"`
	Country          string         `json:"country"`
	TraceabilityCode string         `json:"traceability_code"`
	OrderID          int64          `json:"order_id"`
	Batches          int32          `json:"batches"`
	Batchno          string         `json:"batchno"`
	Weightpassed     float64        `json:"weightpassed"`
	Fmcode           sql.NullString `json:"fmcode"`
	Fmname           string         `json:"fmname"`
	Expname          string         `json:"expname"`
	Cropname         string         `json:"cropname"`
	CreatedAt        time.Time      `json:"created_at"`
	Qcp3ID           int64          `json:"qcp3_id"`
	Status           string         `json:"status"`
	UserID           int32          `json:"user_id"`
	Fullname         string         `json:"fullname"`
}

func (q *Queries) ListAllCompaniesQcp3DataWithStatus(ctx context.Context, arg ListAllCompaniesQcp3DataWithStatusParams) ([]ListAllCompaniesQcp3DataWithStatusRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesQcp3DataWithStatus, pq.Array(arg.Column1), arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesQcp3DataWithStatusRow{}
	for rows.Next() {
		var i ListAllCompaniesQcp3DataWithStatusRow
		if err := rows.Scan(
			&i.ConsignmentNo,
			&i.Client,
			&i.Country,
			&i.TraceabilityCode,
			&i.OrderID,
			&i.Batches,
			&i.Batchno,
			&i.Weightpassed,
			&i.Fmcode,
			&i.Fmname,
			&i.Expname,
			&i.Cropname,
			&i.CreatedAt,
			&i.Qcp3ID,
			&i.Status,
			&i.UserID,
			&i.Fullname,
		); 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 listAllCompaniesQcp3Ds = `-- name: ListAllCompaniesQcp3Ds :many
SELECT orders.consignment_no,clients.companyname as client,
countries.countryname as country,receptionform.traceability_code,
orders.id as order_id,receptionform.batches,qcp3.batchno,
qcp3.weightpassed,farmers.fmcode,farmers.fmname,exportcompanies.expname,
crops.cropname,qcp3.created_at,qcp3.id as qcp3_id,
qcp3.status,qcp3.user_id,users.fullname FROM qcp3
JOIN  receptionform on receptionform.id = qcp3.reception_id
JOIN  farmers   on farmers.id  = receptionform.supplier_id
JOIN  crops     on crops.id    = receptionform.crop_id
JOIN  exportcompanies on exportcompanies.id = qcp3.exportcompany_id
JOIN  orders    on  orders.id   = receptionform.order_id
JOIN  clients   on  clients.id  = orders.client_id
JOIN  countries on  countries.id = clients.country_id
JOIN  users     on  users.id = qcp3.user_id
WHERE qcp3.status = ANY($1::text[])
ORDER BY qcp3.created_at DESC
`

type ListAllCompaniesQcp3DsRow struct {
	ConsignmentNo    sql.NullString `json:"consignment_no"`
	Client           string         `json:"client"`
	Country          string         `json:"country"`
	TraceabilityCode string         `json:"traceability_code"`
	OrderID          int64          `json:"order_id"`
	Batches          int32          `json:"batches"`
	Batchno          string         `json:"batchno"`
	Weightpassed     float64        `json:"weightpassed"`
	Fmcode           sql.NullString `json:"fmcode"`
	Fmname           string         `json:"fmname"`
	Expname          string         `json:"expname"`
	Cropname         string         `json:"cropname"`
	CreatedAt        time.Time      `json:"created_at"`
	Qcp3ID           int64          `json:"qcp3_id"`
	Status           string         `json:"status"`
	UserID           int32          `json:"user_id"`
	Fullname         string         `json:"fullname"`
}

func (q *Queries) ListAllCompaniesQcp3Ds(ctx context.Context, dollar_1 []string) ([]ListAllCompaniesQcp3DsRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesQcp3Ds, pq.Array(dollar_1))
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesQcp3DsRow{}
	for rows.Next() {
		var i ListAllCompaniesQcp3DsRow
		if err := rows.Scan(
			&i.ConsignmentNo,
			&i.Client,
			&i.Country,
			&i.TraceabilityCode,
			&i.OrderID,
			&i.Batches,
			&i.Batchno,
			&i.Weightpassed,
			&i.Fmcode,
			&i.Fmname,
			&i.Expname,
			&i.Cropname,
			&i.CreatedAt,
			&i.Qcp3ID,
			&i.Status,
			&i.UserID,
			&i.Fullname,
		); 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 listAllCompaniesQcp3WFs = `-- name: ListAllCompaniesQcp3WFs :many
SELECT orders.consignment_no,clients.companyname as client,
countries.countryname as country,receptionform.traceability_code,
orders.id as order_id,receptionform.batches,qcp3.batchno,
qcp3.weightpassed,farmers.fmcode,farmers.fmname,exportcompanies.expname,
crops.cropname,qcp3.created_at,qcp3.id as qcp3_id,
qcp3.status,qcp3.user_id,users.fullname FROM qcp3
JOIN  receptionform on receptionform.id = qcp3.reception_id
JOIN  farmers   on farmers.id  = receptionform.supplier_id
JOIN  crops     on crops.id    = receptionform.crop_id
JOIN  exportcompanies on exportcompanies.id = qcp3.exportcompany_id
JOIN  orders    on  orders.id   = receptionform.order_id
JOIN  clients   on  clients.id  = orders.client_id
JOIN  countries on  countries.id = clients.country_id
JOIN  users     on  users.id = qcp3.user_id
WHERE qcp3.status = ANY($1::text[])
ORDER BY qcp3.created_at DESC
LIMIT $2 OFFSET $3
`

type ListAllCompaniesQcp3WFsParams struct {
	Column1 []string `json:"column_1"`
	Limit   int32    `json:"limit"`
	Offset  int32    `json:"offset"`
}

type ListAllCompaniesQcp3WFsRow struct {
	ConsignmentNo    sql.NullString `json:"consignment_no"`
	Client           string         `json:"client"`
	Country          string         `json:"country"`
	TraceabilityCode string         `json:"traceability_code"`
	OrderID          int64          `json:"order_id"`
	Batches          int32          `json:"batches"`
	Batchno          string         `json:"batchno"`
	Weightpassed     float64        `json:"weightpassed"`
	Fmcode           sql.NullString `json:"fmcode"`
	Fmname           string         `json:"fmname"`
	Expname          string         `json:"expname"`
	Cropname         string         `json:"cropname"`
	CreatedAt        time.Time      `json:"created_at"`
	Qcp3ID           int64          `json:"qcp3_id"`
	Status           string         `json:"status"`
	UserID           int32          `json:"user_id"`
	Fullname         string         `json:"fullname"`
}

func (q *Queries) ListAllCompaniesQcp3WFs(ctx context.Context, arg ListAllCompaniesQcp3WFsParams) ([]ListAllCompaniesQcp3WFsRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesQcp3WFs, pq.Array(arg.Column1), arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesQcp3WFsRow{}
	for rows.Next() {
		var i ListAllCompaniesQcp3WFsRow
		if err := rows.Scan(
			&i.ConsignmentNo,
			&i.Client,
			&i.Country,
			&i.TraceabilityCode,
			&i.OrderID,
			&i.Batches,
			&i.Batchno,
			&i.Weightpassed,
			&i.Fmcode,
			&i.Fmname,
			&i.Expname,
			&i.Cropname,
			&i.CreatedAt,
			&i.Qcp3ID,
			&i.Status,
			&i.UserID,
			&i.Fullname,
		); 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 listAllCompaniesQcp3s = `-- name: ListAllCompaniesQcp3s :many
SELECT orders.consignment_no,clients.companyname as client,
countries.countryname as country,receptionform.traceability_code,
orders.id as order_id,receptionform.batches,qcp3.batchno,
qcp3.weightpassed,farmers.fmcode,farmers.fmname,exportcompanies.expname,
crops.cropname,qcp3.created_at,qcp3.id as qcp3_id,
qcp3.status,qcp3.user_id,users.fullname FROM qcp3
JOIN  receptionform on receptionform.id = qcp3.reception_id
JOIN  farmers   on farmers.id  = receptionform.supplier_id
JOIN  crops     on crops.id    = receptionform.crop_id
JOIN  exportcompanies on exportcompanies.id = qcp3.exportcompany_id
JOIN  orders    on  orders.id   = receptionform.order_id
JOIN  clients   on  clients.id  = orders.client_id
JOIN  countries on  countries.id = clients.country_id
JOIN  users     on  users.id = qcp3.user_id
WHERE   qcp3.status = ANY($1::text[]) AND qcp3.created_at
BETWEEN TO_TIMESTAMP($2, 'YYYY-MM-DD HH24:MI:SS')
AND     TO_TIMESTAMP($3, 'YYYY-MM-DD HH24:MI:SS')
ORDER BY qcp3.created_at DESC
LIMIT   $4 OFFSET $5
`

type ListAllCompaniesQcp3sParams struct {
	Column1       []string `json:"column_1"`
	ToTimestamp   string   `json:"to_timestamp"`
	ToTimestamp_2 string   `json:"to_timestamp_2"`
	Limit         int32    `json:"limit"`
	Offset        int32    `json:"offset"`
}

type ListAllCompaniesQcp3sRow struct {
	ConsignmentNo    sql.NullString `json:"consignment_no"`
	Client           string         `json:"client"`
	Country          string         `json:"country"`
	TraceabilityCode string         `json:"traceability_code"`
	OrderID          int64          `json:"order_id"`
	Batches          int32          `json:"batches"`
	Batchno          string         `json:"batchno"`
	Weightpassed     float64        `json:"weightpassed"`
	Fmcode           sql.NullString `json:"fmcode"`
	Fmname           string         `json:"fmname"`
	Expname          string         `json:"expname"`
	Cropname         string         `json:"cropname"`
	CreatedAt        time.Time      `json:"created_at"`
	Qcp3ID           int64          `json:"qcp3_id"`
	Status           string         `json:"status"`
	UserID           int32          `json:"user_id"`
	Fullname         string         `json:"fullname"`
}

func (q *Queries) ListAllCompaniesQcp3s(ctx context.Context, arg ListAllCompaniesQcp3sParams) ([]ListAllCompaniesQcp3sRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesQcp3s,
		pq.Array(arg.Column1),
		arg.ToTimestamp,
		arg.ToTimestamp_2,
		arg.Limit,
		arg.Offset,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesQcp3sRow{}
	for rows.Next() {
		var i ListAllCompaniesQcp3sRow
		if err := rows.Scan(
			&i.ConsignmentNo,
			&i.Client,
			&i.Country,
			&i.TraceabilityCode,
			&i.OrderID,
			&i.Batches,
			&i.Batchno,
			&i.Weightpassed,
			&i.Fmcode,
			&i.Fmname,
			&i.Expname,
			&i.Cropname,
			&i.CreatedAt,
			&i.Qcp3ID,
			&i.Status,
			&i.UserID,
			&i.Fullname,
		); 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 listPendingOrderQcp3s = `-- name: ListPendingOrderQcp3s :many
SELECT crops.cropname,crops.id as crop_id,qcp3.batchno,receptionform.order_id,
qcp3.user_id,users.fullname,qcp3.created_at,qcp3.status,countries.countryname country, clients.companyname client_name,
orders.consignment_no,qcp3.id qcp3_id,receptionform.traceability_code, qcp3.status qcp3_status from qcp3
LEFT JOIN receptionform on receptionform.id = qcp3.reception_id
LEFT JOIN orders        on orders.id  = receptionform.order_id
LEFT JOIN clients       on clients.id = orders.client_id
LEFT JOIN countries     on countries.id = clients.country_id
LEFT JOIN crops         on crops.id   = receptionform.crop_id
LEFT JOIN users         on users.id   = qcp3.user_id
WHERE orders.id = $3  AND qcp3.status = $4
ORDER BY qcp3.created_at DESC
LIMIT $1 OFFSET $2
`

type ListPendingOrderQcp3sParams struct {
	Limit  int32  `json:"limit"`
	Offset int32  `json:"offset"`
	ID     int64  `json:"id"`
	Status string `json:"status"`
}

type ListPendingOrderQcp3sRow struct {
	Cropname         sql.NullString `json:"cropname"`
	CropID           sql.NullInt64  `json:"crop_id"`
	Batchno          string         `json:"batchno"`
	OrderID          sql.NullInt32  `json:"order_id"`
	UserID           int32          `json:"user_id"`
	Fullname         sql.NullString `json:"fullname"`
	CreatedAt        time.Time      `json:"created_at"`
	Status           string         `json:"status"`
	Country          sql.NullString `json:"country"`
	ClientName       sql.NullString `json:"client_name"`
	ConsignmentNo    sql.NullString `json:"consignment_no"`
	Qcp3ID           int64          `json:"qcp3_id"`
	TraceabilityCode sql.NullString `json:"traceability_code"`
	Qcp3Status       string         `json:"qcp3_status"`
}

func (q *Queries) ListPendingOrderQcp3s(ctx context.Context, arg ListPendingOrderQcp3sParams) ([]ListPendingOrderQcp3sRow, error) {
	rows, err := q.db.QueryContext(ctx, listPendingOrderQcp3s,
		arg.Limit,
		arg.Offset,
		arg.ID,
		arg.Status,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListPendingOrderQcp3sRow{}
	for rows.Next() {
		var i ListPendingOrderQcp3sRow
		if err := rows.Scan(
			&i.Cropname,
			&i.CropID,
			&i.Batchno,
			&i.OrderID,
			&i.UserID,
			&i.Fullname,
			&i.CreatedAt,
			&i.Status,
			&i.Country,
			&i.ClientName,
			&i.ConsignmentNo,
			&i.Qcp3ID,
			&i.TraceabilityCode,
			&i.Qcp3Status,
		); 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 listPendingQcp3s = `-- name: ListPendingQcp3s :many
SELECT crops.cropname,crops.id as crop_id,qcp3.batchno,receptionform.order_id,farmers.fmname,
qcp3.user_id,users.fullname,qcp3.created_at,qcp3.status,countries.countryname country, clients.companyname client_name,
orders.consignment_no,qcp3.id qcp3_id,receptionform.traceability_code, qcp3.status qcp3_status from qcp3
LEFT JOIN receptionform on receptionform.id = qcp3.reception_id
LEFT JOIN orders        on orders.id  = receptionform.order_id
LEFT JOIN clients       on clients.id = orders.client_id
LEFT JOIN countries     on countries.id = clients.country_id
LEFT JOIN crops         on crops.id   = receptionform.crop_id
LEFT JOIN users         on users.id   = qcp3.user_id
LEFT JOIN farmers       on farmers.id  = receptionform.supplier_id
WHERE qcp3.exportcompany_id     = $3  AND qcp3.status = $4
ORDER BY qcp3.created_at DESC
LIMIT $1 OFFSET $2
`

type ListPendingQcp3sParams struct {
	Limit           int32  `json:"limit"`
	Offset          int32  `json:"offset"`
	ExportcompanyID int32  `json:"exportcompany_id"`
	Status          string `json:"status"`
}

type ListPendingQcp3sRow struct {
	Cropname         sql.NullString `json:"cropname"`
	CropID           sql.NullInt64  `json:"crop_id"`
	Batchno          string         `json:"batchno"`
	OrderID          sql.NullInt32  `json:"order_id"`
	Fmname           sql.NullString `json:"fmname"`
	UserID           int32          `json:"user_id"`
	Fullname         sql.NullString `json:"fullname"`
	CreatedAt        time.Time      `json:"created_at"`
	Status           string         `json:"status"`
	Country          sql.NullString `json:"country"`
	ClientName       sql.NullString `json:"client_name"`
	ConsignmentNo    sql.NullString `json:"consignment_no"`
	Qcp3ID           int64          `json:"qcp3_id"`
	TraceabilityCode sql.NullString `json:"traceability_code"`
	Qcp3Status       string         `json:"qcp3_status"`
}

func (q *Queries) ListPendingQcp3s(ctx context.Context, arg ListPendingQcp3sParams) ([]ListPendingQcp3sRow, error) {
	rows, err := q.db.QueryContext(ctx, listPendingQcp3s,
		arg.Limit,
		arg.Offset,
		arg.ExportcompanyID,
		arg.Status,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListPendingQcp3sRow{}
	for rows.Next() {
		var i ListPendingQcp3sRow
		if err := rows.Scan(
			&i.Cropname,
			&i.CropID,
			&i.Batchno,
			&i.OrderID,
			&i.Fmname,
			&i.UserID,
			&i.Fullname,
			&i.CreatedAt,
			&i.Status,
			&i.Country,
			&i.ClientName,
			&i.ConsignmentNo,
			&i.Qcp3ID,
			&i.TraceabilityCode,
			&i.Qcp3Status,
		); 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 listQcp3Attributes = `-- name: ListQcp3Attributes :many
SELECT id, qcp3_id, qualityattribute_id, qtyremoved, qtytaken, percentage, other, created_at FROM qcp3_attributes
ORDER BY id LIMIT $1
OFFSET $2
`

type ListQcp3AttributesParams struct {
	Limit  int32 `json:"limit"`
	Offset int32 `json:"offset"`
}

func (q *Queries) ListQcp3Attributes(ctx context.Context, arg ListQcp3AttributesParams) ([]Qcp3Attribute, error) {
	rows, err := q.db.QueryContext(ctx, listQcp3Attributes, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp3Attribute{}
	for rows.Next() {
		var i Qcp3Attribute
		if err := rows.Scan(
			&i.ID,
			&i.Qcp3ID,
			&i.QualityattributeID,
			&i.Qtyremoved,
			&i.Qtytaken,
			&i.Percentage,
			&i.Other,
			&i.CreatedAt,
		); 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 listQcp3Recommendation = `-- name: ListQcp3Recommendation :many
SELECT id, qcp3_id, status, netweightrejected, netweightpassed, reasonforrejection, other, created_at FROM qcp3_recommendation
ORDER BY id LIMIT $1
OFFSET $2
`

type ListQcp3RecommendationParams struct {
	Limit  int32 `json:"limit"`
	Offset int32 `json:"offset"`
}

func (q *Queries) ListQcp3Recommendation(ctx context.Context, arg ListQcp3RecommendationParams) ([]Qcp3Recommendation, error) {
	rows, err := q.db.QueryContext(ctx, listQcp3Recommendation, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp3Recommendation{}
	for rows.Next() {
		var i Qcp3Recommendation
		if err := rows.Scan(
			&i.ID,
			&i.Qcp3ID,
			&i.Status,
			&i.Netweightrejected,
			&i.Netweightpassed,
			&i.Reasonforrejection,
			&i.Other,
			&i.CreatedAt,
		); 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 listQcp3s = `-- name: ListQcp3s :many
SELECT id, batchno, reception_id, exportcompany_id, weightpassed, user_id, status, created_at FROM qcp3
ORDER BY id LIMIT $1
OFFSET $2
`

type ListQcp3sParams struct {
	Limit  int32 `json:"limit"`
	Offset int32 `json:"offset"`
}

func (q *Queries) ListQcp3s(ctx context.Context, arg ListQcp3sParams) ([]Qcp3, error) {
	rows, err := q.db.QueryContext(ctx, listQcp3s, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp3{}
	for rows.Next() {
		var i Qcp3
		if err := rows.Scan(
			&i.ID,
			&i.Batchno,
			&i.ReceptionID,
			&i.ExportcompanyID,
			&i.Weightpassed,
			&i.UserID,
			&i.Status,
			&i.CreatedAt,
		); 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 qcp3Details = `-- name: Qcp3Details :one
SELECT orders.consignment_no,receptionform.traceability_code,batchno,order_crops.weightreceived,receptionform.batches,farmers.fmname,farmers.fmcode,clients.companyname, countries.countryname,
crops.cropname, qcp3.created_at, qcp3.weightpassed,qcp3.status FROM qcp3
JOIN   receptionform on  receptionform.id = qcp3.reception_id
JOIN   farmers       on  farmers.id = receptionform.supplier_id
JOIN   crops         on  crops.id   = receptionform.crop_id
JOIN   orders        on  orders.id  = receptionform.order_id
JOIN   order_crops   on  order_crops.order_id = orders.id
JOIN   clients       on  clients.id = orders.client_id
JOIN   countries     on  countries.id = clients.country_id
WHERE  qcp3.id = $1
`

type Qcp3DetailsRow struct {
	ConsignmentNo    sql.NullString  `json:"consignment_no"`
	TraceabilityCode string          `json:"traceability_code"`
	Batchno          string          `json:"batchno"`
	Weightreceived   sql.NullFloat64 `json:"weightreceived"`
	Batches          int32           `json:"batches"`
	Fmname           string          `json:"fmname"`
	Fmcode           sql.NullString  `json:"fmcode"`
	Companyname      string          `json:"companyname"`
	Countryname      string          `json:"countryname"`
	Cropname         string          `json:"cropname"`
	CreatedAt        time.Time       `json:"created_at"`
	Weightpassed     float64         `json:"weightpassed"`
	Status           string          `json:"status"`
}

func (q *Queries) Qcp3Details(ctx context.Context, id int64) (Qcp3DetailsRow, error) {
	row := q.db.QueryRowContext(ctx, qcp3Details, id)
	var i Qcp3DetailsRow
	err := row.Scan(
		&i.ConsignmentNo,
		&i.TraceabilityCode,
		&i.Batchno,
		&i.Weightreceived,
		&i.Batches,
		&i.Fmname,
		&i.Fmcode,
		&i.Companyname,
		&i.Countryname,
		&i.Cropname,
		&i.CreatedAt,
		&i.Weightpassed,
		&i.Status,
	)
	return i, err
}

const qcp3MarkAsDuplicate = `-- name: Qcp3MarkAsDuplicate :exec
UPDATE qcp3
  set
    status = 'Duplicate'
WHERE id = $1
RETURNING id, batchno, reception_id, exportcompany_id, weightpassed, user_id, status, created_at
`

func (q *Queries) Qcp3MarkAsDuplicate(ctx context.Context, id int64) error {
	_, err := q.db.ExecContext(ctx, qcp3MarkAsDuplicate, id)
	return err
}

const qcp3OrderSum = `-- name: Qcp3OrderSum :one
SELECT COUNT(id)
FROM  qcp3
JOIN  receptionform on receptionform.id = qcp3.reception_id
WHERE qcp3.status IN ('ReSorting','Pending','AwaitingResort')
AND   receptionform.order_id = $1
`

func (q *Queries) Qcp3OrderSum(ctx context.Context, orderID int32) (int64, error) {
	row := q.db.QueryRowContext(ctx, qcp3OrderSum, orderID)
	var count int64
	err := row.Scan(&count)
	return count, err
}

const qcp3PerOrder = `-- name: Qcp3PerOrder :many
SELECT qcp3.reception_id,qcp3.id as qcp3_id,crops.variant,crops.cropname,crops.cropname,crops.variant,
receptionform.traceability_code,qcp3_recommendation.netweightrejected,
qcp3_recommendation.netweightpassed,qcp3_recommendation.status
from qcp3
INNER  JOIN  qcp3_recommendation  on qcp3_recommendation.qcp3_id     = qcp3.id
INNER  JOIN  receptionform        on receptionform.id                = qcp3.reception_id
INNER  JOIN  crops                on crops.id                        = receptionform.crop_id
WHERE  receptionform.order_id = $1 ORDER BY qcp3.created_at DESC
`

type Qcp3PerOrderRow struct {
	ReceptionID       int32           `json:"reception_id"`
	Qcp3ID            int64           `json:"qcp3_id"`
	Variant           string          `json:"variant"`
	Cropname          string          `json:"cropname"`
	Cropname_2        string          `json:"cropname_2"`
	Variant_2         string          `json:"variant_2"`
	TraceabilityCode  string          `json:"traceability_code"`
	Netweightrejected float64         `json:"netweightrejected"`
	Netweightpassed   sql.NullFloat64 `json:"netweightpassed"`
	Status            string          `json:"status"`
}

func (q *Queries) Qcp3PerOrder(ctx context.Context, orderID int32) ([]Qcp3PerOrderRow, error) {
	rows, err := q.db.QueryContext(ctx, qcp3PerOrder, orderID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp3PerOrderRow{}
	for rows.Next() {
		var i Qcp3PerOrderRow
		if err := rows.Scan(
			&i.ReceptionID,
			&i.Qcp3ID,
			&i.Variant,
			&i.Cropname,
			&i.Cropname_2,
			&i.Variant_2,
			&i.TraceabilityCode,
			&i.Netweightrejected,
			&i.Netweightpassed,
			&i.Status,
		); 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 qcp3QualityAttributesPerOrder = `-- name: Qcp3QualityAttributesPerOrder :many
SELECT qcp3_attributes.qtyremoved,qcp3_attributes.id, qcp3_attributes.qtytaken,
qcp3_attributes.percentage,qualityattributes.description FROM qcp3_attributes
INNER JOIN qcp3              on qcp3.id = qcp3_attributes.qcp3_id
INNER JOIN qualityattributes on qualityattributes.id = qcp3_attributes.qualityattribute_id
where qcp3.id = $1
`

type Qcp3QualityAttributesPerOrderRow struct {
	Qtyremoved  float64 `json:"qtyremoved"`
	ID          int64   `json:"id"`
	Qtytaken    float64 `json:"qtytaken"`
	Percentage  float64 `json:"percentage"`
	Description string  `json:"description"`
}

func (q *Queries) Qcp3QualityAttributesPerOrder(ctx context.Context, id int64) ([]Qcp3QualityAttributesPerOrderRow, error) {
	rows, err := q.db.QueryContext(ctx, qcp3QualityAttributesPerOrder, id)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp3QualityAttributesPerOrderRow{}
	for rows.Next() {
		var i Qcp3QualityAttributesPerOrderRow
		if err := rows.Scan(
			&i.Qtyremoved,
			&i.ID,
			&i.Qtytaken,
			&i.Percentage,
			&i.Description,
		); 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 qcp3Report = `-- name: Qcp3Report :one
SELECT qcp3.exportcompany_id,
qualityattributes.description,
qcp3.created_at,exportcompanies.expname exportcompany_name,
users.fullname user_name, qcp3.reception_id,
qcp3.user_id,qcp3.weightpassed,
qcp3.status qcp3_status,clients.companyname,
countries.countryname,crops.cropname,
qcp3_attributes.qualityattribute_id,
qcp3_attributes.qtyRemoved,
qcp3_attributes.qtyTaken,
qcp3_attributes.other,
qcp3_attributes.percentage,
qcp3_attributes.qcp3_id,
qcp3_recommendation.status recommendation_status,
qcp3_recommendation.netweightrejected,
qcp3_recommendation.netweightpassed,
qcp3_recommendation.other,
exportcompanies.logo,receptionform.traceability_code as traceabilitycode FROM qcp3
LEFT JOIN receptionform       on receptionform.id        = qcp3.reception_id
LEFT JOIN crops               on crops.id                = receptionform.crop_id
LEFT JOIN orders              on orders.id               = receptionform.order_id
LEFT JOIN clients             on clients.id              = orders.client_id
LEFT JOIN countries           on countries.id            = clients.country_id
LEFT JOIN exportcompanies     on exportcompanies.id      = receptionform.exportcompany_id
LEFT JOIN users               on users.id                = receptionform.user_id
LEFT JOIN qcp3_attributes     on qcp3_attributes.qcp3_id = qcp3.id
LEFT JOIN qcp3_recommendation on qcp3_recommendation.qcp3_id = qcp3.id
LEFT JOIN qualityattributes   on qualityattributes.id  = qcp3_attributes.qualityattribute_id
WHERE qcp3.id = $1
`

type Qcp3ReportRow struct {
	ExportcompanyID      int32           `json:"exportcompany_id"`
	Description          sql.NullString  `json:"description"`
	CreatedAt            time.Time       `json:"created_at"`
	ExportcompanyName    sql.NullString  `json:"exportcompany_name"`
	UserName             sql.NullString  `json:"user_name"`
	ReceptionID          int32           `json:"reception_id"`
	UserID               int32           `json:"user_id"`
	Weightpassed         float64         `json:"weightpassed"`
	Qcp3Status           string          `json:"qcp3_status"`
	Companyname          sql.NullString  `json:"companyname"`
	Countryname          sql.NullString  `json:"countryname"`
	Cropname             sql.NullString  `json:"cropname"`
	QualityattributeID   sql.NullInt32   `json:"qualityattribute_id"`
	Qtyremoved           sql.NullFloat64 `json:"qtyremoved"`
	Qtytaken             sql.NullFloat64 `json:"qtytaken"`
	Other                sql.NullString  `json:"other"`
	Percentage           sql.NullFloat64 `json:"percentage"`
	Qcp3ID               sql.NullInt32   `json:"qcp3_id"`
	RecommendationStatus sql.NullString  `json:"recommendation_status"`
	Netweightrejected    sql.NullFloat64 `json:"netweightrejected"`
	Netweightpassed      sql.NullFloat64 `json:"netweightpassed"`
	Other_2              sql.NullString  `json:"other_2"`
	Logo                 sql.NullString  `json:"logo"`
	Traceabilitycode     sql.NullString  `json:"traceabilitycode"`
}

func (q *Queries) Qcp3Report(ctx context.Context, id int64) (Qcp3ReportRow, error) {
	row := q.db.QueryRowContext(ctx, qcp3Report, id)
	var i Qcp3ReportRow
	err := row.Scan(
		&i.ExportcompanyID,
		&i.Description,
		&i.CreatedAt,
		&i.ExportcompanyName,
		&i.UserName,
		&i.ReceptionID,
		&i.UserID,
		&i.Weightpassed,
		&i.Qcp3Status,
		&i.Companyname,
		&i.Countryname,
		&i.Cropname,
		&i.QualityattributeID,
		&i.Qtyremoved,
		&i.Qtytaken,
		&i.Other,
		&i.Percentage,
		&i.Qcp3ID,
		&i.RecommendationStatus,
		&i.Netweightrejected,
		&i.Netweightpassed,
		&i.Other_2,
		&i.Logo,
		&i.Traceabilitycode,
	)
	return i, err
}

const qcp3Sum = `-- name: Qcp3Sum :one
SELECT COUNT(id)
FROM  qcp3
WHERE qcp3.status IN ('ReSorting','Pending','AwaitingResort')
AND   qcp3.exportcompany_id = $1
`

func (q *Queries) Qcp3Sum(ctx context.Context, exportcompanyID int32) (int64, error) {
	row := q.db.QueryRowContext(ctx, qcp3Sum, exportcompanyID)
	var count int64
	err := row.Scan(&count)
	return count, err
}

const returnAllDetailsPerQcp3 = `-- name: ReturnAllDetailsPerQcp3 :one
SELECT qcp3.batchno,qcp3.reception_id,
qcp3.exportcompany_id,qcp3.user_id,
qcp3.weightpassed,qcp3.status,receptionform.order_id,
receptionform.traceability_code,receptionform.crop_id FROM qcp3
JOIN receptionform on receptionform.id = qcp3.reception_id
JOIN orders on orders.id = receptionform.order_id
WHERE qcp3.id = $1 LIMIT 1
`

type ReturnAllDetailsPerQcp3Row struct {
	Batchno          string  `json:"batchno"`
	ReceptionID      int32   `json:"reception_id"`
	ExportcompanyID  int32   `json:"exportcompany_id"`
	UserID           int32   `json:"user_id"`
	Weightpassed     float64 `json:"weightpassed"`
	Status           string  `json:"status"`
	OrderID          int32   `json:"order_id"`
	TraceabilityCode string  `json:"traceability_code"`
	CropID           int32   `json:"crop_id"`
}

func (q *Queries) ReturnAllDetailsPerQcp3(ctx context.Context, id int64) (ReturnAllDetailsPerQcp3Row, error) {
	row := q.db.QueryRowContext(ctx, returnAllDetailsPerQcp3, id)
	var i ReturnAllDetailsPerQcp3Row
	err := row.Scan(
		&i.Batchno,
		&i.ReceptionID,
		&i.ExportcompanyID,
		&i.UserID,
		&i.Weightpassed,
		&i.Status,
		&i.OrderID,
		&i.TraceabilityCode,
		&i.CropID,
	)
	return i, err
}

const updateQcP3Status = `-- name: UpdateQcP3Status :exec
UPDATE qcp3
  set
    status = $2
WHERE id = $1
RETURNING id, batchno, reception_id, exportcompany_id, weightpassed, user_id, status, created_at
`

type UpdateQcP3StatusParams struct {
	ID     int64  `json:"id"`
	Status string `json:"status"`
}

func (q *Queries) UpdateQcP3Status(ctx context.Context, arg UpdateQcP3StatusParams) error {
	_, err := q.db.ExecContext(ctx, updateQcP3Status, arg.ID, arg.Status)
	return err
}

const updateQcp3 = `-- name: UpdateQcp3 :one
UPDATE qcp3
  set
      batchno = $2,
      reception_id = $3,
      exportcompany_id = $4,
      user_id = $5,
      status  = $6
WHERE id = $1
RETURNING id, batchno, reception_id, exportcompany_id, weightpassed, user_id, status, created_at
`

type UpdateQcp3Params struct {
	ID              int64  `json:"id"`
	Batchno         string `json:"batchno"`
	ReceptionID     int32  `json:"reception_id"`
	ExportcompanyID int32  `json:"exportcompany_id"`
	UserID          int32  `json:"user_id"`
	Status          string `json:"status"`
}

func (q *Queries) UpdateQcp3(ctx context.Context, arg UpdateQcp3Params) (Qcp3, error) {
	row := q.db.QueryRowContext(ctx, updateQcp3,
		arg.ID,
		arg.Batchno,
		arg.ReceptionID,
		arg.ExportcompanyID,
		arg.UserID,
		arg.Status,
	)
	var i Qcp3
	err := row.Scan(
		&i.ID,
		&i.Batchno,
		&i.ReceptionID,
		&i.ExportcompanyID,
		&i.Weightpassed,
		&i.UserID,
		&i.Status,
		&i.CreatedAt,
	)
	return i, err
}

const updateQcp3Attributes = `-- name: UpdateQcp3Attributes :one
UPDATE qcp3_attributes
  set
     qcp3_id = $2,
     qualityattribute_id  = $3,
     percentage = $4,
     other = $5,
     qtyremoved = $6,
     qtytaken = $7
WHERE id = $1
RETURNING id, qcp3_id, qualityattribute_id, qtyremoved, qtytaken, percentage, other, created_at
`

type UpdateQcp3AttributesParams struct {
	ID                 int64          `json:"id"`
	Qcp3ID             int32          `json:"qcp3_id"`
	QualityattributeID int32          `json:"qualityattribute_id"`
	Percentage         float64        `json:"percentage"`
	Other              sql.NullString `json:"other"`
	Qtyremoved         float64        `json:"qtyremoved"`
	Qtytaken           float64        `json:"qtytaken"`
}

func (q *Queries) UpdateQcp3Attributes(ctx context.Context, arg UpdateQcp3AttributesParams) (Qcp3Attribute, error) {
	row := q.db.QueryRowContext(ctx, updateQcp3Attributes,
		arg.ID,
		arg.Qcp3ID,
		arg.QualityattributeID,
		arg.Percentage,
		arg.Other,
		arg.Qtyremoved,
		arg.Qtytaken,
	)
	var i Qcp3Attribute
	err := row.Scan(
		&i.ID,
		&i.Qcp3ID,
		&i.QualityattributeID,
		&i.Qtyremoved,
		&i.Qtytaken,
		&i.Percentage,
		&i.Other,
		&i.CreatedAt,
	)
	return i, err
}

const updateQcp3Recommendation = `-- name: UpdateQcp3Recommendation :one
UPDATE qcp3_recommendation
  set
     qcp3_id = $2,
     status = $3,
     netweightrejected = $4,
     netweightpassed = $5,
     other  = $6
WHERE id = $1
RETURNING id, qcp3_id, status, netweightrejected, netweightpassed, reasonforrejection, other, created_at
`

type UpdateQcp3RecommendationParams struct {
	ID                int64           `json:"id"`
	Qcp3ID            int32           `json:"qcp3_id"`
	Status            string          `json:"status"`
	Netweightrejected float64         `json:"netweightrejected"`
	Netweightpassed   sql.NullFloat64 `json:"netweightpassed"`
	Other             sql.NullString  `json:"other"`
}

func (q *Queries) UpdateQcp3Recommendation(ctx context.Context, arg UpdateQcp3RecommendationParams) (Qcp3Recommendation, error) {
	row := q.db.QueryRowContext(ctx, updateQcp3Recommendation,
		arg.ID,
		arg.Qcp3ID,
		arg.Status,
		arg.Netweightrejected,
		arg.Netweightpassed,
		arg.Other,
	)
	var i Qcp3Recommendation
	err := row.Scan(
		&i.ID,
		&i.Qcp3ID,
		&i.Status,
		&i.Netweightrejected,
		&i.Netweightpassed,
		&i.Reasonforrejection,
		&i.Other,
		&i.CreatedAt,
	)
	return i, err
}

const updateQcp3RecommendationStatus = `-- name: UpdateQcp3RecommendationStatus :one
UPDATE qcp3_recommendation
  set
     reasonforrejection  = $2
WHERE qcp3_id = $1
RETURNING id, qcp3_id, status, netweightrejected, netweightpassed, reasonforrejection, other, created_at
`

type UpdateQcp3RecommendationStatusParams struct {
	Qcp3ID             int32          `json:"qcp3_id"`
	Reasonforrejection sql.NullString `json:"reasonforrejection"`
}

func (q *Queries) UpdateQcp3RecommendationStatus(ctx context.Context, arg UpdateQcp3RecommendationStatusParams) (Qcp3Recommendation, error) {
	row := q.db.QueryRowContext(ctx, updateQcp3RecommendationStatus, arg.Qcp3ID, arg.Reasonforrejection)
	var i Qcp3Recommendation
	err := row.Scan(
		&i.ID,
		&i.Qcp3ID,
		&i.Status,
		&i.Netweightrejected,
		&i.Netweightpassed,
		&i.Reasonforrejection,
		&i.Other,
		&i.CreatedAt,
	)
	return i, err
}

const updateQcp3Status = `-- name: UpdateQcp3Status :one
UPDATE qcp3
  set
    status = $2
WHERE id   = $1
RETURNING id, batchno, reception_id, exportcompany_id, weightpassed, user_id, status, created_at
`

type UpdateQcp3StatusParams struct {
	ID     int64  `json:"id"`
	Status string `json:"status"`
}

func (q *Queries) UpdateQcp3Status(ctx context.Context, arg UpdateQcp3StatusParams) (Qcp3, error) {
	row := q.db.QueryRowContext(ctx, updateQcp3Status, arg.ID, arg.Status)
	var i Qcp3
	err := row.Scan(
		&i.ID,
		&i.Batchno,
		&i.ReceptionID,
		&i.ExportcompanyID,
		&i.Weightpassed,
		&i.UserID,
		&i.Status,
		&i.CreatedAt,
	)
	return i, err
}

const updateQcp3StatusResort = `-- name: UpdateQcp3StatusResort :one
UPDATE qcp3
  set
      status  = $2
WHERE batchno = $1
RETURNING id, batchno, reception_id, exportcompany_id, weightpassed, user_id, status, created_at
`

type UpdateQcp3StatusResortParams struct {
	Batchno string `json:"batchno"`
	Status  string `json:"status"`
}

func (q *Queries) UpdateQcp3StatusResort(ctx context.Context, arg UpdateQcp3StatusResortParams) (Qcp3, error) {
	row := q.db.QueryRowContext(ctx, updateQcp3StatusResort, arg.Batchno, arg.Status)
	var i Qcp3
	err := row.Scan(
		&i.ID,
		&i.Batchno,
		&i.ReceptionID,
		&i.ExportcompanyID,
		&i.Weightpassed,
		&i.UserID,
		&i.Status,
		&i.CreatedAt,
	)
	return i, err
}
