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

package db

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

	"github.com/lib/pq"
)

const companyQcp2SingleWithStatus = `-- name: CompanyQcp2SingleWithStatus :many
SELECT
  crops.cropname,
  qcp2.batchno,
  receptionform.order_id,
  farmers.fmname,
  qcp2.user_id,
  users.fullname,
  qcp2.created_at,
  qcp2.status,
  countries.countryname country,
  clients.companyname client_name,
  orders.consignment_no,
  qcp2.id qcp2_id,
  receptionform.traceability_code,
  qcp2.status qcp2_status
FROM
  qcp2
LEFT JOIN receptionform ON receptionform.id = qcp2.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 = qcp2.user_id
LEFT JOIN farmers ON farmers.id = receptionform.supplier_id
WHERE qcp2.exportcompany_id = $3
AND   qcp2.status = $4
ORDER BY qcp2.created_at DESC
LIMIT $1 OFFSET $2
`

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

type CompanyQcp2SingleWithStatusRow struct {
	Cropname         sql.NullString `json:"cropname"`
	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"`
	Qcp2ID           int64          `json:"qcp2_id"`
	TraceabilityCode sql.NullString `json:"traceability_code"`
	Qcp2Status       string         `json:"qcp2_status"`
}

func (q *Queries) CompanyQcp2SingleWithStatus(ctx context.Context, arg CompanyQcp2SingleWithStatusParams) ([]CompanyQcp2SingleWithStatusRow, error) {
	rows, err := q.db.QueryContext(ctx, companyQcp2SingleWithStatus,
		arg.Limit,
		arg.Offset,
		arg.ExportcompanyID,
		arg.Status,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []CompanyQcp2SingleWithStatusRow{}
	for rows.Next() {
		var i CompanyQcp2SingleWithStatusRow
		if err := rows.Scan(
			&i.Cropname,
			&i.Batchno,
			&i.OrderID,
			&i.Fmname,
			&i.UserID,
			&i.Fullname,
			&i.CreatedAt,
			&i.Status,
			&i.Country,
			&i.ClientName,
			&i.ConsignmentNo,
			&i.Qcp2ID,
			&i.TraceabilityCode,
			&i.Qcp2Status,
		); 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 companycp2s = `-- name: Companycp2s :many
SELECT crops.cropname,qcp2.batchno,receptionform.order_id,farmers.fmname,
qcp2.user_id,users.fullname,qcp2.created_at,qcp2.status,countries.countryname country, clients.companyname client_name,
orders.consignment_no,qcp2.id qcp2_id,receptionform.traceability_code, qcp2.status qcp2_status from qcp2
LEFT JOIN receptionform on receptionform.id = qcp2.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   = qcp2.user_id
LEFT JOIN farmers on farmers.id  = receptionform.supplier_id
WHERE qcp2.exportcompany_id     = $3
ORDER BY qcp2.created_at DESC
LIMIT $1 OFFSET $2
`

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

type Companycp2sRow struct {
	Cropname         sql.NullString `json:"cropname"`
	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"`
	Qcp2ID           int64          `json:"qcp2_id"`
	TraceabilityCode sql.NullString `json:"traceability_code"`
	Qcp2Status       string         `json:"qcp2_status"`
}

func (q *Queries) Companycp2s(ctx context.Context, arg Companycp2sParams) ([]Companycp2sRow, error) {
	rows, err := q.db.QueryContext(ctx, companycp2s, arg.Limit, arg.Offset, arg.ExportcompanyID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Companycp2sRow{}
	for rows.Next() {
		var i Companycp2sRow
		if err := rows.Scan(
			&i.Cropname,
			&i.Batchno,
			&i.OrderID,
			&i.Fmname,
			&i.UserID,
			&i.Fullname,
			&i.CreatedAt,
			&i.Status,
			&i.Country,
			&i.ClientName,
			&i.ConsignmentNo,
			&i.Qcp2ID,
			&i.TraceabilityCode,
			&i.Qcp2Status,
		); 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 createQcp2 = `-- name: CreateQcp2 :one
INSERT INTO qcp2 (
      batchno,
      reception_id,
      weightpassed,
      exportcompany_id,
      user_id,
      status
 ) VALUES (
     $1,
     $2,
     $3,
     $4,
     $5,
     $6
    )
RETURNING id, batchno, reception_id, exportcompany_id, user_id, weightpassed, status, created_at
`

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

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

const createQcp2Recommendation = `-- name: CreateQcp2Recommendation :one
INSERT INTO qcp2_recommendation (
    qcp2_id,
    status,
    netweightrejected,
    netweightpassed,
    other
 ) VALUES (
     $1,
     $2,
     $3,
     $4,
     $5
    )
RETURNING id, qcp2_id, status, netweightrejected, netweightpassed, other, created_at
`

type CreateQcp2RecommendationParams struct {
	Qcp2ID            int32           `json:"qcp2_id"`
	Status            string          `json:"status"`
	Netweightrejected float64         `json:"netweightrejected"`
	Netweightpassed   sql.NullFloat64 `json:"netweightpassed"`
	Other             sql.NullString  `json:"other"`
}

func (q *Queries) CreateQcp2Recommendation(ctx context.Context, arg CreateQcp2RecommendationParams) (Qcp2Recommendation, error) {
	row := q.db.QueryRowContext(ctx, createQcp2Recommendation,
		arg.Qcp2ID,
		arg.Status,
		arg.Netweightrejected,
		arg.Netweightpassed,
		arg.Other,
	)
	var i Qcp2Recommendation
	err := row.Scan(
		&i.ID,
		&i.Qcp2ID,
		&i.Status,
		&i.Netweightrejected,
		&i.Netweightpassed,
		&i.Other,
		&i.CreatedAt,
	)
	return i, err
}

const deleteQcp2 = `-- name: DeleteQcp2 :exec
DELETE FROM qcp2 WHERE id= $1
`

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

const deleteQcp2Recommendation = `-- name: DeleteQcp2Recommendation :exec
DELETE FROM qcp2_recommendation WHERE id= $1
`

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

const getQcp2 = `-- name: GetQcp2 :one
SELECT id, batchno, reception_id, exportcompany_id, user_id, weightpassed, status, created_at FROM qcp2
WHERE id = $1 LIMIT 1
`

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

const getQcp2Recommendation = `-- name: GetQcp2Recommendation :one
SELECT id, qcp2_id, status, netweightrejected, netweightpassed, other, created_at FROM qcp2_recommendation
WHERE qcp2_id = $1 LIMIT 1
`

func (q *Queries) GetQcp2Recommendation(ctx context.Context, qcp2ID int32) (Qcp2Recommendation, error) {
	row := q.db.QueryRowContext(ctx, getQcp2Recommendation, qcp2ID)
	var i Qcp2Recommendation
	err := row.Scan(
		&i.ID,
		&i.Qcp2ID,
		&i.Status,
		&i.Netweightrejected,
		&i.Netweightpassed,
		&i.Other,
		&i.CreatedAt,
	)
	return i, err
}

const listAllCompaniesQcp2Data = `-- name: ListAllCompaniesQcp2Data :many
SELECT orders.consignment_no,clients.companyname as client,
countries.countryname as country,receptionform.traceability_code,
orders.id as order_id,receptionform.batches,qcp2.batchno,
qcp2.weightpassed,farmers.fmcode,farmers.fmname,
exportcompanies.expname,crops.cropname,qcp2.created_at,qcp2.id as qcp2_id,
qcp2.status,qcp2.user_id,users.fullname FROM qcp2
JOIN  receptionform on receptionform.id = qcp2.reception_id
JOIN  farmers   on farmers.id  = receptionform.supplier_id
JOIN  crops     on crops.id    = receptionform.crop_id
JOIN  exportcompanies on exportcompanies.id = qcp2.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 = qcp2.user_id
ORDER BY qcp2.created_at DESC
LIMIT  $1 OFFSET $2
`

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

type ListAllCompaniesQcp2DataRow 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"`
	Qcp2ID           int64          `json:"qcp2_id"`
	Status           string         `json:"status"`
	UserID           int32          `json:"user_id"`
	Fullname         string         `json:"fullname"`
}

func (q *Queries) ListAllCompaniesQcp2Data(ctx context.Context, arg ListAllCompaniesQcp2DataParams) ([]ListAllCompaniesQcp2DataRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesQcp2Data, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesQcp2DataRow{}
	for rows.Next() {
		var i ListAllCompaniesQcp2DataRow
		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.Qcp2ID,
			&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 listAllCompaniesQcp2DateFilter = `-- name: ListAllCompaniesQcp2DateFilter :many
SELECT orders.consignment_no,clients.companyname as client,
countries.countryname as country,receptionform.traceability_code,
orders.id as order_id,receptionform.batches,qcp2.batchno,
qcp2.weightpassed,farmers.fmcode,farmers.fmname,
exportcompanies.expname,crops.cropname,qcp2.created_at,qcp2.id as qcp2_id,
qcp2.status,qcp2.user_id,users.fullname FROM qcp2
JOIN  receptionform on receptionform.id = qcp2.reception_id
JOIN  farmers   on farmers.id  = receptionform.supplier_id
JOIN  crops     on crops.id    = receptionform.crop_id
JOIN  exportcompanies on exportcompanies.id = qcp2.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 = qcp2.user_id
WHERE   qcp2.created_at
BETWEEN TO_TIMESTAMP($1, 'YYYY-MM-DD HH24:MI:SS')
AND     TO_TIMESTAMP($2, 'YYYY-MM-DD HH24:MI:SS')
ORDER BY qcp2.created_at DESC
LIMIT   $3 OFFSET $4
`

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

type ListAllCompaniesQcp2DateFilterRow 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"`
	Qcp2ID           int64          `json:"qcp2_id"`
	Status           string         `json:"status"`
	UserID           int32          `json:"user_id"`
	Fullname         string         `json:"fullname"`
}

func (q *Queries) ListAllCompaniesQcp2DateFilter(ctx context.Context, arg ListAllCompaniesQcp2DateFilterParams) ([]ListAllCompaniesQcp2DateFilterRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesQcp2DateFilter,
		arg.ToTimestamp,
		arg.ToTimestamp_2,
		arg.Limit,
		arg.Offset,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesQcp2DateFilterRow{}
	for rows.Next() {
		var i ListAllCompaniesQcp2DateFilterRow
		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.Qcp2ID,
			&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 listAllCompaniesQcp2Ds = `-- name: ListAllCompaniesQcp2Ds :many
SELECT orders.consignment_no,clients.companyname as client,
countries.countryname as country,receptionform.traceability_code,
orders.id as order_id,receptionform.batches,qcp2.batchno,
qcp2.weightpassed,farmers.fmcode,farmers.fmname,
exportcompanies.expname,crops.cropname,qcp2.created_at,qcp2.id as qcp2_id,
qcp2.status,qcp2.user_id,users.fullname FROM qcp2
JOIN  receptionform on receptionform.id = qcp2.reception_id
JOIN  farmers   on farmers.id  = receptionform.supplier_id
JOIN  crops     on crops.id    = receptionform.crop_id
JOIN  exportcompanies on exportcompanies.id = qcp2.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 = qcp2.user_id
WHERE qcp2.status = $1
ORDER BY qcp2.created_at DESC
`

type ListAllCompaniesQcp2DsRow 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"`
	Qcp2ID           int64          `json:"qcp2_id"`
	Status           string         `json:"status"`
	UserID           int32          `json:"user_id"`
	Fullname         string         `json:"fullname"`
}

func (q *Queries) ListAllCompaniesQcp2Ds(ctx context.Context, status string) ([]ListAllCompaniesQcp2DsRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesQcp2Ds, status)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesQcp2DsRow{}
	for rows.Next() {
		var i ListAllCompaniesQcp2DsRow
		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.Qcp2ID,
			&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 listAllCompaniesQcp2WFs = `-- name: ListAllCompaniesQcp2WFs :many
SELECT orders.consignment_no,clients.companyname as client,
countries.countryname as country,receptionform.traceability_code,
orders.id as order_id,receptionform.batches,qcp2.batchno,
qcp2.weightpassed,farmers.fmcode,farmers.fmname,
exportcompanies.expname,crops.cropname,qcp2.created_at,qcp2.id as qcp2_id,
qcp2.status,qcp2.user_id,users.fullname FROM qcp2
JOIN  receptionform on receptionform.id = qcp2.reception_id
JOIN  farmers   on farmers.id  = receptionform.supplier_id
JOIN  crops     on crops.id    = receptionform.crop_id
JOIN  exportcompanies on exportcompanies.id = qcp2.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 = qcp2.user_id
WHERE qcp2.status = ANY($1::text[])
ORDER BY qcp2.created_at DESC
LIMIT $2 OFFSET $3
`

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

type ListAllCompaniesQcp2WFsRow 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"`
	Qcp2ID           int64          `json:"qcp2_id"`
	Status           string         `json:"status"`
	UserID           int32          `json:"user_id"`
	Fullname         string         `json:"fullname"`
}

func (q *Queries) ListAllCompaniesQcp2WFs(ctx context.Context, arg ListAllCompaniesQcp2WFsParams) ([]ListAllCompaniesQcp2WFsRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesQcp2WFs, pq.Array(arg.Column1), arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesQcp2WFsRow{}
	for rows.Next() {
		var i ListAllCompaniesQcp2WFsRow
		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.Qcp2ID,
			&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 listAllCompaniesQcp2s = `-- name: ListAllCompaniesQcp2s :many
SELECT orders.consignment_no,clients.companyname as client,
countries.countryname as country,receptionform.traceability_code,
orders.id as order_id,receptionform.batches,qcp2.batchno,
qcp2.weightpassed,farmers.fmcode,farmers.fmname,
exportcompanies.expname,crops.cropname,qcp2.created_at,qcp2.id as qcp2_id,
qcp2.status,qcp2.user_id,users.fullname FROM qcp2
JOIN  receptionform on receptionform.id = qcp2.reception_id
JOIN  farmers   on farmers.id  = receptionform.supplier_id
JOIN  crops     on crops.id    = receptionform.crop_id
JOIN  exportcompanies on exportcompanies.id = qcp2.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 = qcp2.user_id
WHERE   qcp2.status = ANY($1::text[])
AND     qcp2.created_at
BETWEEN TO_TIMESTAMP($2, 'YYYY-MM-DD HH24:MI:SS')
AND     TO_TIMESTAMP($3, 'YYYY-MM-DD HH24:MI:SS')
ORDER BY qcp2.created_at DESC
LIMIT   $4 OFFSET $5
`

type ListAllCompaniesQcp2sParams 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 ListAllCompaniesQcp2sRow 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"`
	Qcp2ID           int64          `json:"qcp2_id"`
	Status           string         `json:"status"`
	UserID           int32          `json:"user_id"`
	Fullname         string         `json:"fullname"`
}

func (q *Queries) ListAllCompaniesQcp2s(ctx context.Context, arg ListAllCompaniesQcp2sParams) ([]ListAllCompaniesQcp2sRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesQcp2s,
		pq.Array(arg.Column1),
		arg.ToTimestamp,
		arg.ToTimestamp_2,
		arg.Limit,
		arg.Offset,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesQcp2sRow{}
	for rows.Next() {
		var i ListAllCompaniesQcp2sRow
		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.Qcp2ID,
			&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 listExporterPendingOrderQcp2s = `-- name: ListExporterPendingOrderQcp2s :many
SELECT crops.cropname,qcp2.batchno,receptionform.order_id,
qcp2.user_id,users.fullname,qcp2.created_at,qcp2.status,countries.countryname country, clients.companyname client_name,
orders.consignment_no,qcp2.id qcp2_id,receptionform.traceability_code, qcp2.status qcp2_status from qcp2
LEFT JOIN receptionform on receptionform.id = qcp2.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   = qcp2.user_id
WHERE orders.id     = $3 AND qcp2.status = $4
ORDER BY qcp2.created_at DESC
LIMIT $1 OFFSET $2
`

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

type ListExporterPendingOrderQcp2sRow struct {
	Cropname         sql.NullString `json:"cropname"`
	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"`
	Qcp2ID           int64          `json:"qcp2_id"`
	TraceabilityCode sql.NullString `json:"traceability_code"`
	Qcp2Status       string         `json:"qcp2_status"`
}

func (q *Queries) ListExporterPendingOrderQcp2s(ctx context.Context, arg ListExporterPendingOrderQcp2sParams) ([]ListExporterPendingOrderQcp2sRow, error) {
	rows, err := q.db.QueryContext(ctx, listExporterPendingOrderQcp2s,
		arg.Limit,
		arg.Offset,
		arg.ID,
		arg.Status,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListExporterPendingOrderQcp2sRow{}
	for rows.Next() {
		var i ListExporterPendingOrderQcp2sRow
		if err := rows.Scan(
			&i.Cropname,
			&i.Batchno,
			&i.OrderID,
			&i.UserID,
			&i.Fullname,
			&i.CreatedAt,
			&i.Status,
			&i.Country,
			&i.ClientName,
			&i.ConsignmentNo,
			&i.Qcp2ID,
			&i.TraceabilityCode,
			&i.Qcp2Status,
		); 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 listExporterPendingQcp2D = `-- name: ListExporterPendingQcp2D :many
SELECT
  crops.cropname,
  qcp2.batchno,
  receptionform.order_id,
  farmers.fmname,
  qcp2.user_id,
  users.fullname,
  qcp2.created_at,
  qcp2.status,
  countries.countryname country,
  clients.companyname client_name,
  orders.consignment_no,
  qcp2.id qcp2_id,
  receptionform.traceability_code,
  qcp2.status qcp2_status
FROM
  qcp2
LEFT JOIN receptionform ON receptionform.id = qcp2.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 = qcp2.user_id
LEFT JOIN farmers ON farmers.id = receptionform.supplier_id
WHERE qcp2.exportcompany_id = $3
AND     qcp2.created_at
BETWEEN TO_TIMESTAMP($4, 'YYYY-MM-DD HH24:MI:SS')
AND     TO_TIMESTAMP($5, 'YYYY-MM-DD HH24:MI:SS')
ORDER BY qcp2.created_at DESC
LIMIT $1 OFFSET $2
`

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

type ListExporterPendingQcp2DRow struct {
	Cropname         sql.NullString `json:"cropname"`
	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"`
	Qcp2ID           int64          `json:"qcp2_id"`
	TraceabilityCode sql.NullString `json:"traceability_code"`
	Qcp2Status       string         `json:"qcp2_status"`
}

func (q *Queries) ListExporterPendingQcp2D(ctx context.Context, arg ListExporterPendingQcp2DParams) ([]ListExporterPendingQcp2DRow, error) {
	rows, err := q.db.QueryContext(ctx, listExporterPendingQcp2D,
		arg.Limit,
		arg.Offset,
		arg.ExportcompanyID,
		arg.ToTimestamp,
		arg.ToTimestamp_2,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListExporterPendingQcp2DRow{}
	for rows.Next() {
		var i ListExporterPendingQcp2DRow
		if err := rows.Scan(
			&i.Cropname,
			&i.Batchno,
			&i.OrderID,
			&i.Fmname,
			&i.UserID,
			&i.Fullname,
			&i.CreatedAt,
			&i.Status,
			&i.Country,
			&i.ClientName,
			&i.ConsignmentNo,
			&i.Qcp2ID,
			&i.TraceabilityCode,
			&i.Qcp2Status,
		); 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 listExporterPendingQcp2Ws = `-- name: ListExporterPendingQcp2Ws :many
SELECT
  crops.cropname,
  qcp2.batchno,
  receptionform.order_id,
  farmers.fmname,
  qcp2.user_id,
  users.fullname,
  qcp2.created_at,
  qcp2.status,
  countries.countryname country,
  clients.companyname client_name,
  orders.consignment_no,
  qcp2.id qcp2_id,
  receptionform.traceability_code,
  qcp2.status qcp2_status
FROM
  qcp2
LEFT JOIN receptionform ON receptionform.id = qcp2.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 = qcp2.user_id
LEFT JOIN farmers ON farmers.id = receptionform.supplier_id
WHERE qcp2.exportcompany_id = $3
AND   qcp2.status = ANY($4::text[])
ORDER BY qcp2.created_at DESC
LIMIT $1 OFFSET $2
`

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

type ListExporterPendingQcp2WsRow struct {
	Cropname         sql.NullString `json:"cropname"`
	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"`
	Qcp2ID           int64          `json:"qcp2_id"`
	TraceabilityCode sql.NullString `json:"traceability_code"`
	Qcp2Status       string         `json:"qcp2_status"`
}

func (q *Queries) ListExporterPendingQcp2Ws(ctx context.Context, arg ListExporterPendingQcp2WsParams) ([]ListExporterPendingQcp2WsRow, error) {
	rows, err := q.db.QueryContext(ctx, listExporterPendingQcp2Ws,
		arg.Limit,
		arg.Offset,
		arg.ExportcompanyID,
		pq.Array(arg.Column4),
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListExporterPendingQcp2WsRow{}
	for rows.Next() {
		var i ListExporterPendingQcp2WsRow
		if err := rows.Scan(
			&i.Cropname,
			&i.Batchno,
			&i.OrderID,
			&i.Fmname,
			&i.UserID,
			&i.Fullname,
			&i.CreatedAt,
			&i.Status,
			&i.Country,
			&i.ClientName,
			&i.ConsignmentNo,
			&i.Qcp2ID,
			&i.TraceabilityCode,
			&i.Qcp2Status,
		); 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 listExporterPendingQcp2s = `-- name: ListExporterPendingQcp2s :many
SELECT
  crops.cropname,
  qcp2.batchno,
  receptionform.order_id,
  farmers.fmname,
  qcp2.user_id,
  users.fullname,
  qcp2.created_at,
  qcp2.status,
  countries.countryname country,
  clients.companyname client_name,
  orders.consignment_no,
  qcp2.id qcp2_id,
  receptionform.traceability_code,
  qcp2.status qcp2_status
FROM
  qcp2
LEFT JOIN receptionform ON receptionform.id = qcp2.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 = qcp2.user_id
LEFT JOIN farmers ON farmers.id = receptionform.supplier_id
WHERE qcp2.exportcompany_id = $3
  AND     qcp2.status = ANY($4::text[])
  AND     qcp2.created_at
  BETWEEN TO_TIMESTAMP($5, 'YYYY-MM-DD HH24:MI:SS')
  AND     TO_TIMESTAMP($6, 'YYYY-MM-DD HH24:MI:SS')
  ORDER BY qcp2.created_at DESC
  LIMIT $1 OFFSET $2
`

type ListExporterPendingQcp2sParams struct {
	Limit           int32    `json:"limit"`
	Offset          int32    `json:"offset"`
	ExportcompanyID int32    `json:"exportcompany_id"`
	Column4         []string `json:"column_4"`
	ToTimestamp     string   `json:"to_timestamp"`
	ToTimestamp_2   string   `json:"to_timestamp_2"`
}

type ListExporterPendingQcp2sRow struct {
	Cropname         sql.NullString `json:"cropname"`
	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"`
	Qcp2ID           int64          `json:"qcp2_id"`
	TraceabilityCode sql.NullString `json:"traceability_code"`
	Qcp2Status       string         `json:"qcp2_status"`
}

func (q *Queries) ListExporterPendingQcp2s(ctx context.Context, arg ListExporterPendingQcp2sParams) ([]ListExporterPendingQcp2sRow, error) {
	rows, err := q.db.QueryContext(ctx, listExporterPendingQcp2s,
		arg.Limit,
		arg.Offset,
		arg.ExportcompanyID,
		pq.Array(arg.Column4),
		arg.ToTimestamp,
		arg.ToTimestamp_2,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListExporterPendingQcp2sRow{}
	for rows.Next() {
		var i ListExporterPendingQcp2sRow
		if err := rows.Scan(
			&i.Cropname,
			&i.Batchno,
			&i.OrderID,
			&i.Fmname,
			&i.UserID,
			&i.Fullname,
			&i.CreatedAt,
			&i.Status,
			&i.Country,
			&i.ClientName,
			&i.ConsignmentNo,
			&i.Qcp2ID,
			&i.TraceabilityCode,
			&i.Qcp2Status,
		); 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 listQcp2Recommendation = `-- name: ListQcp2Recommendation :many
SELECT id, qcp2_id, status, netweightrejected, netweightpassed, other, created_at FROM qcp2_recommendation
ORDER BY id LIMIT $1
OFFSET $2
`

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

func (q *Queries) ListQcp2Recommendation(ctx context.Context, arg ListQcp2RecommendationParams) ([]Qcp2Recommendation, error) {
	rows, err := q.db.QueryContext(ctx, listQcp2Recommendation, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp2Recommendation{}
	for rows.Next() {
		var i Qcp2Recommendation
		if err := rows.Scan(
			&i.ID,
			&i.Qcp2ID,
			&i.Status,
			&i.Netweightrejected,
			&i.Netweightpassed,
			&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 listQcp2s = `-- name: ListQcp2s :many
SELECT id, batchno, reception_id, exportcompany_id, user_id, weightpassed, status, created_at FROM qcp2
WHERE status = "Pending" AND
exportcompany_id= $3
ORDER BY id LIMIT $1
OFFSET $2
`

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

func (q *Queries) ListQcp2s(ctx context.Context, arg ListQcp2sParams) ([]Qcp2, error) {
	rows, err := q.db.QueryContext(ctx, listQcp2s, arg.Limit, arg.Offset, arg.ExportcompanyID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp2{}
	for rows.Next() {
		var i Qcp2
		if err := rows.Scan(
			&i.ID,
			&i.Batchno,
			&i.ReceptionID,
			&i.ExportcompanyID,
			&i.UserID,
			&i.Weightpassed,
			&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 qcp2Details = `-- name: Qcp2Details :one
SELECT orders.consignment_no,receptionform.traceability_code,batchno,order_crops.weightreceived,qcp2.weightpassed, receptionform.batches,farmers.fmname,farmers.fmcode,
crops.cropname, qcp2.created_at,qcp2.status FROM qcp2
JOIN   receptionform on receptionform.id = qcp2.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
WHERE  qcp2.id = $1
`

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

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

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

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

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

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

const qcp2PerOrder = `-- name: Qcp2PerOrder :many
SELECT qcp2.reception_id,qcp2.id as qcp2_id,
crops.variant,crops.cropname,crops.cropname,
crops.variant,receptionform.traceability_code,
qcp2_recommendation.netweightrejected,qcp2_recommendation.netweightpassed,
qcp2_recommendation.status
from qcp2
INNER  JOIN  qcp2_recommendation  on qcp2_recommendation.qcp2_id     = qcp2.id
INNER  JOIN  receptionform        on receptionform.id                = qcp2.reception_id
INNER  JOIN  crops                on crops.id                        = receptionform.crop_id
WHERE  receptionform.order_id = $1 ORDER BY qcp2.created_at DESC
`

type Qcp2PerOrderRow struct {
	ReceptionID       int32           `json:"reception_id"`
	Qcp2ID            int64           `json:"qcp2_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) Qcp2PerOrder(ctx context.Context, orderID int32) ([]Qcp2PerOrderRow, error) {
	rows, err := q.db.QueryContext(ctx, qcp2PerOrder, orderID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp2PerOrderRow{}
	for rows.Next() {
		var i Qcp2PerOrderRow
		if err := rows.Scan(
			&i.ReceptionID,
			&i.Qcp2ID,
			&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 qcp2QualityAttributesPerOrder = `-- name: Qcp2QualityAttributesPerOrder :many
SELECT qcp2_attributes.qtyremoved,qcp2_attributes.id,qcp2_attributes.qtytaken,
qcp2_attributes.percentage,qualityattributes.description FROM qcp2_attributes
INNER JOIN qcp2 on qcp2.id  = qcp2_attributes.qcp2_id
INNER JOIN qualityattributes on qualityattributes.id = qcp2_attributes.qualityattribute_id
where qcp2.id = $1
`

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

func (q *Queries) Qcp2QualityAttributesPerOrder(ctx context.Context, id int64) ([]Qcp2QualityAttributesPerOrderRow, error) {
	rows, err := q.db.QueryContext(ctx, qcp2QualityAttributesPerOrder, id)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp2QualityAttributesPerOrderRow{}
	for rows.Next() {
		var i Qcp2QualityAttributesPerOrderRow
		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 qcp2Report = `-- name: Qcp2Report :one
SELECT qcp2.exportcompany_id,
qualityattributes.description,
qcp2.created_at,exportcompanies.expname exportcompany_name,
users.fullname user_name, qcp2.reception_id,
qcp2.user_id,qcp2.weightpassed,
qcp2.status qcp2_status,clients.companyname,
countries.countryname,crops.cropname,
qcp2_attributes.qualityattribute_id,
qcp2_attributes.qtyRemoved,
qcp2_attributes.qtyTaken,
qcp2_attributes.other,
qcp2_attributes.percentage,
qcp2_attributes.qcp2_id,
qcp2_recommendation.status recommendation_status,
qcp2_recommendation.netweightrejected,
qcp2_recommendation.netweightpassed,
qcp2_recommendation.other,
exportcompanies.logo,receptionform.traceability_code as traceabilitycode FROM qcp2
LEFT JOIN receptionform       on receptionform.id        = qcp2.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 qcp2_attributes     on qcp2_attributes.qcp2_id = qcp2.id
LEFT JOIN qcp2_recommendation on qcp2_recommendation.qcp2_id = qcp2.id
LEFT JOIN qualityattributes   on qualityattributes.id  = qcp2_attributes.qualityattribute_id
WHERE qcp2.id = $1
`

type Qcp2ReportRow 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"`
	Qcp2Status           string          `json:"qcp2_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"`
	Qcp2ID               sql.NullInt32   `json:"qcp2_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) Qcp2Report(ctx context.Context, id int64) (Qcp2ReportRow, error) {
	row := q.db.QueryRowContext(ctx, qcp2Report, id)
	var i Qcp2ReportRow
	err := row.Scan(
		&i.ExportcompanyID,
		&i.Description,
		&i.CreatedAt,
		&i.ExportcompanyName,
		&i.UserName,
		&i.ReceptionID,
		&i.UserID,
		&i.Weightpassed,
		&i.Qcp2Status,
		&i.Companyname,
		&i.Countryname,
		&i.Cropname,
		&i.QualityattributeID,
		&i.Qtyremoved,
		&i.Qtytaken,
		&i.Other,
		&i.Percentage,
		&i.Qcp2ID,
		&i.RecommendationStatus,
		&i.Netweightrejected,
		&i.Netweightpassed,
		&i.Other_2,
		&i.Logo,
		&i.Traceabilitycode,
	)
	return i, err
}

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

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

const updateQcP2Status = `-- name: UpdateQcP2Status :exec
UPDATE qcp2
  set
    status = $2
WHERE id = $1
RETURNING id, batchno, reception_id, exportcompany_id, user_id, weightpassed, status, created_at
`

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

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

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

type UpdateQcp2Params 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) UpdateQcp2(ctx context.Context, arg UpdateQcp2Params) (Qcp2, error) {
	row := q.db.QueryRowContext(ctx, updateQcp2,
		arg.ID,
		arg.Batchno,
		arg.ReceptionID,
		arg.ExportcompanyID,
		arg.UserID,
		arg.Status,
	)
	var i Qcp2
	err := row.Scan(
		&i.ID,
		&i.Batchno,
		&i.ReceptionID,
		&i.ExportcompanyID,
		&i.UserID,
		&i.Weightpassed,
		&i.Status,
		&i.CreatedAt,
	)
	return i, err
}

const updateQcp2Recommendation = `-- name: UpdateQcp2Recommendation :one
UPDATE qcp2_recommendation
  set
     qcp2_id = $2,
     status = $3,
     netweightrejected = $4,
     netweightpassed = $5,
     other  = $6
WHERE id = $1
RETURNING id, qcp2_id, status, netweightrejected, netweightpassed, other, created_at
`

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

func (q *Queries) UpdateQcp2Recommendation(ctx context.Context, arg UpdateQcp2RecommendationParams) (Qcp2Recommendation, error) {
	row := q.db.QueryRowContext(ctx, updateQcp2Recommendation,
		arg.ID,
		arg.Qcp2ID,
		arg.Status,
		arg.Netweightrejected,
		arg.Netweightpassed,
		arg.Other,
	)
	var i Qcp2Recommendation
	err := row.Scan(
		&i.ID,
		&i.Qcp2ID,
		&i.Status,
		&i.Netweightrejected,
		&i.Netweightpassed,
		&i.Other,
		&i.CreatedAt,
	)
	return i, err
}

const updateQcp2StatusResort = `-- name: UpdateQcp2StatusResort :one
UPDATE qcp2
  set
      status  = $2
WHERE batchno = $1
RETURNING id, batchno, reception_id, exportcompany_id, user_id, weightpassed, status, created_at
`

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

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