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

package db

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

	"github.com/lib/pq"
)

const allPendingOrderQcp1s = `-- name: AllPendingOrderQcp1s :many
SELECT orders.consignment_no,clients.companyname,countries.countryname,receptionform.traceability_code, receptionform.order_id,receptionform.batches,farmers.fmname,farmers.fmcode,
crops.cropname, qcp1.created_at, qcp1.id qcp1_id, qcp1.status, qcp1.user_id user_id ,users.fullname,receptionform.id, weightpassed FROM qcp1
LEFT JOIN   receptionform on receptionform.id = qcp1.receptionform_id
LEFT JOIN   farmers       on  farmers.id   = receptionform.supplier_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   users         on  users.id     = receptionform.user_id
WHERE    orders.id   = $1 AND  qcp1.status = $2
ORDER BY qcp1.created_at DESC
`

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

type AllPendingOrderQcp1sRow struct {
	ConsignmentNo    sql.NullString `json:"consignment_no"`
	Companyname      sql.NullString `json:"companyname"`
	Countryname      sql.NullString `json:"countryname"`
	TraceabilityCode sql.NullString `json:"traceability_code"`
	OrderID          sql.NullInt32  `json:"order_id"`
	Batches          sql.NullInt32  `json:"batches"`
	Fmname           sql.NullString `json:"fmname"`
	Fmcode           sql.NullString `json:"fmcode"`
	Cropname         sql.NullString `json:"cropname"`
	CreatedAt        time.Time      `json:"created_at"`
	Qcp1ID           int64          `json:"qcp1_id"`
	Status           string         `json:"status"`
	UserID           int32          `json:"user_id"`
	Fullname         sql.NullString `json:"fullname"`
	ID               sql.NullInt64  `json:"id"`
	Weightpassed     float64        `json:"weightpassed"`
}

