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

package db

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

const createInspectionReport = `-- name: CreateInspectionReport :one
INSERT INTO inspectionreport (
    consignment_no,
    notes,
    instruction,
    user_id,
    exportcompany_id
 ) VALUES (
     $1,
     $2,
     $3,
     $4,
     $5
    )
RETURNING id, consignment_no, notes, instruction, user_id, exportcompany_id, created_at
`

type CreateInspectionReportParams struct {
	ConsignmentNo   string `json:"consignment_no"`
	Notes           string `json:"notes"`
	Instruction     string `json:"instruction"`
	UserID          int32  `json:"user_id"`
	ExportcompanyID int32  `json:"exportcompany_id"`
}

func (q *Queries) CreateInspectionReport(ctx context.Context, arg CreateInspectionReportParams) (Inspectionreport, error) {
	row := q.db.QueryRowContext(ctx, createInspectionReport,
		arg.ConsignmentNo,
		arg.Notes,
		arg.Instruction,
		arg.UserID,
		arg.ExportcompanyID,
	)
	var i Inspectionreport
	err := row.Scan(
		&i.ID,
		&i.ConsignmentNo,
		&i.Notes,
		&i.Instruction,
		&i.UserID,
		&i.ExportcompanyID,
		&i.CreatedAt,
	)
	return i, err
}

const createQcp4 = `-- name: CreateQcp4 :one
INSERT INTO qcp4 (
    packinglist_id,
    status,
    user_id,
    exportcompany_id
 ) VALUES (
     $1,
     $2,
     $3,
     $4
    )
RETURNING id, packinglist_id, user_id, status, exportcompany_id, created_at
`

type CreateQcp4Params struct {
	PackinglistID   int32  `json:"packinglist_id"`
	Status          string `json:"status"`
	UserID          int32  `json:"user_id"`
	ExportcompanyID int32  `json:"exportcompany_id"`
}

func (q *Queries) CreateQcp4(ctx context.Context, arg CreateQcp4Params) (Qcp4, error) {
	row := q.db.QueryRowContext(ctx, createQcp4,
		arg.PackinglistID,
		arg.Status,
		arg.UserID,
		arg.ExportcompanyID,
	)
	var i Qcp4
	err := row.Scan(
		&i.ID,
		&i.PackinglistID,
		&i.UserID,
		&i.Status,
		&i.ExportcompanyID,
		&i.CreatedAt,
	)
	return i, err
}

const createQcp4Attributes = `-- name: CreateQcp4Attributes :one
INSERT INTO qcp4_attributes (
    qcp4_id,
    qualityattributes_id,
    qcp4_product_id,
    user_id,
    exportcompany_id
 ) VALUES (
     $1,
     $2,
     $3,
     $4,
     $5
    )
RETURNING id, qcp4_id, qualityattributes_id, qcp4_product_id, user_id, exportcompany_id, created_at
`

type CreateQcp4AttributesParams struct {
	Qcp4ID              int32 `json:"qcp4_id"`
	QualityattributesID int32 `json:"qualityattributes_id"`
	Qcp4ProductID       int32 `json:"qcp4_product_id"`
	UserID              int32 `json:"user_id"`
	ExportcompanyID     int32 `json:"exportcompany_id"`
}

func (q *Queries) CreateQcp4Attributes(ctx context.Context, arg CreateQcp4AttributesParams) (Qcp4Attribute, error) {
	row := q.db.QueryRowContext(ctx, createQcp4Attributes,
		arg.Qcp4ID,
		arg.QualityattributesID,
		arg.Qcp4ProductID,
		arg.UserID,
		arg.ExportcompanyID,
	)
	var i Qcp4Attribute
	err := row.Scan(
		&i.ID,
		&i.Qcp4ID,
		&i.QualityattributesID,
		&i.Qcp4ProductID,
		&i.UserID,
		&i.ExportcompanyID,
		&i.CreatedAt,
	)
	return i, err
}

const createQcp4OtherQualityAttributes = `-- name: CreateQcp4OtherQualityAttributes :one
INSERT INTO qcp4_other_attributes(
     qcp4_id,
     qcp4_other_id,
     qualityattributes_id,
     other ,
     user_id,
     exportcompany_id
) VALUES (
    $1,
    $2,
    $3,
    $4,
    $5,
    $6
)
RETURNING id, qcp4_id, qcp4_other_id, other, qualityattributes_id, user_id, exportcompany_id, created_at
`

type CreateQcp4OtherQualityAttributesParams struct {
	Qcp4ID              int32  `json:"qcp4_id"`
	Qcp4OtherID         int32  `json:"qcp4_other_id"`
	QualityattributesID int32  `json:"qualityattributes_id"`
	Other               string `json:"other"`
	UserID              int32  `json:"user_id"`
	ExportcompanyID     int32  `json:"exportcompany_id"`
}

func (q *Queries) CreateQcp4OtherQualityAttributes(ctx context.Context, arg CreateQcp4OtherQualityAttributesParams) (Qcp4OtherAttribute, error) {
	row := q.db.QueryRowContext(ctx, createQcp4OtherQualityAttributes,
		arg.Qcp4ID,
		arg.Qcp4OtherID,
		arg.QualityattributesID,
		arg.Other,
		arg.UserID,
		arg.ExportcompanyID,
	)
	var i Qcp4OtherAttribute
	err := row.Scan(
		&i.ID,
		&i.Qcp4ID,
		&i.Qcp4OtherID,
		&i.Other,
		&i.QualityattributesID,
		&i.UserID,
		&i.ExportcompanyID,
		&i.CreatedAt,
	)
	return i, err
}

const createQcp4OtherRecommendations = `-- name: CreateQcp4OtherRecommendations :one
INSERT INTO qcp4_otherrecommendations (
    qcp4_id,
    qcp4_others_id,
    status,
    reason,
    weight_rejected,
    weight_passed,
    user_id,
    exportcompany_id
 ) VALUES (
     $1,
     $2,
     $3,
     $4,
     $5,
     $6,
     $7,
     $8
    )
RETURNING id, qcp4_id, qcp4_others_id, status, reason, weight_rejected, weight_passed, user_id, exportcompany_id, created_at
`

type CreateQcp4OtherRecommendationsParams struct {
	Qcp4ID          int32          `json:"qcp4_id"`
	Qcp4OthersID    int32          `json:"qcp4_others_id"`
	Status          string         `json:"status"`
	Reason          sql.NullString `json:"reason"`
	WeightRejected  float64        `json:"weight_rejected"`
	WeightPassed    float64        `json:"weight_passed"`
	UserID          int32          `json:"user_id"`
	ExportcompanyID int32          `json:"exportcompany_id"`
}

func (q *Queries) CreateQcp4OtherRecommendations(ctx context.Context, arg CreateQcp4OtherRecommendationsParams) (Qcp4Otherrecommendation, error) {
	row := q.db.QueryRowContext(ctx, createQcp4OtherRecommendations,
		arg.Qcp4ID,
		arg.Qcp4OthersID,
		arg.Status,
		arg.Reason,
		arg.WeightRejected,
		arg.WeightPassed,
		arg.UserID,
		arg.ExportcompanyID,
	)
	var i Qcp4Otherrecommendation
	err := row.Scan(
		&i.ID,
		&i.Qcp4ID,
		&i.Qcp4OthersID,
		&i.Status,
		&i.Reason,
		&i.WeightRejected,
		&i.WeightPassed,
		&i.UserID,
		&i.ExportcompanyID,
		&i.CreatedAt,
	)
	return i, err
}

const createQcp4Others = `-- name: CreateQcp4Others :one
INSERT INTO qcp4_others (
    qcp4_id,
    packinglist_id,
    product_name,
    noofboxes,
    sampledboxes,
    boxweight,
    productnetweight,
    totalproductnetweight,
    totalproductgrossweight,
    status,
    user_id,
    exportcompany_id
 ) VALUES (
     $1,
     $2,
     $3,
     $4,
     $5,
     $6,
     $7,
     $8,
     $9,
     $10,
     $11,
     $12
    )
RETURNING id, qcp4_id, packinglist_id, product_name, noofboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, sampledboxes, status, user_id, exportcompany_id, created_at
`

type CreateQcp4OthersParams struct {
	Qcp4ID                  int32           `json:"qcp4_id"`
	PackinglistID           int32           `json:"packinglist_id"`
	ProductName             string          `json:"product_name"`
	Noofboxes               int32           `json:"noofboxes"`
	Sampledboxes            sql.NullInt32   `json:"sampledboxes"`
	Boxweight               sql.NullFloat64 `json:"boxweight"`
	Productnetweight        sql.NullFloat64 `json:"productnetweight"`
	Totalproductnetweight   sql.NullFloat64 `json:"totalproductnetweight"`
	Totalproductgrossweight sql.NullFloat64 `json:"totalproductgrossweight"`
	Status                  string          `json:"status"`
	UserID                  int32           `json:"user_id"`
	ExportcompanyID         int32           `json:"exportcompany_id"`
}

func (q *Queries) CreateQcp4Others(ctx context.Context, arg CreateQcp4OthersParams) (Qcp4Other, error) {
	row := q.db.QueryRowContext(ctx, createQcp4Others,
		arg.Qcp4ID,
		arg.PackinglistID,
		arg.ProductName,
		arg.Noofboxes,
		arg.Sampledboxes,
		arg.Boxweight,
		arg.Productnetweight,
		arg.Totalproductnetweight,
		arg.Totalproductgrossweight,
		arg.Status,
		arg.UserID,
		arg.ExportcompanyID,
	)
	var i Qcp4Other
	err := row.Scan(
		&i.ID,
		&i.Qcp4ID,
		&i.PackinglistID,
		&i.ProductName,
		&i.Noofboxes,
		&i.Boxweight,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.Sampledboxes,
		&i.Status,
		&i.UserID,
		&i.ExportcompanyID,
		&i.CreatedAt,
	)
	return i, err
}

const createQcp4Products = `-- name: CreateQcp4Products :one
INSERT INTO qcp4_products (
    qcp4_id,
    traceability_code,
    product_id,
	totalboxes,
    boxweight,
    productnetweight,
    totalproductnetweight,
    totalproductgrossweight,
    sampledboxes,
    status
 ) VALUES (
     $1,
     $2,
     $3,
     $4,
     $5,
     $6,
     $7,
     $8,
     $9,
     $10
    )
RETURNING id, qcp4_id, traceability_code, product_id, totalboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, status, sampledboxes, created_at
`

type CreateQcp4ProductsParams struct {
	Qcp4ID                  int32           `json:"qcp4_id"`
	TraceabilityCode        string          `json:"traceability_code"`
	ProductID               int32           `json:"product_id"`
	Totalboxes              int32           `json:"totalboxes"`
	Boxweight               sql.NullFloat64 `json:"boxweight"`
	Productnetweight        sql.NullFloat64 `json:"productnetweight"`
	Totalproductnetweight   sql.NullFloat64 `json:"totalproductnetweight"`
	Totalproductgrossweight sql.NullFloat64 `json:"totalproductgrossweight"`
	Sampledboxes            sql.NullInt32   `json:"sampledboxes"`
	Status                  string          `json:"status"`
}

func (q *Queries) CreateQcp4Products(ctx context.Context, arg CreateQcp4ProductsParams) (Qcp4Product, error) {
	row := q.db.QueryRowContext(ctx, createQcp4Products,
		arg.Qcp4ID,
		arg.TraceabilityCode,
		arg.ProductID,
		arg.Totalboxes,
		arg.Boxweight,
		arg.Productnetweight,
		arg.Totalproductnetweight,
		arg.Totalproductgrossweight,
		arg.Sampledboxes,
		arg.Status,
	)
	var i Qcp4Product
	err := row.Scan(
		&i.ID,
		&i.Qcp4ID,
		&i.TraceabilityCode,
		&i.ProductID,
		&i.Totalboxes,
		&i.Boxweight,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.Status,
		&i.Sampledboxes,
		&i.CreatedAt,
	)
	return i, err
}

const createQcp4Recommendations = `-- name: CreateQcp4Recommendations :one
INSERT INTO qcp4_recommendations (
    qcp4_id,
    qcp4_product_id,
    status,
    reason,
    weight_rejected,
    weight_passed,
    user_id,
    exportcompany_id
 ) VALUES (
     $1,
     $2,
     $3,
     $4,
     $5,
     $6,
     $7,
     $8
    )
RETURNING id, qcp4_id, status, qcp4_product_id, reason, weight_rejected, weight_passed, user_id, exportcompany_id, created_at
`

type CreateQcp4RecommendationsParams struct {
	Qcp4ID          int32          `json:"qcp4_id"`
	Qcp4ProductID   int32          `json:"qcp4_product_id"`
	Status          string         `json:"status"`
	Reason          sql.NullString `json:"reason"`
	WeightRejected  float64        `json:"weight_rejected"`
	WeightPassed    float64        `json:"weight_passed"`
	UserID          int32          `json:"user_id"`
	ExportcompanyID int32          `json:"exportcompany_id"`
}

func (q *Queries) CreateQcp4Recommendations(ctx context.Context, arg CreateQcp4RecommendationsParams) (Qcp4Recommendation, error) {
	row := q.db.QueryRowContext(ctx, createQcp4Recommendations,
		arg.Qcp4ID,
		arg.Qcp4ProductID,
		arg.Status,
		arg.Reason,
		arg.WeightRejected,
		arg.WeightPassed,
		arg.UserID,
		arg.ExportcompanyID,
	)
	var i Qcp4Recommendation
	err := row.Scan(
		&i.ID,
		&i.Qcp4ID,
		&i.Status,
		&i.Qcp4ProductID,
		&i.Reason,
		&i.WeightRejected,
		&i.WeightPassed,
		&i.UserID,
		&i.ExportcompanyID,
		&i.CreatedAt,
	)
	return i, err
}