func (q *Queries) AllPendingOrderQcp1s(ctx context.Context, arg AllPendingOrderQcp1sParams) ([]AllPendingOrderQcp1sRow, error) {
	rows, err := q.db.QueryContext(ctx, allPendingOrderQcp1s, arg.ID, arg.Status)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []AllPendingOrderQcp1sRow{}
	for rows.Next() {
		var i AllPendingOrderQcp1sRow
		if err := rows.Scan(
			&i.ConsignmentNo,
			&i.Companyname,
			&i.Countryname,
			&i.TraceabilityCode,
			&i.OrderID,
			&i.Batches,
			&i.Fmname,
			&i.Fmcode,
			&i.Cropname,
			&i.CreatedAt,
			&i.Qcp1ID,
			&i.Status,
			&i.UserID,
			&i.Fullname,
			&i.ID,
			&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 allPendingQcp1s = `-- name: AllPendingQcp1s :many
SELECT orders.consignment_no,clients.companyname,countries.countryname,receptionform.traceability_code, receptionform.order_id,receptionform.batches,farmers.fmname,farmers.fmcode,
crops.cropname, qcp1.created_at, qcp1.id qcp1_id, qcp1.status, qcp1.user_id user_id ,users.fullname,receptionform.id, weightpassed FROM qcp1
LEFT JOIN   receptionform on receptionform.id = qcp1.receptionform_id
LEFT JOIN   farmers       on  farmers.id   = receptionform.supplier_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   users         on  users.id     = receptionform.user_id
WHERE    qcp1.exportcompany_id   = $1 AND  qcp1.status = $2
ORDER BY qcp1.created_at DESC
`

type AllPendingQcp1sParams struct {
	ExportcompanyID int32  `json:"exportcompany_id"`
	Status          string `json:"status"`
}

type AllPendingQcp1sRow struct {
	ConsignmentNo    sql.NullString `json:"consignment_no"`
	Companyname      sql.NullString `json:"companyname"`
	Countryname      sql.NullString `json:"countryname"`
	TraceabilityCode sql.NullString `json:"traceability_code"`
	OrderID          sql.NullInt32  `json:"order_id"`
	Batches          sql.NullInt32  `json:"batches"`
	Fmname           sql.NullString `json:"fmname"`
	Fmcode           sql.NullString `json:"fmcode"`
	Cropname         sql.NullString `json:"cropname"`
	CreatedAt        time.Time      `json:"created_at"`
	Qcp1ID           int64          `json:"qcp1_id"`
	Status           string         `json:"status"`
	UserID           int32          `json:"user_id"`
	Fullname         sql.NullString `json:"fullname"`
	ID               sql.NullInt64  `json:"id"`
	Weightpassed     float64        `json:"weightpassed"`
}

func (q *Queries) AllPendingQcp1s(ctx context.Context, arg AllPendingQcp1sParams) ([]AllPendingQcp1sRow, error) {
	rows, err := q.db.QueryContext(ctx, allPendingQcp1s, arg.ExportcompanyID, arg.Status)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []AllPendingQcp1sRow{}
	for rows.Next() {
		var i AllPendingQcp1sRow
		if err := rows.Scan(
			&i.ConsignmentNo,
			&i.Companyname,
			&i.Countryname,
			&i.TraceabilityCode,
			&i.OrderID,
			&i.Batches,
			&i.Fmname,
			&i.Fmcode,
			&i.Cropname,
			&i.CreatedAt,
			&i.Qcp1ID,
			&i.Status,
			&i.UserID,
			&i.Fullname,
			&i.ID,
			&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 companyQcp1DateRanges = `-- name: CompanyQcp1DateRanges :many
SELECT orders.consignment_no,clients.companyname,countries.countryname,receptionform.traceability_code, receptionform.order_id,receptionform.batches,farmers.fmname,farmers.fmcode,
crops.cropname, qcp1.created_at, qcp1.id qcp1_id, qcp1.status, qcp1.user_id user_id ,users.fullname,receptionform.id, weightpassed FROM qcp1
LEFT JOIN   receptionform on receptionform.id = qcp1.receptionform_id
LEFT JOIN   farmers       on  farmers.id   = receptionform.supplier_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   users         on  users.id     = receptionform.user_id
WHERE    qcp1.exportcompany_id = $3
AND      qcp1.created_at
BETWEEN  TO_TIMESTAMP($4, 'YYYY-MM-DD HH24:MI:SS')
AND      TO_TIMESTAMP($5, 'YYYY-MM-DD HH24:MI:SS')
ORDER BY qcp1.created_at DESC
LIMIT $1 OFFSET $2
`

type CompanyQcp1DateRangesParams 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 CompanyQcp1DateRangesRow struct {
	ConsignmentNo    sql.NullString `json:"consignment_no"`
	Companyname      sql.NullString `json:"companyname"`
	Countryname      sql.NullString `json:"countryname"`
	TraceabilityCode sql.NullString `json:"traceability_code"`
	OrderID          sql.NullInt32  `json:"order_id"`
	Batches          sql.NullInt32  `json:"batches"`
	Fmname           sql.NullString `json:"fmname"`
	Fmcode           sql.NullString `json:"fmcode"`
	Cropname         sql.NullString `json:"cropname"`
	CreatedAt        time.Time      `json:"created_at"`
	Qcp1ID           int64          `json:"qcp1_id"`
	Status           string         `json:"status"`
	UserID           int32          `json:"user_id"`
	Fullname         sql.NullString `json:"fullname"`
	ID               sql.NullInt64  `json:"id"`
	Weightpassed     float64        `json:"weightpassed"`
}

func (q *Queries) CompanyQcp1DateRanges(ctx context.Context, arg CompanyQcp1DateRangesParams) ([]CompanyQcp1DateRangesRow, error) {
	rows, err := q.db.QueryContext(ctx, companyQcp1DateRanges,
		arg.Limit,
		arg.Offset,
		arg.ExportcompanyID,
		arg.ToTimestamp,
		arg.ToTimestamp_2,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []CompanyQcp1DateRangesRow{}
	for rows.Next() {
		var i CompanyQcp1DateRangesRow
		if err := rows.Scan(
			&i.ConsignmentNo,
			&i.Companyname,
			&i.Countryname,
			&i.TraceabilityCode,
			&i.OrderID,
			&i.Batches,
			&i.Fmname,
			&i.Fmcode,
			&i.Cropname,
			&i.CreatedAt,
			&i.Qcp1ID,
			&i.Status,
			&i.UserID,
			&i.Fullname,
			&i.ID,
			&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 companyQcp1DateRangesWithStatus = `-- name: CompanyQcp1DateRangesWithStatus :many
SELECT orders.consignment_no,clients.companyname,countries.countryname,receptionform.traceability_code, receptionform.order_id,receptionform.batches,farmers.fmname,farmers.fmcode,
crops.cropname, qcp1.created_at, qcp1.id qcp1_id, qcp1.status, qcp1.user_id user_id ,users.fullname,receptionform.id, weightpassed FROM qcp1
LEFT JOIN   receptionform on receptionform.id = qcp1.receptionform_id
LEFT JOIN   farmers       on  farmers.id   = receptionform.supplier_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   users         on  users.id     = receptionform.user_id
WHERE       qcp1.exportcompany_id = $3
AND         qcp1.status = $4
AND         qcp1.created_at
BETWEEN     TO_TIMESTAMP($5, 'YYYY-MM-DD HH24:MI:SS')
AND         TO_TIMESTAMP($6, 'YYYY-MM-DD HH24:MI:SS')
ORDER BY    qcp1.created_at DESC
LIMIT $1 OFFSET $2
`

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

type CompanyQcp1DateRangesWithStatusRow struct {
	ConsignmentNo    sql.NullString `json:"consignment_no"`
	Companyname      sql.NullString `json:"companyname"`
	Countryname      sql.NullString `json:"countryname"`
	TraceabilityCode sql.NullString `json:"traceability_code"`
	OrderID          sql.NullInt32  `json:"order_id"`
	Batches          sql.NullInt32  `json:"batches"`
	Fmname           sql.NullString `json:"fmname"`
	Fmcode           sql.NullString `json:"fmcode"`
	Cropname         sql.NullString `json:"cropname"`
	CreatedAt        time.Time      `json:"created_at"`
	Qcp1ID           int64          `json:"qcp1_id"`
	Status           string         `json:"status"`
	UserID           int32          `json:"user_id"`
	Fullname         sql.NullString `json:"fullname"`
	ID               sql.NullInt64  `json:"id"`
	Weightpassed     float64        `json:"weightpassed"`
}

func (q *Queries) CompanyQcp1DateRangesWithStatus(ctx context.Context, arg CompanyQcp1DateRangesWithStatusParams) ([]CompanyQcp1DateRangesWithStatusRow, error) {
	rows, err := q.db.QueryContext(ctx, companyQcp1DateRangesWithStatus,
		arg.Limit,
		arg.Offset,
		arg.ExportcompanyID,
		arg.Status,
		arg.ToTimestamp,
		arg.ToTimestamp_2,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []CompanyQcp1DateRangesWithStatusRow{}
	for rows.Next() {
		var i CompanyQcp1DateRangesWithStatusRow
		if err := rows.Scan(
			&i.ConsignmentNo,
			&i.Companyname,
			&i.Countryname,
			&i.TraceabilityCode,
			&i.OrderID,
			&i.Batches,
			&i.Fmname,
			&i.Fmcode,
			&i.Cropname,
			&i.CreatedAt,
			&i.Qcp1ID,
			&i.Status,
			&i.UserID,
			&i.Fullname,
			&i.ID,
			&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 companyQcp1SingleWithStatus = `-- name: CompanyQcp1SingleWithStatus :many
SELECT orders.consignment_no,clients.companyname,countries.countryname,receptionform.traceability_code, receptionform.order_id,receptionform.batches,farmers.fmname,farmers.fmcode,
crops.cropname,qcp1.created_at, qcp1.id qcp1_id, qcp1.status, qcp1.user_id user_id ,users.fullname,receptionform.id, weightpassed FROM qcp1
LEFT JOIN   receptionform on receptionform.id = qcp1.receptionform_id
LEFT JOIN   farmers       on  farmers.id   = receptionform.supplier_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   users         on  users.id     = receptionform.user_id
WHERE       qcp1.exportcompany_id = $2
AND         qcp1.status = $1
ORDER BY    qcp1.created_at DESC
LIMIT   $3 OFFSET $4
`

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

type CompanyQcp1SingleWithStatusRow struct {
	ConsignmentNo    sql.NullString `json:"consignment_no"`
	Companyname      sql.NullString `json:"companyname"`
	Countryname      sql.NullString `json:"countryname"`
	TraceabilityCode sql.NullString `json:"traceability_code"`
	OrderID          sql.NullInt32  `json:"order_id"`
	Batches          sql.NullInt32  `json:"batches"`
	Fmname           sql.NullString `json:"fmname"`
	Fmcode           sql.NullString `json:"fmcode"`
	Cropname         sql.NullString `json:"cropname"`
	CreatedAt        time.Time      `json:"created_at"`
	Qcp1ID           int64          `json:"qcp1_id"`
	Status           string         `json:"status"`
	UserID           int32          `json:"user_id"`
	Fullname         sql.NullString `json:"fullname"`
	ID               sql.NullInt64  `json:"id"`
	Weightpassed     float64        `json:"weightpassed"`
}

func (q *Queries) CompanyQcp1SingleWithStatus(ctx context.Context, arg CompanyQcp1SingleWithStatusParams) ([]CompanyQcp1SingleWithStatusRow, error) {
	rows, err := q.db.QueryContext(ctx, companyQcp1SingleWithStatus,
		arg.Status,
		arg.ExportcompanyID,
		arg.Limit,
		arg.Offset,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []CompanyQcp1SingleWithStatusRow{}
	for rows.Next() {
		var i CompanyQcp1SingleWithStatusRow
		if err := rows.Scan(
			&i.ConsignmentNo,
			&i.Companyname,
			&i.Countryname,
			&i.TraceabilityCode,
			&i.OrderID,
			&i.Batches,
			&i.Fmname,
			&i.Fmcode,
			&i.Cropname,
			&i.CreatedAt,
			&i.Qcp1ID,
			&i.Status,
			&i.UserID,
			&i.Fullname,
			&i.ID,
			&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 companyQcp1WithStatus = `-- name: CompanyQcp1WithStatus :many
SELECT orders.consignment_no,clients.companyname,countries.countryname,receptionform.traceability_code, receptionform.order_id,receptionform.batches,farmers.fmname,farmers.fmcode,
crops.cropname,qcp1.created_at, qcp1.id qcp1_id, qcp1.status, qcp1.user_id user_id ,users.fullname,receptionform.id, weightpassed FROM qcp1
LEFT JOIN   receptionform on receptionform.id = qcp1.receptionform_id
LEFT JOIN   farmers       on  farmers.id   = receptionform.supplier_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   users         on  users.id     = receptionform.user_id
WHERE       qcp1.exportcompany_id = $2
AND         qcp1.status = ANY($1::text[])
ORDER BY    qcp1.created_at DESC
LIMIT $3 OFFSET $4
`

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

type CompanyQcp1WithStatusRow struct {
	ConsignmentNo    sql.NullString `json:"consignment_no"`
	Companyname      sql.NullString `json:"companyname"`
	Countryname      sql.NullString `json:"countryname"`
	TraceabilityCode sql.NullString `json:"traceability_code"`
	OrderID          sql.NullInt32  `json:"order_id"`
	Batches          sql.NullInt32  `json:"batches"`
	Fmname           sql.NullString `json:"fmname"`
	Fmcode           sql.NullString `json:"fmcode"`
	Cropname         sql.NullString `json:"cropname"`
	CreatedAt        time.Time      `json:"created_at"`
	Qcp1ID           int64          `json:"qcp1_id"`
	Status           string         `json:"status"`
	UserID           int32          `json:"user_id"`
	Fullname         sql.NullString `json:"fullname"`
	ID               sql.NullInt64  `json:"id"`
	Weightpassed     float64        `json:"weightpassed"`
}

func (q *Queries) CompanyQcp1WithStatus(ctx context.Context, arg CompanyQcp1WithStatusParams) ([]CompanyQcp1WithStatusRow, error) {
	rows, err := q.db.QueryContext(ctx, companyQcp1WithStatus,
		pq.Array(arg.Column1),
		arg.ExportcompanyID,
		arg.Limit,
		arg.Offset,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []CompanyQcp1WithStatusRow{}
	for rows.Next() {
		var i CompanyQcp1WithStatusRow
		if err := rows.Scan(
			&i.ConsignmentNo,
			&i.Companyname,
			&i.Countryname,
			&i.TraceabilityCode,
			&i.OrderID,
			&i.Batches,
			&i.Fmname,
			&i.Fmcode,
			&i.Cropname,
			&i.CreatedAt,
			&i.Qcp1ID,
			&i.Status,
			&i.UserID,
			&i.Fullname,
			&i.ID,
			&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 companyQcp1s = `-- name: CompanyQcp1s :many
SELECT orders.consignment_no,clients.companyname,countries.countryname,receptionform.traceability_code, receptionform.order_id,receptionform.batches,farmers.fmname,farmers.fmcode,
crops.cropname, qcp1.created_at, qcp1.id qcp1_id, qcp1.status, qcp1.user_id user_id ,users.fullname,receptionform.id, weightpassed FROM qcp1
LEFT JOIN   receptionform on receptionform.id = qcp1.receptionform_id
LEFT JOIN   farmers       on  farmers.id   = receptionform.supplier_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   users         on  users.id     = receptionform.user_id
WHERE       qcp1.exportcompany_id   = $1
ORDER BY    qcp1.created_at DESC LIMIT $2 OFFSET $3
`

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

type CompanyQcp1sRow struct {
	ConsignmentNo    sql.NullString `json:"consignment_no"`
	Companyname      sql.NullString `json:"companyname"`
	Countryname      sql.NullString `json:"countryname"`
	TraceabilityCode sql.NullString `json:"traceability_code"`
	OrderID          sql.NullInt32  `json:"order_id"`
	Batches          sql.NullInt32  `json:"batches"`
	Fmname           sql.NullString `json:"fmname"`
	Fmcode           sql.NullString `json:"fmcode"`
	Cropname         sql.NullString `json:"cropname"`
	CreatedAt        time.Time      `json:"created_at"`
	Qcp1ID           int64          `json:"qcp1_id"`
	Status           string         `json:"status"`
	UserID           int32          `json:"user_id"`
	Fullname         sql.NullString `json:"fullname"`
	ID               sql.NullInt64  `json:"id"`
	Weightpassed     float64        `json:"weightpassed"`
}

func (q *Queries) CompanyQcp1s(ctx context.Context, arg CompanyQcp1sParams) ([]CompanyQcp1sRow, error) {
	rows, err := q.db.QueryContext(ctx, companyQcp1s, arg.ExportcompanyID, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []CompanyQcp1sRow{}
	for rows.Next() {
		var i CompanyQcp1sRow
		if err := rows.Scan(
			&i.ConsignmentNo,
			&i.Companyname,
			&i.Countryname,
			&i.TraceabilityCode,
			&i.OrderID,
			&i.Batches,
			&i.Fmname,
			&i.Fmcode,
			&i.Cropname,
			&i.CreatedAt,
			&i.Qcp1ID,
			&i.Status,
			&i.UserID,
			&i.Fullname,
			&i.ID,
			&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 createQcp1 = `-- name: CreateQcp1 :one
INSERT INTO qcp1 (
      exportcompany_id,
      receptionform_id,
      user_id,
      weightpassed,
      status
 ) VALUES (
     $1,
     $2,
     $3,
     $4,
     $5
    )
RETURNING id, receptionform_id, exportcompany_id, user_id, weightpassed, status, created_at
`

type CreateQcp1Params struct {
	ExportcompanyID int32   `json:"exportcompany_id"`
	ReceptionformID int32   `json:"receptionform_id"`
	UserID          int32   `json:"user_id"`
	Weightpassed    float64 `json:"weightpassed"`
	Status          string  `json:"status"`
}

func (q *Queries) CreateQcp1(ctx context.Context, arg CreateQcp1Params) (Qcp1, error) {
	row := q.db.QueryRowContext(ctx, createQcp1,
		arg.ExportcompanyID,
		arg.ReceptionformID,
		arg.UserID,
		arg.Weightpassed,
		arg.Status,
	)
	var i Qcp1
	err := row.Scan(
		&i.ID,
		&i.ReceptionformID,
		&i.ExportcompanyID,
		&i.UserID,
		&i.Weightpassed,
		&i.Status,
		&i.CreatedAt,
	)
	return i, err
}

const deleteQcp1 = `-- name: DeleteQcp1 :exec
DELETE FROM qcp1 WHERE id= $1
`

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

const getQcp1 = `-- name: GetQcp1 :one
SELECT id, receptionform_id, exportcompany_id, user_id, weightpassed, status, created_at FROM qcp1
WHERE id = $1 LIMIT 1
`

func (q *Queries) GetQcp1(ctx context.Context, id int64) (Qcp1, error) {
	row := q.db.QueryRowContext(ctx, getQcp1, id)
	var i Qcp1
	err := row.Scan(
		&i.ID,
		&i.ReceptionformID,
		&i.ExportcompanyID,
		&i.UserID,
		&i.Weightpassed,
		&i.Status,
		&i.CreatedAt,
	)
	return i, err
}

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

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

type ListAllCompaniesQcp1DataRow 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"`
	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"`
	Qcp1ID           int64          `json:"qcp1_id"`
	Status           string         `json:"status"`
	UserID           int32          `json:"user_id"`
	Fullname         string         `json:"fullname"`
}

func (q *Queries) ListAllCompaniesQcp1Data(ctx context.Context, arg ListAllCompaniesQcp1DataParams) ([]ListAllCompaniesQcp1DataRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesQcp1Data, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesQcp1DataRow{}
	for rows.Next() {
		var i ListAllCompaniesQcp1DataRow
		if err := rows.Scan(
			&i.ConsignmentNo,
			&i.Client,
			&i.Country,
			&i.TraceabilityCode,
			&i.OrderID,
			&i.Batches,
			&i.Weightpassed,
			&i.Fmcode,
			&i.Fmname,
			&i.Expname,
			&i.Cropname,
			&i.CreatedAt,
			&i.Qcp1ID,
			&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 listAllCompaniesQcp1DataWithDate = `-- name: ListAllCompaniesQcp1DataWithDate :many
SELECT orders.consignment_no,clients.companyname as client,
countries.countryname as country,receptionform.traceability_code,
orders.id as order_id,receptionform.batches,
qcp1.weightpassed,farmers.fmcode,farmers.fmname,exportcompanies.expname,
crops.cropname,qcp1.created_at,qcp1.id as qcp1_id,
qcp1.status,qcp1.user_id,users.fullname FROM qcp1
JOIN  receptionform on receptionform.id = qcp1.receptionform_id
JOIN  farmers   on farmers.id  = receptionform.supplier_id
JOIN  crops     on crops.id    = receptionform.crop_id
JOIN  exportcompanies on exportcompanies.id = qcp1.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 = qcp1.user_id
WHERE       qcp1.created_at
BETWEEN     TO_TIMESTAMP($1, 'YYYY-MM-DD HH24:MI:SS')
AND         TO_TIMESTAMP($2, 'YYYY-MM-DD HH24:MI:SS')
ORDER BY    qcp1.created_at DESC
LIMIT   $3 OFFSET $4
`

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

type ListAllCompaniesQcp1DataWithDateRow 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"`
	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"`
	Qcp1ID           int64          `json:"qcp1_id"`
	Status           string         `json:"status"`
	UserID           int32          `json:"user_id"`
	Fullname         string         `json:"fullname"`
}

func (q *Queries) ListAllCompaniesQcp1DataWithDate(ctx context.Context, arg ListAllCompaniesQcp1DataWithDateParams) ([]ListAllCompaniesQcp1DataWithDateRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesQcp1DataWithDate,
		arg.ToTimestamp,
		arg.ToTimestamp_2,
		arg.Limit,
		arg.Offset,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesQcp1DataWithDateRow{}
	for rows.Next() {
		var i ListAllCompaniesQcp1DataWithDateRow
		if err := rows.Scan(
			&i.ConsignmentNo,
			&i.Client,
			&i.Country,
			&i.TraceabilityCode,
			&i.OrderID,
			&i.Batches,
			&i.Weightpassed,
			&i.Fmcode,
			&i.Fmname,
			&i.Expname,
			&i.Cropname,
			&i.CreatedAt,
			&i.Qcp1ID,
			&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 listAllCompaniesQcp1DataWithDateStatus = `-- name: ListAllCompaniesQcp1DataWithDateStatus :many
SELECT orders.consignment_no,clients.companyname as client,
countries.countryname as country,receptionform.traceability_code,
orders.id as order_id,receptionform.batches,
qcp1.weightpassed,farmers.fmcode,farmers.fmname,exportcompanies.expname,
crops.cropname,qcp1.created_at,qcp1.id as qcp1_id,
qcp1.status,qcp1.user_id,users.fullname FROM qcp1
JOIN  receptionform on receptionform.id = qcp1.receptionform_id
JOIN  farmers   on farmers.id  = receptionform.supplier_id
JOIN  crops     on crops.id    = receptionform.crop_id
JOIN  exportcompanies on exportcompanies.id = qcp1.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 = qcp1.user_id
WHERE   qcp1.status = ANY($1::text[])
AND     qcp1.created_at
BETWEEN TO_TIMESTAMP($2, 'YYYY-MM-DD HH24:MI:SS')
AND     TO_TIMESTAMP($3, 'YYYY-MM-DD HH24:MI:SS')
ORDER BY qcp1.created_at DESC
LIMIT   $4 OFFSET $5
`

type ListAllCompaniesQcp1DataWithDateStatusParams 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 ListAllCompaniesQcp1DataWithDateStatusRow 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"`
	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"`
	Qcp1ID           int64          `json:"qcp1_id"`
	Status           string         `json:"status"`
	UserID           int32          `json:"user_id"`
	Fullname         string         `json:"fullname"`
}

func (q *Queries) ListAllCompaniesQcp1DataWithDateStatus(ctx context.Context, arg ListAllCompaniesQcp1DataWithDateStatusParams) ([]ListAllCompaniesQcp1DataWithDateStatusRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesQcp1DataWithDateStatus,
		pq.Array(arg.Column1),
		arg.ToTimestamp,
		arg.ToTimestamp_2,
		arg.Limit,
		arg.Offset,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesQcp1DataWithDateStatusRow{}
	for rows.Next() {
		var i ListAllCompaniesQcp1DataWithDateStatusRow
		if err := rows.Scan(
			&i.ConsignmentNo,
			&i.Client,
			&i.Country,
			&i.TraceabilityCode,
			&i.OrderID,
			&i.Batches,
			&i.Weightpassed,
			&i.Fmcode,
			&i.Fmname,
			&i.Expname,
			&i.Cropname,
			&i.CreatedAt,
			&i.Qcp1ID,
			&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 listAllCompaniesQcp1DataWithStatus = `-- name: ListAllCompaniesQcp1DataWithStatus :many
SELECT orders.consignment_no,clients.companyname as client,
countries.countryname as country,receptionform.traceability_code,
orders.id as order_id,receptionform.batches,
qcp1.weightpassed,farmers.fmcode,farmers.fmname,exportcompanies.expname,
crops.cropname,qcp1.created_at,qcp1.id as qcp1_id,
qcp1.status,qcp1.user_id,users.fullname FROM qcp1
JOIN  receptionform on receptionform.id = qcp1.receptionform_id
JOIN  farmers   on farmers.id  = receptionform.supplier_id
JOIN  crops     on crops.id    = receptionform.crop_id
JOIN  exportcompanies on exportcompanies.id = qcp1.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 = qcp1.user_id
WHERE       qcp1.status = ANY($1::text[])
ORDER BY    qcp1.created_at DESC
LIMIT   $2 OFFSET $3
`

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

type ListAllCompaniesQcp1DataWithStatusRow 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"`
	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"`
	Qcp1ID           int64          `json:"qcp1_id"`
	Status           string         `json:"status"`
	UserID           int32          `json:"user_id"`
	Fullname         string         `json:"fullname"`
}

func (q *Queries) ListAllCompaniesQcp1DataWithStatus(ctx context.Context, arg ListAllCompaniesQcp1DataWithStatusParams) ([]ListAllCompaniesQcp1DataWithStatusRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesQcp1DataWithStatus, pq.Array(arg.Column1), arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesQcp1DataWithStatusRow{}
	for rows.Next() {
		var i ListAllCompaniesQcp1DataWithStatusRow
		if err := rows.Scan(
			&i.ConsignmentNo,
			&i.Client,
			&i.Country,
			&i.TraceabilityCode,
			&i.OrderID,
			&i.Batches,
			&i.Weightpassed,
			&i.Fmcode,
			&i.Fmname,
			&i.Expname,
			&i.Cropname,
			&i.CreatedAt,
			&i.Qcp1ID,
			&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 listAllCompaniesQcp1Ds = `-- name: ListAllCompaniesQcp1Ds :many
SELECT orders.consignment_no,clients.companyname as client,
countries.countryname as country,receptionform.traceability_code,
orders.id as order_id,receptionform.batches,
qcp1.weightpassed,farmers.fmcode,farmers.fmname,exportcompanies.expname,
crops.cropname,qcp1.created_at,qcp1.id as qcp1_id,
qcp1.status,qcp1.user_id,users.fullname FROM qcp1
JOIN  receptionform on receptionform.id = qcp1.receptionform_id
JOIN  farmers   on farmers.id  = receptionform.supplier_id
JOIN  crops     on crops.id    = receptionform.crop_id
JOIN  exportcompanies on exportcompanies.id = qcp1.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 = qcp1.user_id
WHERE qcp1.status = $1
ORDER BY  qcp1.created_at DESC
`

type ListAllCompaniesQcp1DsRow 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"`
	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"`
	Qcp1ID           int64          `json:"qcp1_id"`
	Status           string         `json:"status"`
	UserID           int32          `json:"user_id"`
	Fullname         string         `json:"fullname"`
}

func (q *Queries) ListAllCompaniesQcp1Ds(ctx context.Context, status string) ([]ListAllCompaniesQcp1DsRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesQcp1Ds, status)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesQcp1DsRow{}
	for rows.Next() {
		var i ListAllCompaniesQcp1DsRow
		if err := rows.Scan(
			&i.ConsignmentNo,
			&i.Client,
			&i.Country,
			&i.TraceabilityCode,
			&i.OrderID,
			&i.Batches,
			&i.Weightpassed,
			&i.Fmcode,
			&i.Fmname,
			&i.Expname,
			&i.Cropname,
			&i.CreatedAt,
			&i.Qcp1ID,
			&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 listAllCompaniesQcp1WFs = `-- name: ListAllCompaniesQcp1WFs :many
SELECT orders.consignment_no,clients.companyname as client,
countries.countryname as country,receptionform.traceability_code,
orders.id as order_id,receptionform.batches,
qcp1.weightpassed,farmers.fmcode,farmers.fmname,exportcompanies.expname,
crops.cropname,qcp1.created_at,qcp1.id as qcp1_id,
qcp1.status,qcp1.user_id,users.fullname FROM qcp1
JOIN  receptionform on receptionform.id = qcp1.receptionform_id
JOIN  farmers   on farmers.id  = receptionform.supplier_id
JOIN  crops     on crops.id    = receptionform.crop_id
JOIN  exportcompanies on exportcompanies.id = qcp1.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 = qcp1.user_id
WHERE       qcp1.status = $1
ORDER BY    qcp1.created_at DESC
LIMIT $2 OFFSET $3
`

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

type ListAllCompaniesQcp1WFsRow 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"`
	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"`
	Qcp1ID           int64          `json:"qcp1_id"`
	Status           string         `json:"status"`
	UserID           int32          `json:"user_id"`
	Fullname         string         `json:"fullname"`
}

func (q *Queries) ListAllCompaniesQcp1WFs(ctx context.Context, arg ListAllCompaniesQcp1WFsParams) ([]ListAllCompaniesQcp1WFsRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesQcp1WFs, arg.Status, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesQcp1WFsRow{}
	for rows.Next() {
		var i ListAllCompaniesQcp1WFsRow
		if err := rows.Scan(
			&i.ConsignmentNo,
			&i.Client,
			&i.Country,
			&i.TraceabilityCode,
			&i.OrderID,
			&i.Batches,
			&i.Weightpassed,
			&i.Fmcode,
			&i.Fmname,
			&i.Expname,
			&i.Cropname,
			&i.CreatedAt,
			&i.Qcp1ID,
			&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 listAllCompaniesQcp1s = `-- name: ListAllCompaniesQcp1s :many
SELECT orders.consignment_no,clients.companyname as client,
countries.countryname as country,receptionform.traceability_code,
orders.id as order_id,receptionform.batches,
qcp1.weightpassed,farmers.fmcode,farmers.fmname,exportcompanies.expname,
crops.cropname,qcp1.created_at,qcp1.id as qcp1_id,
qcp1.status,qcp1.user_id,users.fullname FROM qcp1
JOIN  receptionform on receptionform.id = qcp1.receptionform_id
JOIN  farmers   on farmers.id  = receptionform.supplier_id
JOIN  crops     on crops.id    = receptionform.crop_id
JOIN  exportcompanies on exportcompanies.id = qcp1.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 = qcp1.user_id
WHERE qcp1.status = $1
AND         qcp1.created_at
BETWEEN     TO_TIMESTAMP($2, 'YYYY-MM-DD HH24:MI:SS')
AND         TO_TIMESTAMP($3, 'YYYY-MM-DD HH24:MI:SS')
ORDER BY    qcp1.created_at DESC
LIMIT $4 OFFSET $5
`

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

type ListAllCompaniesQcp1sRow 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"`
	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"`
	Qcp1ID           int64          `json:"qcp1_id"`
	Status           string         `json:"status"`
	UserID           int32          `json:"user_id"`
	Fullname         string         `json:"fullname"`
}

func (q *Queries) ListAllCompaniesQcp1s(ctx context.Context, arg ListAllCompaniesQcp1sParams) ([]ListAllCompaniesQcp1sRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesQcp1s,
		arg.Status,
		arg.ToTimestamp,
		arg.ToTimestamp_2,
		arg.Limit,
		arg.Offset,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesQcp1sRow{}
	for rows.Next() {
		var i ListAllCompaniesQcp1sRow
		if err := rows.Scan(
			&i.ConsignmentNo,
			&i.Client,
			&i.Country,
			&i.TraceabilityCode,
			&i.OrderID,
			&i.Batches,
			&i.Weightpassed,
			&i.Fmcode,
			&i.Fmname,
			&i.Expname,
			&i.Cropname,
			&i.CreatedAt,
			&i.Qcp1ID,
			&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 listPendingExporterQcp1s = `-- name: ListPendingExporterQcp1s :many
SELECT orders.consignment_no,receptionform.batches,farmers.fmname,farmers.fmcode,
crops.cropname, qcp1.created_at FROM qcp1
JOIN   receptionform on receptionform.id = qcp1.receptionform_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
WHERE       qcp1.exportcompany_id   = $3
ORDER BY    qcp1.created_at DESC
LIMIT $1 OFFSET $2
`

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

type ListPendingExporterQcp1sRow struct {
	ConsignmentNo sql.NullString `json:"consignment_no"`
	Batches       int32          `json:"batches"`
	Fmname        string         `json:"fmname"`
	Fmcode        sql.NullString `json:"fmcode"`
	Cropname      string         `json:"cropname"`
	CreatedAt     time.Time      `json:"created_at"`
}

func (q *Queries) ListPendingExporterQcp1s(ctx context.Context, arg ListPendingExporterQcp1sParams) ([]ListPendingExporterQcp1sRow, error) {
	rows, err := q.db.QueryContext(ctx, listPendingExporterQcp1s, arg.Limit, arg.Offset, arg.ExportcompanyID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListPendingExporterQcp1sRow{}
	for rows.Next() {
		var i ListPendingExporterQcp1sRow
		if err := rows.Scan(
			&i.ConsignmentNo,
			&i.Batches,
			&i.Fmname,
			&i.Fmcode,
			&i.Cropname,
			&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 listQcp1s = `-- name: ListQcp1s :many
SELECT id, receptionform_id, exportcompany_id, user_id, weightpassed, status, created_at FROM qcp1
LIMIT $1
OFFSET $2
`

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

func (q *Queries) ListQcp1s(ctx context.Context, arg ListQcp1sParams) ([]Qcp1, error) {
	rows, err := q.db.QueryContext(ctx, listQcp1s, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp1{}
	for rows.Next() {
		var i Qcp1
		if err := rows.Scan(
			&i.ID,
			&i.ReceptionformID,
			&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 qcp1Details = `-- name: Qcp1Details :one
SELECT orders.consignment_no consignment_no,
receptionform.netweight,receptionform.batches batches,receptionform.traceability_code,
farmers.fmname,farmers.fmcode,crops.cropname, qcp1.created_at,qcp1.status FROM qcp1
JOIN   receptionform on receptionform.id = qcp1.receptionform_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  qcp1.id = $1
`

type Qcp1DetailsRow struct {
	ConsignmentNo    sql.NullString `json:"consignment_no"`
	Netweight        float64        `json:"netweight"`
	Batches          int32          `json:"batches"`
	TraceabilityCode string         `json:"traceability_code"`
	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) Qcp1Details(ctx context.Context, id int64) (Qcp1DetailsRow, error) {
	row := q.db.QueryRowContext(ctx, qcp1Details, id)
	var i Qcp1DetailsRow
	err := row.Scan(
		&i.ConsignmentNo,
		&i.Netweight,
		&i.Batches,
		&i.TraceabilityCode,
		&i.Fmname,
		&i.Fmcode,
		&i.Cropname,
		&i.CreatedAt,
		&i.Status,
	)
	return i, err
}

const qcp1MarkAsDuplicate = `-- name: Qcp1MarkAsDuplicate :exec
UPDATE qcp1
  set
    status = 'Duplicate'
WHERE id = $1
RETURNING id, receptionform_id, exportcompany_id, user_id, weightpassed, status, created_at
`

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

const qcp1OrderSum = `-- name: Qcp1OrderSum :one
SELECT COUNT(id)
FROM  qcp1
JOIN  receptionform on receptionform.id = qcp1.receptionform_id
WHERE qcp1.status IN ('Pending', 'AwaitingResort','ReSorting')
AND   receptionform.order_id = $1
`

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

const qcp1PerOrder = `-- name: Qcp1PerOrder :many
SELECT qcp1.receptionform_id,qcp1.id as qcp1_id,crops.variant,crops.cropname,crops.cropname,crops.variant,
receptionform.traceability_code,qcp1_recommendation.netweightrejected,
qcp1_recommendation.netweightpassed,qcp1_recommendation.status
from qcp1
INNER  JOIN  qcp1_recommendation  on qcp1_recommendation.qcp1_id     = qcp1.id
INNER  JOIN  receptionform        on receptionform.id                = qcp1.receptionform_id
INNER  JOIN  crops                on crops.id                        = receptionform.crop_id
WHERE  receptionform.order_id = $1
`

type Qcp1PerOrderRow struct {
	ReceptionformID   int32           `json:"receptionform_id"`
	Qcp1ID            int64           `json:"qcp1_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) Qcp1PerOrder(ctx context.Context, orderID int32) ([]Qcp1PerOrderRow, error) {
	rows, err := q.db.QueryContext(ctx, qcp1PerOrder, orderID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp1PerOrderRow{}
	for rows.Next() {
		var i Qcp1PerOrderRow
		if err := rows.Scan(
			&i.ReceptionformID,
			&i.Qcp1ID,
			&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 qcp1QualityAttributesPerOrder = `-- name: Qcp1QualityAttributesPerOrder :many
SELECT qcp1_attributes.qtyremoved, qcp1_attributes.qtytaken,qcp1_attributes.id,
qcp1_attributes.percentage,qualityattributes.description FROM qcp1_attributes
INNER JOIN qcp1 on qcp1.id = qcp1_attributes.qcp1_id
INNER JOIN qualityattributes on qualityattributes.id = qcp1_attributes.qualityattribute_id
where qcp1.id = $1
`

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

func (q *Queries) Qcp1QualityAttributesPerOrder(ctx context.Context, id int64) ([]Qcp1QualityAttributesPerOrderRow, error) {
	rows, err := q.db.QueryContext(ctx, qcp1QualityAttributesPerOrder, id)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp1QualityAttributesPerOrderRow{}
	for rows.Next() {
		var i Qcp1QualityAttributesPerOrderRow
		if err := rows.Scan(
			&i.Qtyremoved,
			&i.Qtytaken,
			&i.ID,
			&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 qcp1Report = `-- name: Qcp1Report :one
SELECT qcp1.exportcompany_id,
qualityattributes.description,
qcp1.created_at,exportcompanies.expname exportcompany_name,
users.fullname user_name,qcp1.receptionform_id,
qcp1.user_id,qcp1.weightpassed,qcp1.status qcp1_status,clients.companyname,countries.countryname,crops.cropname,
qcp1_attributes.qualityattribute_id,qcp1_attributes.qtyRemoved,
qcp1_attributes.qtyTaken,qcp1_attributes.other,
qcp1_attributes.percentage,
qcp1_attributes.qcp1_id,
qcp1_recommendation.status recommendation_status,
qcp1_recommendation.netweightrejected,
qcp1_recommendation.netweightpassed,
qcp1_recommendation.other,
exportcompanies.logo,
receptionform.traceability_code as traceabilitycode FROM qcp1
LEFT JOIN receptionform       on receptionform.id   = qcp1.receptionform_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 qcp1_attributes on qcp1_attributes.qcp1_id = qcp1.id
LEFT JOIN qcp1_recommendation on qcp1_recommendation.qcp1_id = qcp1.id
LEFT JOIN qualityattributes   on qualityattributes.id  = qcp1_attributes.qualityattribute_id
WHERE qcp1.id = $1
`

type Qcp1ReportRow 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"`
	ReceptionformID      int32           `json:"receptionform_id"`
	UserID               int32           `json:"user_id"`
	Weightpassed         float64         `json:"weightpassed"`
	Qcp1Status           string          `json:"qcp1_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"`
	Qcp1ID               sql.NullInt32   `json:"qcp1_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) Qcp1Report(ctx context.Context, id int64) (Qcp1ReportRow, error) {
	row := q.db.QueryRowContext(ctx, qcp1Report, id)
	var i Qcp1ReportRow
	err := row.Scan(
		&i.ExportcompanyID,
		&i.Description,
		&i.CreatedAt,
		&i.ExportcompanyName,
		&i.UserName,
		&i.ReceptionformID,
		&i.UserID,
		&i.Weightpassed,
		&i.Qcp1Status,
		&i.Companyname,
		&i.Countryname,
		&i.Cropname,
		&i.QualityattributeID,
		&i.Qtyremoved,
		&i.Qtytaken,
		&i.Other,
		&i.Percentage,
		&i.Qcp1ID,
		&i.RecommendationStatus,
		&i.Netweightrejected,
		&i.Netweightpassed,
		&i.Other_2,
		&i.Logo,
		&i.Traceabilitycode,
	)
	return i, err
}

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

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

const updateQcP1Status = `-- name: UpdateQcP1Status :exec
UPDATE qcp1
  set
    status = $2
WHERE id = $1
RETURNING id, receptionform_id, exportcompany_id, user_id, weightpassed, status, created_at
`

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

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

const updateQcp1 = `-- name: UpdateQcp1 :one
UPDATE qcp1
  set
      exportcompany_id = $5,
      receptionform_id = $4,
      user_id = $3,
      status = $2
WHERE id = $1
RETURNING id, receptionform_id, exportcompany_id, user_id, weightpassed, status, created_at
`

type UpdateQcp1Params struct {
	ID              int64  `json:"id"`
	Status          string `json:"status"`
	UserID          int32  `json:"user_id"`
	ReceptionformID int32  `json:"receptionform_id"`
	ExportcompanyID int32  `json:"exportcompany_id"`
}

func (q *Queries) UpdateQcp1(ctx context.Context, arg UpdateQcp1Params) (Qcp1, error) {
	row := q.db.QueryRowContext(ctx, updateQcp1,
		arg.ID,
		arg.Status,
		arg.UserID,
		arg.ReceptionformID,
		arg.ExportcompanyID,
	)
	var i Qcp1
	err := row.Scan(
		&i.ID,
		&i.ReceptionformID,
		&i.ExportcompanyID,
		&i.UserID,
		&i.Weightpassed,
		&i.Status,
		&i.CreatedAt,
	)
	return i, err
}