const filterQcp4PerOrder = `-- name: FilterQcp4PerOrder :many
Select distinct on(qcp4_attributes.qualityattributes_id, qcp4_other_attributes.qualityattributes_id) qcp4_attributes.qualityattributes_id as qcp4_attri_id,
qcp4_other_attributes.qualityattributes_id as qcp4_other_attri_id,qcp4_products.qcp4_id,qcp4_products.traceability_code,
qcp4_products.product_id,qcp4_products.totalboxes,qcp4_products.boxweight,qcp4_products.productnetweight,
qcp4_products.totalproductnetweight,qcp4_products.totalproductgrossweight,crops.id as crop_id,crops.cropname,crops.variant,qcp4_products.sampledboxes,qcp4_products.status,
qualityattributes.description,qcp4_others.product_name others_product_name,qcp4_others.noofboxes others_boxes_number, qcp4_others.boxweight other_box_weight,
qcp4_others.productnetweight others_product_netweight,qcp4_others.totalproductnetweight others_total_productweight,qcp4_others.totalproductgrossweight others_total_productgrossweight,
qcp4_others.sampledboxes other_sampled_boxes,qcp4_others.status others_status,orders.created_at order_date,clients.companyname,countries.countryname,exportcompanies.expname,exportcompanies.expregno,qcp4_recommendations.status recommendation_status,
qcp4_recommendations.weight_passed qcp4_weight_pass,qcp4_recommendations.weight_rejected as weight_rejected,packhouses.phname,orders.consignment_no,orders.status as order_status, orders.id as order_id, qcp4.user_id as inspector_id,
packinglist.user_id as qualitycontroller_id,exportcompanies.id as exportcompany_id FROM qcp4
LEFT JOIN qcp4_products           on qcp4_products.qcp4_id                  = qcp4.id
LEFT JOIN qcp4_others             on qcp4_others.qcp4_id                    = qcp4.id
LEFT JOIN qcp4_other_attributes   on qcp4_other_attributes.qcp4_id          = qcp4.id
LEFT JOIN qcp4_attributes         on qcp4_attributes.qcp4_product_id        = qcp4_products.id
LEFT JOIN qcp4_recommendations    on qcp4_recommendations.qcp4_product_id   = qcp4_products.id
LEFT JOIN qualityattributes       on qualityattributes.id                   = qcp4_attributes.qualityattributes_id
LEFT JOIN packinglist             on packinglist.id                         = qcp4.packinglist_id
LEFT JOIN orders                  on orders.id                              = packinglist.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                     = qcp4.exportcompany_id
LEFT JOIN packhouse_exporter      on packhouse_exporter.exportcompany_id    = exportcompanies.id
LEFT JOIN packhouses              on packhouses.id                          = packhouse_exporter.packhouse_id
LEFT JOIN crops                   on crops.id                               = qcp4_products.product_id
LEFT JOIN users                   on users.id                               = qcp4.user_id
WHERE qcp4.id = $1
`

type FilterQcp4PerOrderRow struct {
	Qcp4AttriID                   sql.NullInt32   `json:"qcp4_attri_id"`
	Qcp4OtherAttriID              sql.NullInt32   `json:"qcp4_other_attri_id"`
	Qcp4ID                        sql.NullInt32   `json:"qcp4_id"`
	TraceabilityCode              sql.NullString  `json:"traceability_code"`
	ProductID                     sql.NullInt32   `json:"product_id"`
	Totalboxes                    sql.NullInt32   `json:"totalboxes"`
	Boxweight                     sql.NullFloat64 `json:"boxweight"`
	Productnetweight              sql.NullFloat64 `json:"productnetweight"`
	Totalproductnetweight         sql.NullFloat64 `json:"totalproductnetweight"`
	Totalproductgrossweight       sql.NullFloat64 `json:"totalproductgrossweight"`
	CropID                        sql.NullInt64   `json:"crop_id"`
	Cropname                      sql.NullString  `json:"cropname"`
	Variant                       sql.NullString  `json:"variant"`
	Sampledboxes                  sql.NullInt32   `json:"sampledboxes"`
	Status                        sql.NullString  `json:"status"`
	Description                   sql.NullString  `json:"description"`
	OthersProductName             sql.NullString  `json:"others_product_name"`
	OthersBoxesNumber             sql.NullInt32   `json:"others_boxes_number"`
	OtherBoxWeight                sql.NullFloat64 `json:"other_box_weight"`
	OthersProductNetweight        sql.NullFloat64 `json:"others_product_netweight"`
	OthersTotalProductweight      sql.NullFloat64 `json:"others_total_productweight"`
	OthersTotalProductgrossweight sql.NullFloat64 `json:"others_total_productgrossweight"`
	OtherSampledBoxes             sql.NullInt32   `json:"other_sampled_boxes"`
	OthersStatus                  sql.NullString  `json:"others_status"`
	OrderDate                     sql.NullTime    `json:"order_date"`
	Companyname                   sql.NullString  `json:"companyname"`
	Countryname                   sql.NullString  `json:"countryname"`
	Expname                       sql.NullString  `json:"expname"`
	Expregno                      sql.NullString  `json:"expregno"`
	RecommendationStatus          sql.NullString  `json:"recommendation_status"`
	Qcp4WeightPass                sql.NullFloat64 `json:"qcp4_weight_pass"`
	WeightRejected                sql.NullFloat64 `json:"weight_rejected"`
	Phname                        sql.NullString  `json:"phname"`
	ConsignmentNo                 sql.NullString  `json:"consignment_no"`
	OrderStatus                   sql.NullString  `json:"order_status"`
	OrderID                       sql.NullInt64   `json:"order_id"`
	InspectorID                   int32           `json:"inspector_id"`
	QualitycontrollerID           sql.NullInt32   `json:"qualitycontroller_id"`
	ExportcompanyID               sql.NullInt64   `json:"exportcompany_id"`
}

func (q *Queries) FilterQcp4PerOrder(ctx context.Context, id int64) ([]FilterQcp4PerOrderRow, error) {
	rows, err := q.db.QueryContext(ctx, filterQcp4PerOrder, id)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []FilterQcp4PerOrderRow{}
	for rows.Next() {
		var i FilterQcp4PerOrderRow
		if err := rows.Scan(
			&i.Qcp4AttriID,
			&i.Qcp4OtherAttriID,
			&i.Qcp4ID,
			&i.TraceabilityCode,
			&i.ProductID,
			&i.Totalboxes,
			&i.Boxweight,
			&i.Productnetweight,
			&i.Totalproductnetweight,
			&i.Totalproductgrossweight,
			&i.CropID,
			&i.Cropname,
			&i.Variant,
			&i.Sampledboxes,
			&i.Status,
			&i.Description,
			&i.OthersProductName,
			&i.OthersBoxesNumber,
			&i.OtherBoxWeight,
			&i.OthersProductNetweight,
			&i.OthersTotalProductweight,
			&i.OthersTotalProductgrossweight,
			&i.OtherSampledBoxes,
			&i.OthersStatus,
			&i.OrderDate,
			&i.Companyname,
			&i.Countryname,
			&i.Expname,
			&i.Expregno,
			&i.RecommendationStatus,
			&i.Qcp4WeightPass,
			&i.WeightRejected,
			&i.Phname,
			&i.ConsignmentNo,
			&i.OrderStatus,
			&i.OrderID,
			&i.InspectorID,
			&i.QualitycontrollerID,
			&i.ExportcompanyID,
		); 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 getConsignmentNoByQcp4ID = `-- name: GetConsignmentNoByQcp4ID :one
SELECT orders.consignment_no, qcp4.id as qcp4_id from qcp4
LEFT JOIN packinglist  on packinglist.id   = qcp4.packinglist_id
LEFT JOIN orders       on orders.id        = packinglist.order_id
WHERE qcp4.id = $1
`

type GetConsignmentNoByQcp4IDRow struct {
	ConsignmentNo sql.NullString `json:"consignment_no"`
	Qcp4ID        int64          `json:"qcp4_id"`
}

func (q *Queries) GetConsignmentNoByQcp4ID(ctx context.Context, id int64) (GetConsignmentNoByQcp4IDRow, error) {
	row := q.db.QueryRowContext(ctx, getConsignmentNoByQcp4ID, id)
	var i GetConsignmentNoByQcp4IDRow
	err := row.Scan(&i.ConsignmentNo, &i.Qcp4ID)
	return i, err
}

const getPackhouseInspectorID = `-- name: GetPackhouseInspectorID :one
SELECT user_id FROM qcp4_recommendations
WHERE qcp4_id = $1 LIMIT 1
`

func (q *Queries) GetPackhouseInspectorID(ctx context.Context, qcp4ID int32) (int32, error) {
	row := q.db.QueryRowContext(ctx, getPackhouseInspectorID, qcp4ID)
	var user_id int32
	err := row.Scan(&user_id)
	return user_id, err
}

const getPackingListIDFromQcp4 = `-- name: GetPackingListIDFromQcp4 :one
SELECT id,user_id,exportcompany_id FROM qcp4
WHERE  packinglist_id= $1 LIMIT 1
`

type GetPackingListIDFromQcp4Row struct {
	ID              int64 `json:"id"`
	UserID          int32 `json:"user_id"`
	ExportcompanyID int32 `json:"exportcompany_id"`
}

func (q *Queries) GetPackingListIDFromQcp4(ctx context.Context, packinglistID int32) (GetPackingListIDFromQcp4Row, error) {
	row := q.db.QueryRowContext(ctx, getPackingListIDFromQcp4, packinglistID)
	var i GetPackingListIDFromQcp4Row
	err := row.Scan(&i.ID, &i.UserID, &i.ExportcompanyID)
	return i, err
}

const getQcp4 = `-- name: GetQcp4 :one
SELECT id, packinglist_id, user_id, status, exportcompany_id, created_at FROM qcp4
WHERE id = $1 LIMIT 1
`

func (q *Queries) GetQcp4(ctx context.Context, id int64) (Qcp4, error) {
	row := q.db.QueryRowContext(ctx, getQcp4, id)
	var i Qcp4
	err := row.Scan(
		&i.ID,
		&i.PackinglistID,
		&i.UserID,
		&i.Status,
		&i.ExportcompanyID,
		&i.CreatedAt,
	)
	return i, err
}

const getQcp4Attributes = `-- name: GetQcp4Attributes :many
SELECT id, qcp4_id, qualityattributes_id, qcp4_product_id, user_id, exportcompany_id, created_at FROM qcp4_attributes
WHERE qcp4_id = $1
`

func (q *Queries) GetQcp4Attributes(ctx context.Context, qcp4ID int32) ([]Qcp4Attribute, error) {
	rows, err := q.db.QueryContext(ctx, getQcp4Attributes, qcp4ID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp4Attribute{}
	for rows.Next() {
		var i Qcp4Attribute
		if err := rows.Scan(
			&i.ID,
			&i.Qcp4ID,
			&i.QualityattributesID,
			&i.Qcp4ProductID,
			&i.UserID,
			&i.ExportcompanyID,
			&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 getQcp4DetailsRes = `-- name: GetQcp4DetailsRes :one
SELECT qcp4.packinglist_id,qcp4.user_id,qcp4.status,qcp4.created_at, orders.consignment_no,qcp4.exportcompany_id FROM qcp4
JOIN   packinglist on packinglist.id = qcp4.packinglist_id
JOIN   orders      on orders.id      = packinglist.order_id
WHERE qcp4.id = $1 LIMIT 1
`

type GetQcp4DetailsResRow struct {
	PackinglistID   int32          `json:"packinglist_id"`
	UserID          int32          `json:"user_id"`
	Status          string         `json:"status"`
	CreatedAt       time.Time      `json:"created_at"`
	ConsignmentNo   sql.NullString `json:"consignment_no"`
	ExportcompanyID int32          `json:"exportcompany_id"`
}

func (q *Queries) GetQcp4DetailsRes(ctx context.Context, id int64) (GetQcp4DetailsResRow, error) {
	row := q.db.QueryRowContext(ctx, getQcp4DetailsRes, id)
	var i GetQcp4DetailsResRow
	err := row.Scan(
		&i.PackinglistID,
		&i.UserID,
		&i.Status,
		&i.CreatedAt,
		&i.ConsignmentNo,
		&i.ExportcompanyID,
	)
	return i, err
}

const getQcp4OtherAttributes = `-- name: GetQcp4OtherAttributes :many
SELECT id, qcp4_id, qcp4_other_id, other, qualityattributes_id, user_id, exportcompany_id, created_at FROM qcp4_other_attributes
WHERE qcp4_id = $1
`

func (q *Queries) GetQcp4OtherAttributes(ctx context.Context, qcp4ID int32) ([]Qcp4OtherAttribute, error) {
	rows, err := q.db.QueryContext(ctx, getQcp4OtherAttributes, qcp4ID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp4OtherAttribute{}
	for rows.Next() {
		var i Qcp4OtherAttribute
		if err := rows.Scan(
			&i.ID,
			&i.Qcp4ID,
			&i.Qcp4OtherID,
			&i.Other,
			&i.QualityattributesID,
			&i.UserID,
			&i.ExportcompanyID,
			&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 getQcp4OtherRecommendations = `-- name: GetQcp4OtherRecommendations :one
SELECT id, qcp4_id, qcp4_others_id, status, reason, weight_rejected, weight_passed, user_id, exportcompany_id, created_at FROM qcp4_otherrecommendations
WHERE qcp4_id = $1 LIMIT 1
`

func (q *Queries) GetQcp4OtherRecommendations(ctx context.Context, qcp4ID int32) (Qcp4Otherrecommendation, error) {
	row := q.db.QueryRowContext(ctx, getQcp4OtherRecommendations, qcp4ID)
	var i Qcp4Otherrecommendation
	err := row.Scan(
		&i.ID,
		&i.Qcp4ID,
		&i.Qcp4OthersID,
		&i.Status,
		&i.Reason,
		&i.WeightRejected,
		&i.WeightPassed,
		&i.UserID,
		&i.ExportcompanyID,
		&i.CreatedAt,
	)
	return i, err
}

const getQcp4Others = `-- name: GetQcp4Others :one
SELECT id, qcp4_id, packinglist_id, product_name, noofboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, sampledboxes, status, user_id, exportcompany_id, created_at FROM qcp4_others
WHERE id = $1 LIMIT 1
`

func (q *Queries) GetQcp4Others(ctx context.Context, id int64) (Qcp4Other, error) {
	row := q.db.QueryRowContext(ctx, getQcp4Others, id)
	var i Qcp4Other
	err := row.Scan(
		&i.ID,
		&i.Qcp4ID,
		&i.PackinglistID,
		&i.ProductName,
		&i.Noofboxes,
		&i.Boxweight,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.Sampledboxes,
		&i.Status,
		&i.UserID,
		&i.ExportcompanyID,
		&i.CreatedAt,
	)
	return i, err
}

const getQcp4OthersByID = `-- name: GetQcp4OthersByID :many
SELECT id, qcp4_id, packinglist_id, product_name, noofboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, sampledboxes, status, user_id, exportcompany_id, created_at FROM qcp4_others
WHERE qcp4_id = $1
`

func (q *Queries) GetQcp4OthersByID(ctx context.Context, qcp4ID int32) ([]Qcp4Other, error) {
	rows, err := q.db.QueryContext(ctx, getQcp4OthersByID, qcp4ID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp4Other{}
	for rows.Next() {
		var i Qcp4Other
		if err := rows.Scan(
			&i.ID,
			&i.Qcp4ID,
			&i.PackinglistID,
			&i.ProductName,
			&i.Noofboxes,
			&i.Boxweight,
			&i.Productnetweight,
			&i.Totalproductnetweight,
			&i.Totalproductgrossweight,
			&i.Sampledboxes,
			&i.Status,
			&i.UserID,
			&i.ExportcompanyID,
			&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 getQcp4OthersByPackinglistID = `-- name: GetQcp4OthersByPackinglistID :many
SELECT id, qcp4_id, packinglist_id, product_name, noofboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, sampledboxes, status, user_id, exportcompany_id, created_at FROM qcp4_others
WHERE  qcp4_others.packinglist_id = $1
`

func (q *Queries) GetQcp4OthersByPackinglistID(ctx context.Context, packinglistID int32) ([]Qcp4Other, error) {
	rows, err := q.db.QueryContext(ctx, getQcp4OthersByPackinglistID, packinglistID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp4Other{}
	for rows.Next() {
		var i Qcp4Other
		if err := rows.Scan(
			&i.ID,
			&i.Qcp4ID,
			&i.PackinglistID,
			&i.ProductName,
			&i.Noofboxes,
			&i.Boxweight,
			&i.Productnetweight,
			&i.Totalproductnetweight,
			&i.Totalproductgrossweight,
			&i.Sampledboxes,
			&i.Status,
			&i.UserID,
			&i.ExportcompanyID,
			&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 getQcp4ProductsByID = `-- name: GetQcp4ProductsByID :many
SELECT qcp4_products.id,qcp4_products.status,
qcp4_products.qcp4_id,qcp4_products.traceability_code,
qcp4_products.totalboxes,qcp4_products.boxweight,qcp4_products.created_at,
qcp4_products.product_id,crops.cropname product_name,clients.companyname,
qcp4_products.sampledboxes,qcp4_products.productnetweight,
qcp4_products.totalproductnetweight,qcp4_products.totalproductgrossweight,orders.consignment_no,
exportcompanies.expname,orders.id as order_id,packinglist.id as packinglist_id
FROM  qcp4_products
JOIN  qcp4            on qcp4.id            = qcp4_products.qcp4_id
JOIN  packinglist     on packinglist.id     = qcp4.packinglist_id
JOIN  orders          on orders.id          = packinglist.order_id
JOIN  clients         on clients.id         = orders.client_id
JOIN  exportcompanies on exportcompanies.id = packinglist.exportcompany_id
JOIN  crops           on crops.id           = qcp4_products.product_id
WHERE qcp4_id = $1
`

type GetQcp4ProductsByIDRow struct {
	ID                      int64           `json:"id"`
	Status                  string          `json:"status"`
	Qcp4ID                  int32           `json:"qcp4_id"`
	TraceabilityCode        string          `json:"traceability_code"`
	Totalboxes              int32           `json:"totalboxes"`
	Boxweight               sql.NullFloat64 `json:"boxweight"`
	CreatedAt               time.Time       `json:"created_at"`
	ProductID               int32           `json:"product_id"`
	ProductName             string          `json:"product_name"`
	Companyname             string          `json:"companyname"`
	Sampledboxes            sql.NullInt32   `json:"sampledboxes"`
	Productnetweight        sql.NullFloat64 `json:"productnetweight"`
	Totalproductnetweight   sql.NullFloat64 `json:"totalproductnetweight"`
	Totalproductgrossweight sql.NullFloat64 `json:"totalproductgrossweight"`
	ConsignmentNo           sql.NullString  `json:"consignment_no"`
	Expname                 string          `json:"expname"`
	OrderID                 int64           `json:"order_id"`
	PackinglistID           int64           `json:"packinglist_id"`
}

func (q *Queries) GetQcp4ProductsByID(ctx context.Context, qcp4ID int32) ([]GetQcp4ProductsByIDRow, error) {
	rows, err := q.db.QueryContext(ctx, getQcp4ProductsByID, qcp4ID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []GetQcp4ProductsByIDRow{}
	for rows.Next() {
		var i GetQcp4ProductsByIDRow
		if err := rows.Scan(
			&i.ID,
			&i.Status,
			&i.Qcp4ID,
			&i.TraceabilityCode,
			&i.Totalboxes,
			&i.Boxweight,
			&i.CreatedAt,
			&i.ProductID,
			&i.ProductName,
			&i.Companyname,
			&i.Sampledboxes,
			&i.Productnetweight,
			&i.Totalproductnetweight,
			&i.Totalproductgrossweight,
			&i.ConsignmentNo,
			&i.Expname,
			&i.OrderID,
			&i.PackinglistID,
		); 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 getQcp4ProductsByPackinglistID = `-- name: GetQcp4ProductsByPackinglistID :many
SELECT qcp4_products.id,qcp4_products.status,
qcp4_products.qcp4_id,qcp4_products.traceability_code,
qcp4_products.totalboxes,qcp4_products.productnetweight,qcp4_products.boxweight,
qcp4_products.product_id,qcp4_products.totalproductgrossweight,
qcp4_products.totalproductnetweight,qcp4_products.sampledboxes FROM qcp4_products
JOIN  qcp4 on qcp4.id   = qcp4_products.qcp4_id
WHERE qcp4.packinglist_id = $1
`

type GetQcp4ProductsByPackinglistIDRow struct {
	ID                      int64           `json:"id"`
	Status                  string          `json:"status"`
	Qcp4ID                  int32           `json:"qcp4_id"`
	TraceabilityCode        string          `json:"traceability_code"`
	Totalboxes              int32           `json:"totalboxes"`
	Productnetweight        sql.NullFloat64 `json:"productnetweight"`
	Boxweight               sql.NullFloat64 `json:"boxweight"`
	ProductID               int32           `json:"product_id"`
	Totalproductgrossweight sql.NullFloat64 `json:"totalproductgrossweight"`
	Totalproductnetweight   sql.NullFloat64 `json:"totalproductnetweight"`
	Sampledboxes            sql.NullInt32   `json:"sampledboxes"`
}

func (q *Queries) GetQcp4ProductsByPackinglistID(ctx context.Context, packinglistID int32) ([]GetQcp4ProductsByPackinglistIDRow, error) {
	rows, err := q.db.QueryContext(ctx, getQcp4ProductsByPackinglistID, packinglistID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []GetQcp4ProductsByPackinglistIDRow{}
	for rows.Next() {
		var i GetQcp4ProductsByPackinglistIDRow
		if err := rows.Scan(
			&i.ID,
			&i.Status,
			&i.Qcp4ID,
			&i.TraceabilityCode,
			&i.Totalboxes,
			&i.Productnetweight,
			&i.Boxweight,
			&i.ProductID,
			&i.Totalproductgrossweight,
			&i.Totalproductnetweight,
			&i.Sampledboxes,
		); 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 getQcp4Recommendations = `-- name: GetQcp4Recommendations :many
SELECT id, qcp4_id, status, qcp4_product_id, reason, weight_rejected, weight_passed, user_id, exportcompany_id, created_at FROM qcp4_recommendations
WHERE qcp4_id = $1
`

func (q *Queries) GetQcp4Recommendations(ctx context.Context, qcp4ID int32) ([]Qcp4Recommendation, error) {
	rows, err := q.db.QueryContext(ctx, getQcp4Recommendations, qcp4ID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp4Recommendation{}
	for rows.Next() {
		var i Qcp4Recommendation
		if err := rows.Scan(
			&i.ID,
			&i.Qcp4ID,
			&i.Status,
			&i.Qcp4ProductID,
			&i.Reason,
			&i.WeightRejected,
			&i.WeightPassed,
			&i.UserID,
			&i.ExportcompanyID,
			&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 getQcp4SingleRecommendations = `-- name: GetQcp4SingleRecommendations :one
SELECT id, qcp4_id, status, qcp4_product_id, reason, weight_rejected, weight_passed, user_id, exportcompany_id, created_at FROM qcp4_recommendations
WHERE qcp4_id = $1
AND   qcp4_product_id = $2
`

type GetQcp4SingleRecommendationsParams struct {
	Qcp4ID        int32 `json:"qcp4_id"`
	Qcp4ProductID int32 `json:"qcp4_product_id"`
}

func (q *Queries) GetQcp4SingleRecommendations(ctx context.Context, arg GetQcp4SingleRecommendationsParams) (Qcp4Recommendation, error) {
	row := q.db.QueryRowContext(ctx, getQcp4SingleRecommendations, arg.Qcp4ID, arg.Qcp4ProductID)
	var i Qcp4Recommendation
	err := row.Scan(
		&i.ID,
		&i.Qcp4ID,
		&i.Status,
		&i.Qcp4ProductID,
		&i.Reason,
		&i.WeightRejected,
		&i.WeightPassed,
		&i.UserID,
		&i.ExportcompanyID,
		&i.CreatedAt,
	)
	return i, err
}

const globalQcp4ProductsReport = `-- name: GlobalQcp4ProductsReport :many
SELECT qcp4_products.qcp4_id,qcp4_products.traceability_code,
qcp4_products.product_id,qcp4_products.totalboxes,qcp4_products.boxweight,qcp4_products.productnetweight,
qcp4_products.totalproductnetweight,qcp4_products.totalproductgrossweight,crops.cropname,qcp4_products.sampledboxes,
qcp4_products.status,
qcp4.packinglist_id,qcp4.id as qcp4_id,
qcp4.status,qcp4.user_id,qcp4.exportcompany_id,receptionform.traceability_code,orders.id as order_id,
exportcompanies.expname,qcp4.user_id,users.fullname,clients.companyname,countries.countryname,
qcp4_recommendations.status,qcp4_recommendations.weight_passed,qcp4_recommendations.weight_rejected,
farmers.fmname,farmers.fmcode,qcp4.status,qcp4.created_at,orders.consignment_no FROM qcp4_products
LEFT JOIN  qcp4 on qcp4.id = qcp4_products.qcp4_id
LEFT JOIN  qcp4_recommendations on qcp4_recommendations.qcp4_product_id = qcp4_products.id
LEFT JOIN  packinglist  on packinglist.id    = qcp4.packinglist_id
LEFT JOIN  orders       on orders.id              = packinglist.order_id
LEFT JOIN  clients      on clients.id              = orders.client_id
LEFT JOIN  countries     on countries.id           = clients.country_id
LEFT JOIN  receptionform on receptionform.order_id = orders.id
LEFT JOIN  farmers on farmers.id = receptionform.supplier_id
LEFT JOIN  crops on crops.id = qcp4_products.product_id
LEFT JOIN  exportcompanies on exportcompanies.id = qcp4.exportcompany_id
LEFT JOIN  users on  users.id = qcp4.user_id
LIMIT $1 OFFSET $2
`

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

type GlobalQcp4ProductsReportRow struct {
	Qcp4ID                  int32           `json:"qcp4_id"`
	TraceabilityCode        string          `json:"traceability_code"`
	ProductID               int32           `json:"product_id"`
	Totalboxes              int32           `json:"totalboxes"`
	Boxweight               sql.NullFloat64 `json:"boxweight"`
	Productnetweight        sql.NullFloat64 `json:"productnetweight"`
	Totalproductnetweight   sql.NullFloat64 `json:"totalproductnetweight"`
	Totalproductgrossweight sql.NullFloat64 `json:"totalproductgrossweight"`
	Cropname                sql.NullString  `json:"cropname"`
	Sampledboxes            sql.NullInt32   `json:"sampledboxes"`
	Status                  string          `json:"status"`
	PackinglistID           sql.NullInt32   `json:"packinglist_id"`
	Qcp4ID_2                sql.NullInt64   `json:"qcp4_id_2"`
	Status_2                sql.NullString  `json:"status_2"`
	UserID                  sql.NullInt32   `json:"user_id"`
	ExportcompanyID         sql.NullInt32   `json:"exportcompany_id"`
	TraceabilityCode_2      sql.NullString  `json:"traceability_code_2"`
	OrderID                 sql.NullInt64   `json:"order_id"`
	Expname                 sql.NullString  `json:"expname"`
	UserID_2                sql.NullInt32   `json:"user_id_2"`
	Fullname                sql.NullString  `json:"fullname"`
	Companyname             sql.NullString  `json:"companyname"`
	Countryname             sql.NullString  `json:"countryname"`
	Status_3                sql.NullString  `json:"status_3"`
	WeightPassed            sql.NullFloat64 `json:"weight_passed"`
	WeightRejected          sql.NullFloat64 `json:"weight_rejected"`
	Fmname                  sql.NullString  `json:"fmname"`
	Fmcode                  sql.NullString  `json:"fmcode"`
	Status_4                sql.NullString  `json:"status_4"`
	CreatedAt               sql.NullTime    `json:"created_at"`
	ConsignmentNo           sql.NullString  `json:"consignment_no"`
}

func (q *Queries) GlobalQcp4ProductsReport(ctx context.Context, arg GlobalQcp4ProductsReportParams) ([]GlobalQcp4ProductsReportRow, error) {
	rows, err := q.db.QueryContext(ctx, globalQcp4ProductsReport, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []GlobalQcp4ProductsReportRow{}
	for rows.Next() {
		var i GlobalQcp4ProductsReportRow
		if err := rows.Scan(
			&i.Qcp4ID,
			&i.TraceabilityCode,
			&i.ProductID,
			&i.Totalboxes,
			&i.Boxweight,
			&i.Productnetweight,
			&i.Totalproductnetweight,
			&i.Totalproductgrossweight,
			&i.Cropname,
			&i.Sampledboxes,
			&i.Status,
			&i.PackinglistID,
			&i.Qcp4ID_2,
			&i.Status_2,
			&i.UserID,
			&i.ExportcompanyID,
			&i.TraceabilityCode_2,
			&i.OrderID,
			&i.Expname,
			&i.UserID_2,
			&i.Fullname,
			&i.Companyname,
			&i.Countryname,
			&i.Status_3,
			&i.WeightPassed,
			&i.WeightRejected,
			&i.Fmname,
			&i.Fmcode,
			&i.Status_4,
			&i.CreatedAt,
			&i.ConsignmentNo,
		); 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 globalQcp4ProductsReportFilterDate = `-- name: GlobalQcp4ProductsReportFilterDate :many
SELECT qcp4_products.qcp4_id,qcp4_products.traceability_code,
qcp4_products.product_id,qcp4_products.totalboxes,qcp4_products.boxweight,qcp4_products.productnetweight,
qcp4_products.totalproductnetweight,qcp4_products.totalproductgrossweight,crops.cropname,qcp4_products.sampledboxes,
qcp4_products.status,
qcp4.packinglist_id,qcp4.id as qcp4_id,
qcp4.status,qcp4.user_id,qcp4.exportcompany_id,receptionform.traceability_code,orders.id as order_id,
exportcompanies.expname,qcp4.user_id,users.fullname,clients.companyname,countries.countryname,
qcp4_recommendations.status,qcp4_recommendations.weight_passed,qcp4_recommendations.weight_rejected,
farmers.fmname,farmers.fmcode,qcp4.status,qcp4.created_at,orders.consignment_no FROM qcp4_products
LEFT JOIN  qcp4 on qcp4.id = qcp4_products.qcp4_id
LEFT JOIN  qcp4_recommendations on qcp4_recommendations.qcp4_product_id = qcp4_products.id
LEFT JOIN  packinglist  on packinglist.id    = qcp4.packinglist_id
LEFT JOIN  orders       on orders.id              = packinglist.order_id
LEFT JOIN  clients      on clients.id              = orders.client_id
LEFT JOIN  countries     on countries.id           = clients.country_id
LEFT JOIN  receptionform on receptionform.order_id = orders.id
LEFT JOIN  farmers on farmers.id = receptionform.supplier_id
LEFT JOIN  crops on crops.id = qcp4_products.product_id
LEFT JOIN  exportcompanies on exportcompanies.id = qcp4.exportcompany_id
LEFT JOIN  users on  users.id = qcp4.user_id
WHERE   qcp4.created_at
BETWEEN TO_TIMESTAMP($1, 'YYYY-MM-DD HH24:MI:SS')
AND     TO_TIMESTAMP($2, 'YYYY-MM-DD HH24:MI:SS')
LIMIT $3 OFFSET $4
`

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

type GlobalQcp4ProductsReportFilterDateRow struct {
	Qcp4ID                  int32           `json:"qcp4_id"`
	TraceabilityCode        string          `json:"traceability_code"`
	ProductID               int32           `json:"product_id"`
	Totalboxes              int32           `json:"totalboxes"`
	Boxweight               sql.NullFloat64 `json:"boxweight"`
	Productnetweight        sql.NullFloat64 `json:"productnetweight"`
	Totalproductnetweight   sql.NullFloat64 `json:"totalproductnetweight"`
	Totalproductgrossweight sql.NullFloat64 `json:"totalproductgrossweight"`
	Cropname                sql.NullString  `json:"cropname"`
	Sampledboxes            sql.NullInt32   `json:"sampledboxes"`
	Status                  string          `json:"status"`
	PackinglistID           sql.NullInt32   `json:"packinglist_id"`
	Qcp4ID_2                sql.NullInt64   `json:"qcp4_id_2"`
	Status_2                sql.NullString  `json:"status_2"`
	UserID                  sql.NullInt32   `json:"user_id"`
	ExportcompanyID         sql.NullInt32   `json:"exportcompany_id"`
	TraceabilityCode_2      sql.NullString  `json:"traceability_code_2"`
	OrderID                 sql.NullInt64   `json:"order_id"`
	Expname                 sql.NullString  `json:"expname"`
	UserID_2                sql.NullInt32   `json:"user_id_2"`
	Fullname                sql.NullString  `json:"fullname"`
	Companyname             sql.NullString  `json:"companyname"`
	Countryname             sql.NullString  `json:"countryname"`
	Status_3                sql.NullString  `json:"status_3"`
	WeightPassed            sql.NullFloat64 `json:"weight_passed"`
	WeightRejected          sql.NullFloat64 `json:"weight_rejected"`
	Fmname                  sql.NullString  `json:"fmname"`
	Fmcode                  sql.NullString  `json:"fmcode"`
	Status_4                sql.NullString  `json:"status_4"`
	CreatedAt               sql.NullTime    `json:"created_at"`
	ConsignmentNo           sql.NullString  `json:"consignment_no"`
}

func (q *Queries) GlobalQcp4ProductsReportFilterDate(ctx context.Context, arg GlobalQcp4ProductsReportFilterDateParams) ([]GlobalQcp4ProductsReportFilterDateRow, error) {
	rows, err := q.db.QueryContext(ctx, globalQcp4ProductsReportFilterDate,
		arg.ToTimestamp,
		arg.ToTimestamp_2,
		arg.Limit,
		arg.Offset,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []GlobalQcp4ProductsReportFilterDateRow{}
	for rows.Next() {
		var i GlobalQcp4ProductsReportFilterDateRow
		if err := rows.Scan(
			&i.Qcp4ID,
			&i.TraceabilityCode,
			&i.ProductID,
			&i.Totalboxes,
			&i.Boxweight,
			&i.Productnetweight,
			&i.Totalproductnetweight,
			&i.Totalproductgrossweight,
			&i.Cropname,
			&i.Sampledboxes,
			&i.Status,
			&i.PackinglistID,
			&i.Qcp4ID_2,
			&i.Status_2,
			&i.UserID,
			&i.ExportcompanyID,
			&i.TraceabilityCode_2,
			&i.OrderID,
			&i.Expname,
			&i.UserID_2,
			&i.Fullname,
			&i.Companyname,
			&i.Countryname,
			&i.Status_3,
			&i.WeightPassed,
			&i.WeightRejected,
			&i.Fmname,
			&i.Fmcode,
			&i.Status_4,
			&i.CreatedAt,
			&i.ConsignmentNo,
		); 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 globalQcp4ProductsReportFilterDateStatus = `-- name: GlobalQcp4ProductsReportFilterDateStatus :many
SELECT qcp4_products.qcp4_id,qcp4_products.traceability_code,
qcp4_products.product_id,qcp4_products.totalboxes,qcp4_products.boxweight,qcp4_products.productnetweight,
qcp4_products.totalproductnetweight,qcp4_products.totalproductgrossweight,crops.cropname,qcp4_products.sampledboxes,
qcp4_products.status,
qcp4.packinglist_id,qcp4.id as qcp4_id,
qcp4.status,qcp4.user_id,qcp4.exportcompany_id,receptionform.traceability_code,orders.id as order_id,
exportcompanies.expname,qcp4.user_id,users.fullname,clients.companyname,countries.countryname,
qcp4_recommendations.status,qcp4_recommendations.weight_passed,qcp4_recommendations.weight_rejected,
farmers.fmname,farmers.fmcode,qcp4.status,qcp4.created_at,orders.consignment_no FROM qcp4_products
LEFT JOIN  qcp4 on qcp4.id = qcp4_products.qcp4_id
LEFT JOIN  qcp4_recommendations on qcp4_recommendations.qcp4_product_id = qcp4_products.id
LEFT JOIN  packinglist  on packinglist.id    = qcp4.packinglist_id
LEFT JOIN  orders       on orders.id              = packinglist.order_id
LEFT JOIN  clients      on clients.id              = orders.client_id
LEFT JOIN  countries     on countries.id           = clients.country_id
LEFT JOIN  receptionform on receptionform.order_id = orders.id
LEFT JOIN  farmers on farmers.id = receptionform.supplier_id
LEFT JOIN  crops on crops.id = qcp4_products.product_id
LEFT JOIN  exportcompanies on exportcompanies.id = qcp4.exportcompany_id
LEFT JOIN  users on  users.id = qcp4.user_id
WHERE   qcp4.created_at
BETWEEN TO_TIMESTAMP($1, 'YYYY-MM-DD HH24:MI:SS')
AND     TO_TIMESTAMP($2, 'YYYY-MM-DD HH24:MI:SS')
AND     qcp4.status = $3
LIMIT $4 OFFSET $5
`

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

type GlobalQcp4ProductsReportFilterDateStatusRow struct {
	Qcp4ID                  int32           `json:"qcp4_id"`
	TraceabilityCode        string          `json:"traceability_code"`
	ProductID               int32           `json:"product_id"`
	Totalboxes              int32           `json:"totalboxes"`
	Boxweight               sql.NullFloat64 `json:"boxweight"`
	Productnetweight        sql.NullFloat64 `json:"productnetweight"`
	Totalproductnetweight   sql.NullFloat64 `json:"totalproductnetweight"`
	Totalproductgrossweight sql.NullFloat64 `json:"totalproductgrossweight"`
	Cropname                sql.NullString  `json:"cropname"`
	Sampledboxes            sql.NullInt32   `json:"sampledboxes"`
	Status                  string          `json:"status"`
	PackinglistID           sql.NullInt32   `json:"packinglist_id"`
	Qcp4ID_2                sql.NullInt64   `json:"qcp4_id_2"`
	Status_2                sql.NullString  `json:"status_2"`
	UserID                  sql.NullInt32   `json:"user_id"`
	ExportcompanyID         sql.NullInt32   `json:"exportcompany_id"`
	TraceabilityCode_2      sql.NullString  `json:"traceability_code_2"`
	OrderID                 sql.NullInt64   `json:"order_id"`
	Expname                 sql.NullString  `json:"expname"`
	UserID_2                sql.NullInt32   `json:"user_id_2"`
	Fullname                sql.NullString  `json:"fullname"`
	Companyname             sql.NullString  `json:"companyname"`
	Countryname             sql.NullString  `json:"countryname"`
	Status_3                sql.NullString  `json:"status_3"`
	WeightPassed            sql.NullFloat64 `json:"weight_passed"`
	WeightRejected          sql.NullFloat64 `json:"weight_rejected"`
	Fmname                  sql.NullString  `json:"fmname"`
	Fmcode                  sql.NullString  `json:"fmcode"`
	Status_4                sql.NullString  `json:"status_4"`
	CreatedAt               sql.NullTime    `json:"created_at"`
	ConsignmentNo           sql.NullString  `json:"consignment_no"`
}

func (q *Queries) GlobalQcp4ProductsReportFilterDateStatus(ctx context.Context, arg GlobalQcp4ProductsReportFilterDateStatusParams) ([]GlobalQcp4ProductsReportFilterDateStatusRow, error) {
	rows, err := q.db.QueryContext(ctx, globalQcp4ProductsReportFilterDateStatus,
		arg.ToTimestamp,
		arg.ToTimestamp_2,
		arg.Status,
		arg.Limit,
		arg.Offset,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []GlobalQcp4ProductsReportFilterDateStatusRow{}
	for rows.Next() {
		var i GlobalQcp4ProductsReportFilterDateStatusRow
		if err := rows.Scan(
			&i.Qcp4ID,
			&i.TraceabilityCode,
			&i.ProductID,
			&i.Totalboxes,
			&i.Boxweight,
			&i.Productnetweight,
			&i.Totalproductnetweight,
			&i.Totalproductgrossweight,
			&i.Cropname,
			&i.Sampledboxes,
			&i.Status,
			&i.PackinglistID,
			&i.Qcp4ID_2,
			&i.Status_2,
			&i.UserID,
			&i.ExportcompanyID,
			&i.TraceabilityCode_2,
			&i.OrderID,
			&i.Expname,
			&i.UserID_2,
			&i.Fullname,
			&i.Companyname,
			&i.Countryname,
			&i.Status_3,
			&i.WeightPassed,
			&i.WeightRejected,
			&i.Fmname,
			&i.Fmcode,
			&i.Status_4,
			&i.CreatedAt,
			&i.ConsignmentNo,
		); 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 globalQcp4ProductsReportFilterStatus = `-- name: GlobalQcp4ProductsReportFilterStatus :many
SELECT qcp4_products.qcp4_id,qcp4_products.traceability_code,
qcp4_products.product_id,qcp4_products.totalboxes,qcp4_products.boxweight,qcp4_products.productnetweight,
qcp4_products.totalproductnetweight,qcp4_products.totalproductgrossweight,crops.cropname,qcp4_products.sampledboxes,
qcp4_products.status,
qcp4.packinglist_id,qcp4.id as qcp4_id,
qcp4.status,qcp4.user_id,qcp4.exportcompany_id,receptionform.traceability_code,orders.id as order_id,
exportcompanies.expname,qcp4.user_id,users.fullname,clients.companyname,countries.countryname,
qcp4_recommendations.status,qcp4_recommendations.weight_passed,qcp4_recommendations.weight_rejected,
farmers.fmname,farmers.fmcode,qcp4.status,qcp4.created_at,orders.consignment_no FROM qcp4_products
LEFT JOIN  qcp4 on qcp4.id = qcp4_products.qcp4_id
LEFT JOIN  qcp4_recommendations on qcp4_recommendations.qcp4_product_id = qcp4_products.id
LEFT JOIN  packinglist  on packinglist.id    = qcp4.packinglist_id
LEFT JOIN  orders       on orders.id              = packinglist.order_id
LEFT JOIN  clients      on clients.id              = orders.client_id
LEFT JOIN  countries     on countries.id           = clients.country_id
LEFT JOIN  receptionform on receptionform.order_id = orders.id
LEFT JOIN  farmers on farmers.id = receptionform.supplier_id
LEFT JOIN  crops on crops.id = qcp4_products.product_id
LEFT JOIN  exportcompanies on exportcompanies.id = qcp4.exportcompany_id
LEFT JOIN  users on  users.id = qcp4.user_id
WHERE qcp4_products.status = $1
LIMIT $2 OFFSET $3
`

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

type GlobalQcp4ProductsReportFilterStatusRow struct {
	Qcp4ID                  int32           `json:"qcp4_id"`
	TraceabilityCode        string          `json:"traceability_code"`
	ProductID               int32           `json:"product_id"`
	Totalboxes              int32           `json:"totalboxes"`
	Boxweight               sql.NullFloat64 `json:"boxweight"`
	Productnetweight        sql.NullFloat64 `json:"productnetweight"`
	Totalproductnetweight   sql.NullFloat64 `json:"totalproductnetweight"`
	Totalproductgrossweight sql.NullFloat64 `json:"totalproductgrossweight"`
	Cropname                sql.NullString  `json:"cropname"`
	Sampledboxes            sql.NullInt32   `json:"sampledboxes"`
	Status                  string          `json:"status"`
	PackinglistID           sql.NullInt32   `json:"packinglist_id"`
	Qcp4ID_2                sql.NullInt64   `json:"qcp4_id_2"`
	Status_2                sql.NullString  `json:"status_2"`
	UserID                  sql.NullInt32   `json:"user_id"`
	ExportcompanyID         sql.NullInt32   `json:"exportcompany_id"`
	TraceabilityCode_2      sql.NullString  `json:"traceability_code_2"`
	OrderID                 sql.NullInt64   `json:"order_id"`
	Expname                 sql.NullString  `json:"expname"`
	UserID_2                sql.NullInt32   `json:"user_id_2"`
	Fullname                sql.NullString  `json:"fullname"`
	Companyname             sql.NullString  `json:"companyname"`
	Countryname             sql.NullString  `json:"countryname"`
	Status_3                sql.NullString  `json:"status_3"`
	WeightPassed            sql.NullFloat64 `json:"weight_passed"`
	WeightRejected          sql.NullFloat64 `json:"weight_rejected"`
	Fmname                  sql.NullString  `json:"fmname"`
	Fmcode                  sql.NullString  `json:"fmcode"`
	Status_4                sql.NullString  `json:"status_4"`
	CreatedAt               sql.NullTime    `json:"created_at"`
	ConsignmentNo           sql.NullString  `json:"consignment_no"`
}

func (q *Queries) GlobalQcp4ProductsReportFilterStatus(ctx context.Context, arg GlobalQcp4ProductsReportFilterStatusParams) ([]GlobalQcp4ProductsReportFilterStatusRow, error) {
	rows, err := q.db.QueryContext(ctx, globalQcp4ProductsReportFilterStatus, arg.Status, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []GlobalQcp4ProductsReportFilterStatusRow{}
	for rows.Next() {
		var i GlobalQcp4ProductsReportFilterStatusRow
		if err := rows.Scan(
			&i.Qcp4ID,
			&i.TraceabilityCode,
			&i.ProductID,
			&i.Totalboxes,
			&i.Boxweight,
			&i.Productnetweight,
			&i.Totalproductnetweight,
			&i.Totalproductgrossweight,
			&i.Cropname,
			&i.Sampledboxes,
			&i.Status,
			&i.PackinglistID,
			&i.Qcp4ID_2,
			&i.Status_2,
			&i.UserID,
			&i.ExportcompanyID,
			&i.TraceabilityCode_2,
			&i.OrderID,
			&i.Expname,
			&i.UserID_2,
			&i.Fullname,
			&i.Companyname,
			&i.Countryname,
			&i.Status_3,
			&i.WeightPassed,
			&i.WeightRejected,
			&i.Fmname,
			&i.Fmcode,
			&i.Status_4,
			&i.CreatedAt,
			&i.ConsignmentNo,
		); 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 listAllCompaniesQcp4Ds = `-- name: ListAllCompaniesQcp4Ds :many
SELECT qcp4.packinglist_id,qcp4.id as qcp4_id,
qcp4.status,qcp4.user_id,qcp4.exportcompany_id,
exportcompanies.expname,qcp4.user_id,users.fullname,
qcp4.status,qcp4.created_at FROM qcp4
JOIN  exportcompanies on exportcompanies.id = qcp4.exportcompany_id
JOIN  users on  users.id = qcp4.user_id
WHERE qcp4.status = $1
`

type ListAllCompaniesQcp4DsRow struct {
	PackinglistID   int32     `json:"packinglist_id"`
	Qcp4ID          int64     `json:"qcp4_id"`
	Status          string    `json:"status"`
	UserID          int32     `json:"user_id"`
	ExportcompanyID int32     `json:"exportcompany_id"`
	Expname         string    `json:"expname"`
	UserID_2        int32     `json:"user_id_2"`
	Fullname        string    `json:"fullname"`
	Status_2        string    `json:"status_2"`
	CreatedAt       time.Time `json:"created_at"`
}

func (q *Queries) ListAllCompaniesQcp4Ds(ctx context.Context, status string) ([]ListAllCompaniesQcp4DsRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesQcp4Ds, status)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesQcp4DsRow{}
	for rows.Next() {
		var i ListAllCompaniesQcp4DsRow
		if err := rows.Scan(
			&i.PackinglistID,
			&i.Qcp4ID,
			&i.Status,
			&i.UserID,
			&i.ExportcompanyID,
			&i.Expname,
			&i.UserID_2,
			&i.Fullname,
			&i.Status_2,
			&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 listAllCompaniesQcp4WFs = `-- name: ListAllCompaniesQcp4WFs :many
SELECT qcp4.packinglist_id,qcp4.id as qcp4_id,
qcp4.status,qcp4.user_id,qcp4.exportcompany_id,
exportcompanies.expname,qcp4.user_id,users.fullname,
qcp4.status,qcp4.created_at FROM qcp4
JOIN  exportcompanies on exportcompanies.id = qcp4.exportcompany_id
JOIN  users on  users.id = qcp4.user_id
WHERE qcp4.status = $1 LIMIT $2 OFFSET $3
`

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

type ListAllCompaniesQcp4WFsRow struct {
	PackinglistID   int32     `json:"packinglist_id"`
	Qcp4ID          int64     `json:"qcp4_id"`
	Status          string    `json:"status"`
	UserID          int32     `json:"user_id"`
	ExportcompanyID int32     `json:"exportcompany_id"`
	Expname         string    `json:"expname"`
	UserID_2        int32     `json:"user_id_2"`
	Fullname        string    `json:"fullname"`
	Status_2        string    `json:"status_2"`
	CreatedAt       time.Time `json:"created_at"`
}

func (q *Queries) ListAllCompaniesQcp4WFs(ctx context.Context, arg ListAllCompaniesQcp4WFsParams) ([]ListAllCompaniesQcp4WFsRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesQcp4WFs, arg.Status, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesQcp4WFsRow{}
	for rows.Next() {
		var i ListAllCompaniesQcp4WFsRow
		if err := rows.Scan(
			&i.PackinglistID,
			&i.Qcp4ID,
			&i.Status,
			&i.UserID,
			&i.ExportcompanyID,
			&i.Expname,
			&i.UserID_2,
			&i.Fullname,
			&i.Status_2,
			&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 listAllCompaniesQcp4s = `-- name: ListAllCompaniesQcp4s :many
SELECT qcp4.packinglist_id,qcp4.id as qcp4_id,
qcp4.status,qcp4.user_id,qcp4.exportcompany_id,
exportcompanies.expname,qcp4.user_id,users.fullname,
qcp4.status,qcp4.created_at FROM qcp4
JOIN  exportcompanies on exportcompanies.id = qcp4.exportcompany_id
JOIN  users on  users.id = qcp4.user_id
WHERE qcp4.status = $1 AND qcp4.created_at
BETWEEN TO_TIMESTAMP($2, 'YYYY-MM-DD HH24:MI:SS')
AND     TO_TIMESTAMP($3, 'YYYY-MM-DD HH24:MI:SS')
LIMIT   $4 OFFSET $5
`

type ListAllCompaniesQcp4sParams 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 ListAllCompaniesQcp4sRow struct {
	PackinglistID   int32     `json:"packinglist_id"`
	Qcp4ID          int64     `json:"qcp4_id"`
	Status          string    `json:"status"`
	UserID          int32     `json:"user_id"`
	ExportcompanyID int32     `json:"exportcompany_id"`
	Expname         string    `json:"expname"`
	UserID_2        int32     `json:"user_id_2"`
	Fullname        string    `json:"fullname"`
	Status_2        string    `json:"status_2"`
	CreatedAt       time.Time `json:"created_at"`
}

func (q *Queries) ListAllCompaniesQcp4s(ctx context.Context, arg ListAllCompaniesQcp4sParams) ([]ListAllCompaniesQcp4sRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesQcp4s,
		arg.Status,
		arg.ToTimestamp,
		arg.ToTimestamp_2,
		arg.Limit,
		arg.Offset,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesQcp4sRow{}
	for rows.Next() {
		var i ListAllCompaniesQcp4sRow
		if err := rows.Scan(
			&i.PackinglistID,
			&i.Qcp4ID,
			&i.Status,
			&i.UserID,
			&i.ExportcompanyID,
			&i.Expname,
			&i.UserID_2,
			&i.Fullname,
			&i.Status_2,
			&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 listPendingQcp4s = `-- name: ListPendingQcp4s :many
SELECT crops.cropname,receptionform.order_id,
qcp4.user_id,users.fullname,qcp4.created_at,qcp4.status,
orders.consignment_no,qcp4.id qcp4_id,receptionform.traceability_code from qcp4
LEFT JOIN receptionform on receptionform.id = qcp3.reception_id
LEFT JOIN orders  on orders.id  = receptionform.order_id
LEFT JOIN crops   on crops.id   = receptionform.crop_id
LEFT JOIN users   on users.id   = qcp4.user_id
WHERE qcp4.exportcompany_id     = $3  AND qcp4.status = $4
LIMIT $1 OFFSET $2
`

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

type ListPendingQcp4sRow struct {
	Cropname         sql.NullString `json:"cropname"`
	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"`
	ConsignmentNo    sql.NullString `json:"consignment_no"`
	Qcp4ID           int64          `json:"qcp4_id"`
	TraceabilityCode sql.NullString `json:"traceability_code"`
}

func (q *Queries) ListPendingQcp4s(ctx context.Context, arg ListPendingQcp4sParams) ([]ListPendingQcp4sRow, error) {
	rows, err := q.db.QueryContext(ctx, listPendingQcp4s,
		arg.Limit,
		arg.Offset,
		arg.ExportcompanyID,
		arg.Status,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListPendingQcp4sRow{}
	for rows.Next() {
		var i ListPendingQcp4sRow
		if err := rows.Scan(
			&i.Cropname,
			&i.OrderID,
			&i.UserID,
			&i.Fullname,
			&i.CreatedAt,
			&i.Status,
			&i.ConsignmentNo,
			&i.Qcp4ID,
			&i.TraceabilityCode,
		); 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 listQcp4s = `-- name: ListQcp4s :many
SELECT id, packinglist_id, user_id, status, exportcompany_id, created_at FROM qcp4
ORDER BY id LIMIT $1
OFFSET $2
`

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

func (q *Queries) ListQcp4s(ctx context.Context, arg ListQcp4sParams) ([]Qcp4, error) {
	rows, err := q.db.QueryContext(ctx, listQcp4s, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp4{}
	for rows.Next() {
		var i Qcp4
		if err := rows.Scan(
			&i.ID,
			&i.PackinglistID,
			&i.UserID,
			&i.Status,
			&i.ExportcompanyID,
			&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 qcp4AttributesContent = `-- name: Qcp4AttributesContent :many
Select qcp4_attributes.qcp4_id ,qualityattributes.description from qcp4_attributes
JOIN   qualityattributes on qualityattributes.id = qcp4_attributes.qualityattributes_id
WHERE  qcp4_id = $1
AND    qcp4_attributes.qcp4_product_id = $2
`

type Qcp4AttributesContentParams struct {
	Qcp4ID        int32 `json:"qcp4_id"`
	Qcp4ProductID int32 `json:"qcp4_product_id"`
}

type Qcp4AttributesContentRow struct {
	Qcp4ID      int32  `json:"qcp4_id"`
	Description string `json:"description"`
}

func (q *Queries) Qcp4AttributesContent(ctx context.Context, arg Qcp4AttributesContentParams) ([]Qcp4AttributesContentRow, error) {
	rows, err := q.db.QueryContext(ctx, qcp4AttributesContent, arg.Qcp4ID, arg.Qcp4ProductID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp4AttributesContentRow{}
	for rows.Next() {
		var i Qcp4AttributesContentRow
		if err := rows.Scan(&i.Qcp4ID, &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 qcp4ContentPerOrder = `-- name: Qcp4ContentPerOrder :many
Select clients.companyname,countries.countryname,exportcompanies.expname,exportcompanies.expregno,
packhouses.phname, orders.consignment_no,orders.status,orders.created_at,
orders.id,orders.consignment_no as consignment__no from qcp4
JOIN  packinglist        on packinglist.id       = qcp4.packinglist_id
JOIN  orders             on orders.id            = packinglist.order_id
JOIN  exportcompanies    on exportcompanies.id   = orders.exportcompany_id
JOIN  clients            on clients.id           = orders.client_id
JOIN  countries          on countries.id         = clients.country_id
JOIN  packhouse_exporter on packhouse_exporter.exportcompany_id = exportcompanies.id
JOIN  packhouses         on packhouse_exporter.packhouse_id     = packhouses.id
WHERE qcp4.id = $1
`

type Qcp4ContentPerOrderRow struct {
	Companyname     string         `json:"companyname"`
	Countryname     string         `json:"countryname"`
	Expname         string         `json:"expname"`
	Expregno        string         `json:"expregno"`
	Phname          string         `json:"phname"`
	ConsignmentNo   sql.NullString `json:"consignment_no"`
	Status          string         `json:"status"`
	CreatedAt       time.Time      `json:"created_at"`
	ID              int64          `json:"id"`
	ConsignmentNo_2 sql.NullString `json:"consignment__no_2"`
}

func (q *Queries) Qcp4ContentPerOrder(ctx context.Context, id int64) ([]Qcp4ContentPerOrderRow, error) {
	rows, err := q.db.QueryContext(ctx, qcp4ContentPerOrder, id)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp4ContentPerOrderRow{}
	for rows.Next() {
		var i Qcp4ContentPerOrderRow
		if err := rows.Scan(
			&i.Companyname,
			&i.Countryname,
			&i.Expname,
			&i.Expregno,
			&i.Phname,
			&i.ConsignmentNo,
			&i.Status,
			&i.CreatedAt,
			&i.ID,
			&i.ConsignmentNo_2,
		); 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 qcp4IDByPackingListID = `-- name: Qcp4IDByPackingListID :one
SELECT qcp4.id as qcp4_id, packinglist.id as packinglist_id FROM qcp4
INNER JOIN packinglist on packinglist.id = qcp4.packinglist_id
WHERE packinglist.id = $1
`

type Qcp4IDByPackingListIDRow struct {
	Qcp4ID        int64 `json:"qcp4_id"`
	PackinglistID int64 `json:"packinglist_id"`
}

func (q *Queries) Qcp4IDByPackingListID(ctx context.Context, id int64) (Qcp4IDByPackingListIDRow, error) {
	row := q.db.QueryRowContext(ctx, qcp4IDByPackingListID, id)
	var i Qcp4IDByPackingListIDRow
	err := row.Scan(&i.Qcp4ID, &i.PackinglistID)
	return i, err
}

const qcp4InspectorOtherUpdates = `-- name: Qcp4InspectorOtherUpdates :one
UPDATE qcp4_others
  set
    user_id = $2
WHERE id = $1
RETURNING id, qcp4_id, packinglist_id, product_name, noofboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, sampledboxes, status, user_id, exportcompany_id, created_at
`

type Qcp4InspectorOtherUpdatesParams struct {
	ID     int64 `json:"id"`
	UserID int32 `json:"user_id"`
}

func (q *Queries) Qcp4InspectorOtherUpdates(ctx context.Context, arg Qcp4InspectorOtherUpdatesParams) (Qcp4Other, error) {
	row := q.db.QueryRowContext(ctx, qcp4InspectorOtherUpdates, arg.ID, arg.UserID)
	var i Qcp4Other
	err := row.Scan(
		&i.ID,
		&i.Qcp4ID,
		&i.PackinglistID,
		&i.ProductName,
		&i.Noofboxes,
		&i.Boxweight,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.Sampledboxes,
		&i.Status,
		&i.UserID,
		&i.ExportcompanyID,
		&i.CreatedAt,
	)
	return i, err
}

const qcp4InspectorUpdates = `-- name: Qcp4InspectorUpdates :one
UPDATE qcp4
  set
    user_id = $2
WHERE id = $1
RETURNING id, packinglist_id, user_id, status, exportcompany_id, created_at
`

type Qcp4InspectorUpdatesParams struct {
	ID     int64 `json:"id"`
	UserID int32 `json:"user_id"`
}

func (q *Queries) Qcp4InspectorUpdates(ctx context.Context, arg Qcp4InspectorUpdatesParams) (Qcp4, error) {
	row := q.db.QueryRowContext(ctx, qcp4InspectorUpdates, arg.ID, arg.UserID)
	var i Qcp4
	err := row.Scan(
		&i.ID,
		&i.PackinglistID,
		&i.UserID,
		&i.Status,
		&i.ExportcompanyID,
		&i.CreatedAt,
	)
	return i, err
}

const qcp4OtherAttributesContent = `-- name: Qcp4OtherAttributesContent :many
Select qualityattributes.description, qcp4_others.product_name from qcp4_other_attributes
JOIN   qualityattributes  on qualityattributes.id = qcp4_other_attributes.qualityattributes_id
JOIN   qcp4_others        on qcp4_others.id       = qcp4_other_attributes.qcp4_other_id
JOIN   users              on users.id             = qcp4_other_attributes.user_id
WHERE  qcp4_other_attributes.qcp4_id = $1
AND    qcp4_others.product_name = $2
`

type Qcp4OtherAttributesContentParams struct {
	Qcp4ID      int32  `json:"qcp4_id"`
	ProductName string `json:"product_name"`
}

type Qcp4OtherAttributesContentRow struct {
	Description string `json:"description"`
	ProductName string `json:"product_name"`
}

func (q *Queries) Qcp4OtherAttributesContent(ctx context.Context, arg Qcp4OtherAttributesContentParams) ([]Qcp4OtherAttributesContentRow, error) {
	rows, err := q.db.QueryContext(ctx, qcp4OtherAttributesContent, arg.Qcp4ID, arg.ProductName)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp4OtherAttributesContentRow{}
	for rows.Next() {
		var i Qcp4OtherAttributesContentRow
		if err := rows.Scan(&i.Description, &i.ProductName); 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 qcp4OtherPerConsignment = `-- name: Qcp4OtherPerConsignment :many
SELECT orders.id qcp4orderid,qcp4_others.product_name other_product_name,qcp4_others.status qcp4_others_status,orders.id as qcp4_order_ids, qcp4_others.boxweight others_boxweight,
qcp4_others.productnetweight others_product_netweight,qcp4_others.totalproductnetweight others_total_productweight,qcp4_others.totalproductgrossweight others_total_productgrossweight,
qcp4.id qcp4ID,qcp4_others.noofboxes other_box_numbers,qcp4_others.sampledboxes other_sampled_boxes,qcp4_others.id row_other_id,
qcp4.packinglist_id from qcp4
LEFT JOIN qcp4_others   on qcp4_others.qcp4_id   = qcp4.id
LEFT JOIN packinglist   on packinglist.id        = qcp4.packinglist_id
LEFT JOIN orders        on orders.id             = packinglist.order_id
LEFT JOIN users         on users.id              = qcp4.user_id
WHERE orders.consignment_no = $1
GROUP BY qcp4_others.id,qcp4.id,orders.id
`

type Qcp4OtherPerConsignmentRow struct {
	Qcp4orderid                   sql.NullInt64   `json:"qcp4orderid"`
	OtherProductName              sql.NullString  `json:"other_product_name"`
	Qcp4OthersStatus              sql.NullString  `json:"qcp4_others_status"`
	Qcp4OrderIds                  sql.NullInt64   `json:"qcp4_order_ids"`
	OthersBoxweight               sql.NullFloat64 `json:"others_boxweight"`
	OthersProductNetweight        sql.NullFloat64 `json:"others_product_netweight"`
	OthersTotalProductweight      sql.NullFloat64 `json:"others_total_productweight"`
	OthersTotalProductgrossweight sql.NullFloat64 `json:"others_total_productgrossweight"`
	Qcp4id                        int64           `json:"qcp4id"`
	OtherBoxNumbers               sql.NullInt32   `json:"other_box_numbers"`
	OtherSampledBoxes             sql.NullInt32   `json:"other_sampled_boxes"`
	RowOtherID                    sql.NullInt64   `json:"row_other_id"`
	PackinglistID                 int32           `json:"packinglist_id"`
}

func (q *Queries) Qcp4OtherPerConsignment(ctx context.Context, consignmentNo sql.NullString) ([]Qcp4OtherPerConsignmentRow, error) {
	rows, err := q.db.QueryContext(ctx, qcp4OtherPerConsignment, consignmentNo)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp4OtherPerConsignmentRow{}
	for rows.Next() {
		var i Qcp4OtherPerConsignmentRow
		if err := rows.Scan(
			&i.Qcp4orderid,
			&i.OtherProductName,
			&i.Qcp4OthersStatus,
			&i.Qcp4OrderIds,
			&i.OthersBoxweight,
			&i.OthersProductNetweight,
			&i.OthersTotalProductweight,
			&i.OthersTotalProductgrossweight,
			&i.Qcp4id,
			&i.OtherBoxNumbers,
			&i.OtherSampledBoxes,
			&i.RowOtherID,
			&i.PackinglistID,
		); 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 qcp4OthersContentPerOrder = `-- name: Qcp4OthersContentPerOrder :many
select qcp4_others.qcp4_id,qcp4_others.noofboxes,qcp4_others.product_name,
qcp4_others.boxweight,qcp4_others.productnetweight,qcp4_others.totalproductnetweight,
qcp4_others.totalproductgrossweight,qcp4_others.status,qcp4_others.sampledboxes,
qcp4_others.created_at from qcp4_others
WHERE qcp4_others.qcp4_id = $1
`

type Qcp4OthersContentPerOrderRow struct {
	Qcp4ID                  int32           `json:"qcp4_id"`
	Noofboxes               int32           `json:"noofboxes"`
	ProductName             string          `json:"product_name"`
	Boxweight               sql.NullFloat64 `json:"boxweight"`
	Productnetweight        sql.NullFloat64 `json:"productnetweight"`
	Totalproductnetweight   sql.NullFloat64 `json:"totalproductnetweight"`
	Totalproductgrossweight sql.NullFloat64 `json:"totalproductgrossweight"`
	Status                  string          `json:"status"`
	Sampledboxes            sql.NullInt32   `json:"sampledboxes"`
	CreatedAt               time.Time       `json:"created_at"`
}

func (q *Queries) Qcp4OthersContentPerOrder(ctx context.Context, qcp4ID int32) ([]Qcp4OthersContentPerOrderRow, error) {
	rows, err := q.db.QueryContext(ctx, qcp4OthersContentPerOrder, qcp4ID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp4OthersContentPerOrderRow{}
	for rows.Next() {
		var i Qcp4OthersContentPerOrderRow
		if err := rows.Scan(
			&i.Qcp4ID,
			&i.Noofboxes,
			&i.ProductName,
			&i.Boxweight,
			&i.Productnetweight,
			&i.Totalproductnetweight,
			&i.Totalproductgrossweight,
			&i.Status,
			&i.Sampledboxes,
			&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 qcp4OthersCount = `-- name: Qcp4OthersCount :one
SELECT COUNT(id) AS id_count
FROM   qcp4_others
WHERE  qcp4_id = $1
`

func (q *Queries) Qcp4OthersCount(ctx context.Context, qcp4ID int32) (int64, error) {
	row := q.db.QueryRowContext(ctx, qcp4OthersCount, qcp4ID)
	var id_count int64
	err := row.Scan(&id_count)
	return id_count, err
}

const qcp4PerConsignment = `-- name: Qcp4PerConsignment :many
SELECT orders.id qcp4orderid,orders.id as qcp4_order_ids,qcp4.id qcp4ID,qcp4_products.traceability_code traceability_code,
qcp4_products.id row_id,qcp4_products.product_id product_id,qcp4_products.totalboxes total_boxes,crops.cropname qcp4_product_name,
qcp4_products.status qcp4_product_status,qcp4_products.boxweight qcp4_box_weight,
qcp4_products.productnetweight qcp4_productnet_weight,qcp4_products.totalproductnetweight total_product_netweight,
qcp4_products.totalproductgrossweight total_product_grossweight,qcp4_products.sampledboxes sampled_boxes, qcp4.packinglist_id from qcp4
LEFT JOIN qcp4_products on qcp4_products.qcp4_id = qcp4.id
LEFT JOIN packinglist   on packinglist.id        = qcp4.packinglist_id
LEFT JOIN orders        on orders.id             = packinglist.order_id
LEFT JOIN crops         on crops.id              = qcp4_products.product_id
LEFT JOIN users         on users.id              = qcp4.user_id
WHERE orders.consignment_no = $1
GROUP BY qcp4.id,qcp4_products.id,crops.cropname,orders.id
`

type Qcp4PerConsignmentRow struct {
	Qcp4orderid             sql.NullInt64   `json:"qcp4orderid"`
	Qcp4OrderIds            sql.NullInt64   `json:"qcp4_order_ids"`
	Qcp4id                  int64           `json:"qcp4id"`
	TraceabilityCode        sql.NullString  `json:"traceability_code"`
	RowID                   sql.NullInt64   `json:"row_id"`
	ProductID               sql.NullInt32   `json:"product_id"`
	TotalBoxes              sql.NullInt32   `json:"total_boxes"`
	Qcp4ProductName         sql.NullString  `json:"qcp4_product_name"`
	Qcp4ProductStatus       sql.NullString  `json:"qcp4_product_status"`
	Qcp4BoxWeight           sql.NullFloat64 `json:"qcp4_box_weight"`
	Qcp4ProductnetWeight    sql.NullFloat64 `json:"qcp4_productnet_weight"`
	TotalProductNetweight   sql.NullFloat64 `json:"total_product_netweight"`
	TotalProductGrossweight sql.NullFloat64 `json:"total_product_grossweight"`
	SampledBoxes            sql.NullInt32   `json:"sampled_boxes"`
	PackinglistID           int32           `json:"packinglist_id"`
}

func (q *Queries) Qcp4PerConsignment(ctx context.Context, consignmentNo sql.NullString) ([]Qcp4PerConsignmentRow, error) {
	rows, err := q.db.QueryContext(ctx, qcp4PerConsignment, consignmentNo)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp4PerConsignmentRow{}
	for rows.Next() {
		var i Qcp4PerConsignmentRow
		if err := rows.Scan(
			&i.Qcp4orderid,
			&i.Qcp4OrderIds,
			&i.Qcp4id,
			&i.TraceabilityCode,
			&i.RowID,
			&i.ProductID,
			&i.TotalBoxes,
			&i.Qcp4ProductName,
			&i.Qcp4ProductStatus,
			&i.Qcp4BoxWeight,
			&i.Qcp4ProductnetWeight,
			&i.TotalProductNetweight,
			&i.TotalProductGrossweight,
			&i.SampledBoxes,
			&i.PackinglistID,
		); 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 qcp4ProductRow = `-- name: Qcp4ProductRow :one
SELECT qcp4.id as qcp4_id,qcp4_products.status as qcp4_product_status, qcp4_products.id as qcp4_row_id  from qcp4_products
JOIN   qcp4 on qcp4.id = qcp4_products.qcp4_id
JOIN   packinglist on packinglist.id = qcp4.packinglist_id
WHERE  qcp4_products.product_id=$1
AND    qcp4_products.traceability_code=$2
AND    qcp4_products.boxweight=$3
AND    qcp4.packinglist_id = $4
`

type Qcp4ProductRowParams struct {
	ProductID        int32           `json:"product_id"`
	TraceabilityCode string          `json:"traceability_code"`
	Boxweight        sql.NullFloat64 `json:"boxweight"`
	PackinglistID    int32           `json:"packinglist_id"`
}

type Qcp4ProductRowRow struct {
	Qcp4ID            int64  `json:"qcp4_id"`
	Qcp4ProductStatus string `json:"qcp4_product_status"`
	Qcp4RowID         int64  `json:"qcp4_row_id"`
}

func (q *Queries) Qcp4ProductRow(ctx context.Context, arg Qcp4ProductRowParams) (Qcp4ProductRowRow, error) {
	row := q.db.QueryRowContext(ctx, qcp4ProductRow,
		arg.ProductID,
		arg.TraceabilityCode,
		arg.Boxweight,
		arg.PackinglistID,
	)
	var i Qcp4ProductRowRow
	err := row.Scan(&i.Qcp4ID, &i.Qcp4ProductStatus, &i.Qcp4RowID)
	return i, err
}

const qcp4ProductsContentPerOrder = `-- name: Qcp4ProductsContentPerOrder :many
select qcp4_products.qcp4_id,qcp4_products.totalboxes,
qcp4_products.boxweight,qcp4_products.productnetweight,crops.cropname,crops.id,crops.variant,
crops.crophscode,qcp4_products.totalproductnetweight,qcp4_products.traceability_code,
qcp4_products.totalproductgrossweight,qcp4_products.status,
qcp4_products.sampledboxes,qcp4_products.created_at,qcp4_products.id as product_row_id,qcp4_products.product_id from qcp4_products
JOIN crops on crops.id = qcp4_products.product_id
WHERE qcp4_products.qcp4_id = $1
`

type Qcp4ProductsContentPerOrderRow struct {
	Qcp4ID                  int32           `json:"qcp4_id"`
	Totalboxes              int32           `json:"totalboxes"`
	Boxweight               sql.NullFloat64 `json:"boxweight"`
	Productnetweight        sql.NullFloat64 `json:"productnetweight"`
	Cropname                string          `json:"cropname"`
	ID                      int64           `json:"id"`
	Variant                 string          `json:"variant"`
	Crophscode              string          `json:"crophscode"`
	Totalproductnetweight   sql.NullFloat64 `json:"totalproductnetweight"`
	TraceabilityCode        string          `json:"traceability_code"`
	Totalproductgrossweight sql.NullFloat64 `json:"totalproductgrossweight"`
	Status                  string          `json:"status"`
	Sampledboxes            sql.NullInt32   `json:"sampledboxes"`
	CreatedAt               time.Time       `json:"created_at"`
	ProductRowID            int64           `json:"product_row_id"`
	ProductID               int32           `json:"product_id"`
}

func (q *Queries) Qcp4ProductsContentPerOrder(ctx context.Context, qcp4ID int32) ([]Qcp4ProductsContentPerOrderRow, error) {
	rows, err := q.db.QueryContext(ctx, qcp4ProductsContentPerOrder, qcp4ID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp4ProductsContentPerOrderRow{}
	for rows.Next() {
		var i Qcp4ProductsContentPerOrderRow
		if err := rows.Scan(
			&i.Qcp4ID,
			&i.Totalboxes,
			&i.Boxweight,
			&i.Productnetweight,
			&i.Cropname,
			&i.ID,
			&i.Variant,
			&i.Crophscode,
			&i.Totalproductnetweight,
			&i.TraceabilityCode,
			&i.Totalproductgrossweight,
			&i.Status,
			&i.Sampledboxes,
			&i.CreatedAt,
			&i.ProductRowID,
			&i.ProductID,
		); 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 qcp4ProductsReport = `-- name: Qcp4ProductsReport :many
SELECT qcp4_products.qcp4_id,qcp4_products.traceability_code,
qcp4_products.product_id,qcp4_products.totalboxes,
qcp4_products.boxweight,qcp4_products.productnetweight,
qcp4_products.totalproductnetweight,qcp4_products.totalproductgrossweight,
crops.cropname,qcp4_products.sampledboxes,qcp4_products.status,qualityattributes.description
FROM qcp4_products
LEFT JOIN qcp4_attributes   on qcp4_attributes.qcp4_id = qcp4_products.qcp4_id
LEFT JOIN qualityattributes on qualityattributes.id    = qcp4_attributes.qualityattributes_id
LEFT JOIN crops             on crops.id                = qcp4_products.product_id
WHERE qcp4_products.qcp4_id = $1
`

type Qcp4ProductsReportRow struct {
	Qcp4ID                  int32           `json:"qcp4_id"`
	TraceabilityCode        string          `json:"traceability_code"`
	ProductID               int32           `json:"product_id"`
	Totalboxes              int32           `json:"totalboxes"`
	Boxweight               sql.NullFloat64 `json:"boxweight"`
	Productnetweight        sql.NullFloat64 `json:"productnetweight"`
	Totalproductnetweight   sql.NullFloat64 `json:"totalproductnetweight"`
	Totalproductgrossweight sql.NullFloat64 `json:"totalproductgrossweight"`
	Cropname                sql.NullString  `json:"cropname"`
	Sampledboxes            sql.NullInt32   `json:"sampledboxes"`
	Status                  string          `json:"status"`
	Description             sql.NullString  `json:"description"`
}

func (q *Queries) Qcp4ProductsReport(ctx context.Context, qcp4ID int32) ([]Qcp4ProductsReportRow, error) {
	rows, err := q.db.QueryContext(ctx, qcp4ProductsReport, qcp4ID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp4ProductsReportRow{}
	for rows.Next() {
		var i Qcp4ProductsReportRow
		if err := rows.Scan(
			&i.Qcp4ID,
			&i.TraceabilityCode,
			&i.ProductID,
			&i.Totalboxes,
			&i.Boxweight,
			&i.Productnetweight,
			&i.Totalproductnetweight,
			&i.Totalproductgrossweight,
			&i.Cropname,
			&i.Sampledboxes,
			&i.Status,
			&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 qcp4ProductsResortUpdate = `-- name: Qcp4ProductsResortUpdate :one
UPDATE qcp4_products
  set
    totalboxes              = $2,
    productnetweight        = $3,
    totalproductnetweight   = $4,
    totalproductgrossweight = $5,
    sampledboxes            = $6,
    status                  = $7
  WHERE id = $1
RETURNING id, qcp4_id, traceability_code, product_id, totalboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, status, sampledboxes, created_at
`

type Qcp4ProductsResortUpdateParams struct {
	ID                      int64           `json:"id"`
	Totalboxes              int32           `json:"totalboxes"`
	Productnetweight        sql.NullFloat64 `json:"productnetweight"`
	Totalproductnetweight   sql.NullFloat64 `json:"totalproductnetweight"`
	Totalproductgrossweight sql.NullFloat64 `json:"totalproductgrossweight"`
	Sampledboxes            sql.NullInt32   `json:"sampledboxes"`
	Status                  string          `json:"status"`
}

func (q *Queries) Qcp4ProductsResortUpdate(ctx context.Context, arg Qcp4ProductsResortUpdateParams) (Qcp4Product, error) {
	row := q.db.QueryRowContext(ctx, qcp4ProductsResortUpdate,
		arg.ID,
		arg.Totalboxes,
		arg.Productnetweight,
		arg.Totalproductnetweight,
		arg.Totalproductgrossweight,
		arg.Sampledboxes,
		arg.Status,
	)
	var i Qcp4Product
	err := row.Scan(
		&i.ID,
		&i.Qcp4ID,
		&i.TraceabilityCode,
		&i.ProductID,
		&i.Totalboxes,
		&i.Boxweight,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.Status,
		&i.Sampledboxes,
		&i.CreatedAt,
	)
	return i, err
}

const qcp4Recommendations = `-- name: Qcp4Recommendations :many
Select qcp4_recommendations.weight_passed,qcp4_recommendations.weight_rejected,
qcp4_recommendations.status from qcp4_recommendations
WHERE qcp4_id = $1
AND   qcp4_product_id = $2
`

type Qcp4RecommendationsParams struct {
	Qcp4ID        int32 `json:"qcp4_id"`
	Qcp4ProductID int32 `json:"qcp4_product_id"`
}

type Qcp4RecommendationsRow struct {
	WeightPassed   float64 `json:"weight_passed"`
	WeightRejected float64 `json:"weight_rejected"`
	Status         string  `json:"status"`
}

func (q *Queries) Qcp4Recommendations(ctx context.Context, arg Qcp4RecommendationsParams) ([]Qcp4RecommendationsRow, error) {
	rows, err := q.db.QueryContext(ctx, qcp4Recommendations, arg.Qcp4ID, arg.Qcp4ProductID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp4RecommendationsRow{}
	for rows.Next() {
		var i Qcp4RecommendationsRow
		if err := rows.Scan(&i.WeightPassed, &i.WeightRejected, &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 qcp4Report = `-- name: Qcp4Report :one
SELECT qcp4.exportcompany_id,qcp4.created_at,exportcompanies.expname exportcompany_name,users.fullname user_name, qcp4.packinglist_id,
qcp4.user_id,qcp4.status qcp4_status,clients.companyname,countries.countryname,crops.cropname,qcp4_recommendations.status recommendation_status,qcp4_recommendations.weight_passed,qcp4_recommendations.weight_rejected FROM qcp4
LEFT JOIN qcp4_recommendations on qcp4_recommendations.qcp4_id = qcp4.id
LEFT JOIN packinglist          on packinglist.id               = qcp4.packinglist_id
LEFT JOIN receptionform        on receptionform.id             = packinglist.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
WHERE qcp4.id = $1
`

type Qcp4ReportRow struct {
	ExportcompanyID      int32           `json:"exportcompany_id"`
	CreatedAt            time.Time       `json:"created_at"`
	ExportcompanyName    sql.NullString  `json:"exportcompany_name"`
	UserName             sql.NullString  `json:"user_name"`
	PackinglistID        int32           `json:"packinglist_id"`
	UserID               int32           `json:"user_id"`
	Qcp4Status           string          `json:"qcp4_status"`
	Companyname          sql.NullString  `json:"companyname"`
	Countryname          sql.NullString  `json:"countryname"`
	Cropname             sql.NullString  `json:"cropname"`
	RecommendationStatus sql.NullString  `json:"recommendation_status"`
	WeightPassed         sql.NullFloat64 `json:"weight_passed"`
	WeightRejected       sql.NullFloat64 `json:"weight_rejected"`
}

func (q *Queries) Qcp4Report(ctx context.Context, id int64) (Qcp4ReportRow, error) {
	row := q.db.QueryRowContext(ctx, qcp4Report, id)
	var i Qcp4ReportRow
	err := row.Scan(
		&i.ExportcompanyID,
		&i.CreatedAt,
		&i.ExportcompanyName,
		&i.UserName,
		&i.PackinglistID,
		&i.UserID,
		&i.Qcp4Status,
		&i.Companyname,
		&i.Countryname,
		&i.Cropname,
		&i.RecommendationStatus,
		&i.WeightPassed,
		&i.WeightRejected,
	)
	return i, err
}

const qcp4listOtherPerConsignment = `-- name: Qcp4listOtherPerConsignment :many
SELECT orders.id qcp4orderid,qcp4_others.product_name other_product_name,qcp4_others.status qcp4_others_status,orders.id as qcp4_order_ids, qcp4_others.boxweight others_boxweight,
qcp4_others.productnetweight others_product_netweight,qcp4_others.totalproductnetweight others_total_productweight,qcp4_others.totalproductgrossweight others_total_productgrossweight,
qcp4.id qcp4ID,qcp4_others.noofboxes other_box_numbers,qcp4_others.sampledboxes other_sampled_boxes,qcp4_others.id row_other_id,
qcp4.packinglist_id from qcp4
LEFT JOIN qcp4_others   on qcp4_others.qcp4_id   = qcp4.id
LEFT JOIN packinglist   on packinglist.id        = qcp4.packinglist_id
LEFT JOIN orders        on orders.id             = packinglist.order_id
LEFT JOIN users         on users.id              = qcp4.user_id
WHERE qcp4.exportcompany_id     = $3
AND   qcp4.status = $2
AND   orders.consignment_no = $1
GROUP BY qcp4_others.id,qcp4.id,orders.id
`

type Qcp4listOtherPerConsignmentParams struct {
	ConsignmentNo   sql.NullString `json:"consignment_no"`
	Status          string         `json:"status"`
	ExportcompanyID int32          `json:"exportcompany_id"`
}

type Qcp4listOtherPerConsignmentRow struct {
	Qcp4orderid                   sql.NullInt64   `json:"qcp4orderid"`
	OtherProductName              sql.NullString  `json:"other_product_name"`
	Qcp4OthersStatus              sql.NullString  `json:"qcp4_others_status"`
	Qcp4OrderIds                  sql.NullInt64   `json:"qcp4_order_ids"`
	OthersBoxweight               sql.NullFloat64 `json:"others_boxweight"`
	OthersProductNetweight        sql.NullFloat64 `json:"others_product_netweight"`
	OthersTotalProductweight      sql.NullFloat64 `json:"others_total_productweight"`
	OthersTotalProductgrossweight sql.NullFloat64 `json:"others_total_productgrossweight"`
	Qcp4id                        int64           `json:"qcp4id"`
	OtherBoxNumbers               sql.NullInt32   `json:"other_box_numbers"`
	OtherSampledBoxes             sql.NullInt32   `json:"other_sampled_boxes"`
	RowOtherID                    sql.NullInt64   `json:"row_other_id"`
	PackinglistID                 int32           `json:"packinglist_id"`
}

func (q *Queries) Qcp4listOtherPerConsignment(ctx context.Context, arg Qcp4listOtherPerConsignmentParams) ([]Qcp4listOtherPerConsignmentRow, error) {
	rows, err := q.db.QueryContext(ctx, qcp4listOtherPerConsignment, arg.ConsignmentNo, arg.Status, arg.ExportcompanyID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp4listOtherPerConsignmentRow{}
	for rows.Next() {
		var i Qcp4listOtherPerConsignmentRow
		if err := rows.Scan(
			&i.Qcp4orderid,
			&i.OtherProductName,
			&i.Qcp4OthersStatus,
			&i.Qcp4OrderIds,
			&i.OthersBoxweight,
			&i.OthersProductNetweight,
			&i.OthersTotalProductweight,
			&i.OthersTotalProductgrossweight,
			&i.Qcp4id,
			&i.OtherBoxNumbers,
			&i.OtherSampledBoxes,
			&i.RowOtherID,
			&i.PackinglistID,
		); 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 qcp4listPerConsignment = `-- name: Qcp4listPerConsignment :many
SELECT orders.id qcp4orderid,orders.id as qcp4_order_ids,qcp4.id qcp4ID,qcp4_products.traceability_code traceability_code,
qcp4_products.id row_id,qcp4_products.product_id product_id,qcp4_products.totalboxes total_boxes,crops.cropname qcp4_product_name,
qcp4_products.status qcp4_product_status,qcp4_products.boxweight qcp4_box_weight,
qcp4_products.productnetweight qcp4_productnet_weight,qcp4_products.totalproductnetweight total_product_netweight,
qcp4_products.totalproductgrossweight total_product_grossweight,qcp4_products.sampledboxes sampled_boxes, qcp4.packinglist_id from qcp4
LEFT JOIN qcp4_products on qcp4_products.qcp4_id = qcp4.id
LEFT JOIN packinglist   on packinglist.id        = qcp4.packinglist_id
LEFT JOIN orders        on orders.id             = packinglist.order_id
LEFT JOIN crops         on crops.id              = qcp4_products.product_id
LEFT JOIN users         on users.id              = qcp4.user_id
WHERE qcp4.exportcompany_id     = $3
AND   qcp4.status = $2
AND   orders.consignment_no = $1
GROUP BY qcp4.id,qcp4_products.id,crops.cropname,orders.id
`

type Qcp4listPerConsignmentParams struct {
	ConsignmentNo   sql.NullString `json:"consignment_no"`
	Status          string         `json:"status"`
	ExportcompanyID int32          `json:"exportcompany_id"`
}

type Qcp4listPerConsignmentRow struct {
	Qcp4orderid             sql.NullInt64   `json:"qcp4orderid"`
	Qcp4OrderIds            sql.NullInt64   `json:"qcp4_order_ids"`
	Qcp4id                  int64           `json:"qcp4id"`
	TraceabilityCode        sql.NullString  `json:"traceability_code"`
	RowID                   sql.NullInt64   `json:"row_id"`
	ProductID               sql.NullInt32   `json:"product_id"`
	TotalBoxes              sql.NullInt32   `json:"total_boxes"`
	Qcp4ProductName         sql.NullString  `json:"qcp4_product_name"`
	Qcp4ProductStatus       sql.NullString  `json:"qcp4_product_status"`
	Qcp4BoxWeight           sql.NullFloat64 `json:"qcp4_box_weight"`
	Qcp4ProductnetWeight    sql.NullFloat64 `json:"qcp4_productnet_weight"`
	TotalProductNetweight   sql.NullFloat64 `json:"total_product_netweight"`
	TotalProductGrossweight sql.NullFloat64 `json:"total_product_grossweight"`
	SampledBoxes            sql.NullInt32   `json:"sampled_boxes"`
	PackinglistID           int32           `json:"packinglist_id"`
}

func (q *Queries) Qcp4listPerConsignment(ctx context.Context, arg Qcp4listPerConsignmentParams) ([]Qcp4listPerConsignmentRow, error) {
	rows, err := q.db.QueryContext(ctx, qcp4listPerConsignment, arg.ConsignmentNo, arg.Status, arg.ExportcompanyID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Qcp4listPerConsignmentRow{}
	for rows.Next() {
		var i Qcp4listPerConsignmentRow
		if err := rows.Scan(
			&i.Qcp4orderid,
			&i.Qcp4OrderIds,
			&i.Qcp4id,
			&i.TraceabilityCode,
			&i.RowID,
			&i.ProductID,
			&i.TotalBoxes,
			&i.Qcp4ProductName,
			&i.Qcp4ProductStatus,
			&i.Qcp4BoxWeight,
			&i.Qcp4ProductnetWeight,
			&i.TotalProductNetweight,
			&i.TotalProductGrossweight,
			&i.SampledBoxes,
			&i.PackinglistID,
		); 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 updateQcp4 = `-- name: UpdateQcp4 :one
UPDATE qcp4
  set
    status  = $2
WHERE id = $1
RETURNING id, packinglist_id, user_id, status, exportcompany_id, created_at
`

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

func (q *Queries) UpdateQcp4(ctx context.Context, arg UpdateQcp4Params) (Qcp4, error) {
	row := q.db.QueryRowContext(ctx, updateQcp4, arg.ID, arg.Status)
	var i Qcp4
	err := row.Scan(
		&i.ID,
		&i.PackinglistID,
		&i.UserID,
		&i.Status,
		&i.ExportcompanyID,
		&i.CreatedAt,
	)
	return i, err
}

const updateQcp4OtherStatus = `-- name: UpdateQcp4OtherStatus :one
UPDATE qcp4_others
  set
    status = $2
WHERE id = $1
RETURNING id, qcp4_id, packinglist_id, product_name, noofboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, sampledboxes, status, user_id, exportcompany_id, created_at
`

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

func (q *Queries) UpdateQcp4OtherStatus(ctx context.Context, arg UpdateQcp4OtherStatusParams) (Qcp4Other, error) {
	row := q.db.QueryRowContext(ctx, updateQcp4OtherStatus, arg.ID, arg.Status)
	var i Qcp4Other
	err := row.Scan(
		&i.ID,
		&i.Qcp4ID,
		&i.PackinglistID,
		&i.ProductName,
		&i.Noofboxes,
		&i.Boxweight,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.Sampledboxes,
		&i.Status,
		&i.UserID,
		&i.ExportcompanyID,
		&i.CreatedAt,
	)
	return i, err
}

const updateQcp4Others = `-- name: UpdateQcp4Others :one
UPDATE qcp4_others
  set
    qcp4_id = $2,
    product_name = $3,
    noofboxes = $4
WHERE id = $1
RETURNING id, qcp4_id, packinglist_id, product_name, noofboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, sampledboxes, status, user_id, exportcompany_id, created_at
`

type UpdateQcp4OthersParams struct {
	ID          int64  `json:"id"`
	Qcp4ID      int32  `json:"qcp4_id"`
	ProductName string `json:"product_name"`
	Noofboxes   int32  `json:"noofboxes"`
}

func (q *Queries) UpdateQcp4Others(ctx context.Context, arg UpdateQcp4OthersParams) (Qcp4Other, error) {
	row := q.db.QueryRowContext(ctx, updateQcp4Others,
		arg.ID,
		arg.Qcp4ID,
		arg.ProductName,
		arg.Noofboxes,
	)
	var i Qcp4Other
	err := row.Scan(
		&i.ID,
		&i.Qcp4ID,
		&i.PackinglistID,
		&i.ProductName,
		&i.Noofboxes,
		&i.Boxweight,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.Sampledboxes,
		&i.Status,
		&i.UserID,
		&i.ExportcompanyID,
		&i.CreatedAt,
	)
	return i, err
}

const updateQcp4OthersSampled = `-- name: UpdateQcp4OthersSampled :one
UPDATE qcp4_others
  set
    sampledboxes = $2
WHERE id = $1
RETURNING id, qcp4_id, packinglist_id, product_name, noofboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, sampledboxes, status, user_id, exportcompany_id, created_at
`

type UpdateQcp4OthersSampledParams struct {
	ID           int64         `json:"id"`
	Sampledboxes sql.NullInt32 `json:"sampledboxes"`
}

func (q *Queries) UpdateQcp4OthersSampled(ctx context.Context, arg UpdateQcp4OthersSampledParams) (Qcp4Other, error) {
	row := q.db.QueryRowContext(ctx, updateQcp4OthersSampled, arg.ID, arg.Sampledboxes)
	var i Qcp4Other
	err := row.Scan(
		&i.ID,
		&i.Qcp4ID,
		&i.PackinglistID,
		&i.ProductName,
		&i.Noofboxes,
		&i.Boxweight,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.Sampledboxes,
		&i.Status,
		&i.UserID,
		&i.ExportcompanyID,
		&i.CreatedAt,
	)
	return i, err
}

const updateQcp4Products = `-- name: UpdateQcp4Products :one
UPDATE qcp4_products
  set
    status  = $2
WHERE id = $1
RETURNING id, qcp4_id, traceability_code, product_id, totalboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, status, sampledboxes, created_at
`

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

func (q *Queries) UpdateQcp4Products(ctx context.Context, arg UpdateQcp4ProductsParams) (Qcp4Product, error) {
	row := q.db.QueryRowContext(ctx, updateQcp4Products, arg.ID, arg.Status)
	var i Qcp4Product
	err := row.Scan(
		&i.ID,
		&i.Qcp4ID,
		&i.TraceabilityCode,
		&i.ProductID,
		&i.Totalboxes,
		&i.Boxweight,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.Status,
		&i.Sampledboxes,
		&i.CreatedAt,
	)
	return i, err
}

const updateQcp4Sampled = `-- name: UpdateQcp4Sampled :one
UPDATE qcp4_products
  set
    sampledboxes = $2
WHERE id = $1
RETURNING id, qcp4_id, traceability_code, product_id, totalboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, status, sampledboxes, created_at
`

type UpdateQcp4SampledParams struct {
	ID           int64         `json:"id"`
	Sampledboxes sql.NullInt32 `json:"sampledboxes"`
}

func (q *Queries) UpdateQcp4Sampled(ctx context.Context, arg UpdateQcp4SampledParams) (Qcp4Product, error) {
	row := q.db.QueryRowContext(ctx, updateQcp4Sampled, arg.ID, arg.Sampledboxes)
	var i Qcp4Product
	err := row.Scan(
		&i.ID,
		&i.Qcp4ID,
		&i.TraceabilityCode,
		&i.ProductID,
		&i.Totalboxes,
		&i.Boxweight,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.Status,
		&i.Sampledboxes,
		&i.CreatedAt,
	)
	return i, err
}
