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

package db

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

const checkBoxPackinglistID = `-- name: CheckBoxPackinglistID :one
SELECT EXISTS (
    SELECT 1 FROM boxes
    WHERE packinglist_id  = $1
    AND traceability_code = $2
)
`

type CheckBoxPackinglistIDParams struct {
	PackinglistID    int32  `json:"packinglist_id"`
	TraceabilityCode string `json:"traceability_code"`
}

func (q *Queries) CheckBoxPackinglistID(ctx context.Context, arg CheckBoxPackinglistIDParams) (bool, error) {
	row := q.db.QueryRowContext(ctx, checkBoxPackinglistID, arg.PackinglistID, arg.TraceabilityCode)
	var exists bool
	err := row.Scan(&exists)
	return exists, err
}

const checkBoxWeightMatch = `-- name: CheckBoxWeightMatch :one
SELECT EXISTS (
    SELECT 1 FROM packinglist_products
    WHERE packinglist_id = $1
    AND   order_id = $2
    AND   traceability_code = $3
    AND   product_id  = $4
    AND   boxweight   = $5
)
`

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

func (q *Queries) CheckBoxWeightMatch(ctx context.Context, arg CheckBoxWeightMatchParams) (bool, error) {
	row := q.db.QueryRowContext(ctx, checkBoxWeightMatch,
		arg.PackinglistID,
		arg.OrderID,
		arg.TraceabilityCode,
		arg.ProductID,
		arg.Boxweight,
	)
	var exists bool
	err := row.Scan(&exists)
	return exists, err
}

const checkCropAndTraceabilityCode = `-- name: CheckCropAndTraceabilityCode :one
SELECT EXISTS (
    SELECT 1 FROM packinglist_products
    WHERE product_id = $1
    AND   traceability_code = $2
    AND   packinglist_id = $3
    AND   order_id       = $4
)
`

type CheckCropAndTraceabilityCodeParams struct {
	ProductID        int32  `json:"product_id"`
	TraceabilityCode string `json:"traceability_code"`
	PackinglistID    int32  `json:"packinglist_id"`
	OrderID          int32  `json:"order_id"`
}

func (q *Queries) CheckCropAndTraceabilityCode(ctx context.Context, arg CheckCropAndTraceabilityCodeParams) (bool, error) {
	row := q.db.QueryRowContext(ctx, checkCropAndTraceabilityCode,
		arg.ProductID,
		arg.TraceabilityCode,
		arg.PackinglistID,
		arg.OrderID,
	)
	var exists bool
	err := row.Scan(&exists)
	return exists, err
}

const checkOrderExistanceinPackingList = `-- name: CheckOrderExistanceinPackingList :one
SELECT EXISTS (
    SELECT 1 FROM packinglist_products
    WHERE packinglist_products.order_id = $1
)
`

func (q *Queries) CheckOrderExistanceinPackingList(ctx context.Context, orderID int32) (bool, error) {
	row := q.db.QueryRowContext(ctx, checkOrderExistanceinPackingList, orderID)
	var exists bool
	err := row.Scan(&exists)
	return exists, err
}

const checkOrderIDExistance = `-- name: CheckOrderIDExistance :one
SELECT EXISTS (
    SELECT 1 FROM packinglist
    WHERE order_id = $1
)
`

func (q *Queries) CheckOrderIDExistance(ctx context.Context, orderID int32) (bool, error) {
	row := q.db.QueryRowContext(ctx, checkOrderIDExistance, orderID)
	var exists bool
	err := row.Scan(&exists)
	return exists, err
}

const checkQcp4PackinglistID = `-- name: CheckQcp4PackinglistID :one
SELECT EXISTS (
    SELECT 1 FROM qcp4
    WHERE packinglist_id = $1
)
`

func (q *Queries) CheckQcp4PackinglistID(ctx context.Context, packinglistID int32) (bool, error) {
	row := q.db.QueryRowContext(ctx, checkQcp4PackinglistID, packinglistID)
	var exists bool
	err := row.Scan(&exists)
	return exists, err
}

const checkQcp5PackinglistID = `-- name: CheckQcp5PackinglistID :one
SELECT EXISTS (
    SELECT 1 FROM qcp5
    WHERE packinglist_id = $1
)
`

func (q *Queries) CheckQcp5PackinglistID(ctx context.Context, packinglistID int32) (bool, error) {
	row := q.db.QueryRowContext(ctx, checkQcp5PackinglistID, packinglistID)
	var exists bool
	err := row.Scan(&exists)
	return exists, err
}

const createPackingList = `-- name: CreatePackingList :one
INSERT INTO packinglist (
    status,
    order_id,
    user_id,
    exportcompany_id
 ) VALUES (
      $1,
      $2,
      $3,
      $4
 ) RETURNING id, status, user_id, exportcompany_id, order_id, updated_by, created_at
`

type CreatePackingListParams struct {
	Status          string `json:"status"`
	OrderID         int32  `json:"order_id"`
	UserID          int32  `json:"user_id"`
	ExportcompanyID int32  `json:"exportcompany_id"`
}

func (q *Queries) CreatePackingList(ctx context.Context, arg CreatePackingListParams) (Packinglist, error) {
	row := q.db.QueryRowContext(ctx, createPackingList,
		arg.Status,
		arg.OrderID,
		arg.UserID,
		arg.ExportcompanyID,
	)
	var i Packinglist
	err := row.Scan(
		&i.ID,
		&i.Status,
		&i.UserID,
		&i.ExportcompanyID,
		&i.OrderID,
		&i.UpdatedBy,
		&i.CreatedAt,
	)
	return i, err
}

const createPackingListBatch = `-- name: CreatePackingListBatch :one
INSERT INTO packinglist_batch (
      packinglist_id,
      order_id,
      receptionform_id,
      batchno,
      traceability_code,
      product_id,
      boxweight,
      productnetweight,
      totalproductnetweight,
      totalproductgrossweight,
      totalboxes
 ) VALUES (
      $1,
      $2,
      $3,
      $4,
      $5,
      $6,
      $7,
      $8,
      $9,
      $10,
      $11
 ) RETURNING id, batchno, packinglist_id, order_id, receptionform_id, traceability_code, product_id, totalboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, created_at, status
`

type CreatePackingListBatchParams struct {
	PackinglistID           int32           `json:"packinglist_id"`
	OrderID                 int32           `json:"order_id"`
	ReceptionformID         int32           `json:"receptionform_id"`
	Batchno                 string          `json:"batchno"`
	TraceabilityCode        string          `json:"traceability_code"`
	ProductID               int32           `json:"product_id"`
	Boxweight               sql.NullFloat64 `json:"boxweight"`
	Productnetweight        sql.NullFloat64 `json:"productnetweight"`
	Totalproductnetweight   sql.NullFloat64 `json:"totalproductnetweight"`
	Totalproductgrossweight sql.NullFloat64 `json:"totalproductgrossweight"`
	Totalboxes              sql.NullInt32   `json:"totalboxes"`
}

func (q *Queries) CreatePackingListBatch(ctx context.Context, arg CreatePackingListBatchParams) (PackinglistBatch, error) {
	row := q.db.QueryRowContext(ctx, createPackingListBatch,
		arg.PackinglistID,
		arg.OrderID,
		arg.ReceptionformID,
		arg.Batchno,
		arg.TraceabilityCode,
		arg.ProductID,
		arg.Boxweight,
		arg.Productnetweight,
		arg.Totalproductnetweight,
		arg.Totalproductgrossweight,
		arg.Totalboxes,
	)
	var i PackinglistBatch
	err := row.Scan(
		&i.ID,
		&i.Batchno,
		&i.PackinglistID,
		&i.OrderID,
		&i.ReceptionformID,
		&i.TraceabilityCode,
		&i.ProductID,
		&i.Totalboxes,
		&i.Boxweight,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.CreatedAt,
		&i.Status,
	)
	return i, err
}

const createPackingListOthers = `-- name: CreatePackingListOthers :one
INSERT INTO packinglist_others (
      packinglist_id,
      productname,
      totalboxes,
      boxweight,
      productnetweight,
      totalproductnetweight,
      totalproductgrossweight
 ) VALUES (
      $1,
      $2,
      $3,
      $4,
      $5,
      $6,
      $7
 ) RETURNING id, packinglist_id, productname, totalboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, created_at, status
`

type CreatePackingListOthersParams struct {
	PackinglistID           int32   `json:"packinglist_id"`
	Productname             string  `json:"productname"`
	Totalboxes              int32   `json:"totalboxes"`
	Boxweight               float64 `json:"boxweight"`
	Productnetweight        float64 `json:"productnetweight"`
	Totalproductnetweight   float64 `json:"totalproductnetweight"`
	Totalproductgrossweight float64 `json:"totalproductgrossweight"`
}

func (q *Queries) CreatePackingListOthers(ctx context.Context, arg CreatePackingListOthersParams) (PackinglistOther, error) {
	row := q.db.QueryRowContext(ctx, createPackingListOthers,
		arg.PackinglistID,
		arg.Productname,
		arg.Totalboxes,
		arg.Boxweight,
		arg.Productnetweight,
		arg.Totalproductnetweight,
		arg.Totalproductgrossweight,
	)
	var i PackinglistOther
	err := row.Scan(
		&i.ID,
		&i.PackinglistID,
		&i.Productname,
		&i.Totalboxes,
		&i.Boxweight,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.CreatedAt,
		&i.Status,
	)
	return i, err
}

const createPackingListProducts = `-- name: CreatePackingListProducts :one
INSERT INTO packinglist_products (
      packinglist_id,
      order_id,
      receptionform_id,
      batchno,
      traceability_code,
      product_id,
      totalboxes,
      boxweight,
      productnetweight,
      totalproductnetweight,
      totalproductgrossweight
 ) VALUES (
      $1,
      $2,
      $3,
      $4,
      $5,
      $6,
      $7,
      $8,
      $9,
      $10,
      $11
 ) RETURNING id, packinglist_id, batchno, receptionform_id, order_id, traceability_code, product_id, boxweight, totalboxes, productnetweight, totalproductnetweight, totalproductgrossweight, created_at, status
`

type CreatePackingListProductsParams struct {
	PackinglistID           int32           `json:"packinglist_id"`
	OrderID                 int32           `json:"order_id"`
	ReceptionformID         int32           `json:"receptionform_id"`
	Batchno                 sql.NullString  `json:"batchno"`
	TraceabilityCode        string          `json:"traceability_code"`
	ProductID               int32           `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"`
}

func (q *Queries) CreatePackingListProducts(ctx context.Context, arg CreatePackingListProductsParams) (PackinglistProduct, error) {
	row := q.db.QueryRowContext(ctx, createPackingListProducts,
		arg.PackinglistID,
		arg.OrderID,
		arg.ReceptionformID,
		arg.Batchno,
		arg.TraceabilityCode,
		arg.ProductID,
		arg.Totalboxes,
		arg.Boxweight,
		arg.Productnetweight,
		arg.Totalproductnetweight,
		arg.Totalproductgrossweight,
	)
	var i PackinglistProduct
	err := row.Scan(
		&i.ID,
		&i.PackinglistID,
		&i.Batchno,
		&i.ReceptionformID,
		&i.OrderID,
		&i.TraceabilityCode,
		&i.ProductID,
		&i.Boxweight,
		&i.Totalboxes,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.CreatedAt,
		&i.Status,
	)
	return i, err
}

const deletePackList = `-- name: DeletePackList :exec
DELETE FROM packinglist WHERE id= $1
`

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

const deletePackingList = `-- name: DeletePackingList :exec
DELETE FROM packinglist_others WHERE packinglist_id= $1
`

func (q *Queries) DeletePackingList(ctx context.Context, packinglistID int32) error {
	_, err := q.db.ExecContext(ctx, deletePackingList, packinglistID)
	return err
}

const deletePackingListBatch = `-- name: DeletePackingListBatch :exec
DELETE FROM packinglist_batch WHERE packinglist_id= $1
`

func (q *Queries) DeletePackingListBatch(ctx context.Context, packinglistID int32) error {
	_, err := q.db.ExecContext(ctx, deletePackingListBatch, packinglistID)
	return err
}

const deletePackingListOtherProducts = `-- name: DeletePackingListOtherProducts :exec
DELETE FROM packinglist_others WHERE id= $1
`

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

const deletePackingListProducts = `-- name: DeletePackingListProducts :exec
DELETE FROM packinglist_products WHERE packinglist_id= $1
`

func (q *Queries) DeletePackingListProducts(ctx context.Context, packinglistID int32) error {
	_, err := q.db.ExecContext(ctx, deletePackingListProducts, packinglistID)
	return err
}

const detailsBatchPackingList = `-- name: DetailsBatchPackingList :one
SELECT id, batchno, packinglist_id, order_id, receptionform_id, traceability_code, product_id, totalboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, created_at, status FROM packinglist_batch
WHERE id = $1
`

func (q *Queries) DetailsBatchPackingList(ctx context.Context, id int64) (PackinglistBatch, error) {
	row := q.db.QueryRowContext(ctx, detailsBatchPackingList, id)
	var i PackinglistBatch
	err := row.Scan(
		&i.ID,
		&i.Batchno,
		&i.PackinglistID,
		&i.OrderID,
		&i.ReceptionformID,
		&i.TraceabilityCode,
		&i.ProductID,
		&i.Totalboxes,
		&i.Boxweight,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.CreatedAt,
		&i.Status,
	)
	return i, err
}

const getInterceptionNoticeOtherProducts = `-- name: GetInterceptionNoticeOtherProducts :many
select productothers_interception_notice.packinglist_other_id,productothers_interception_notice.consignment_no,
productothers_interception_notice.exportcompany_id,productothers_interception_notice.reason,packinglist_others.productname,
productothers_interception_notice.action,productothers_interception_notice.notes,productothers_interception_notice.user_id,
productothers_interception_notice.weight_rejected,productothers_interception_notice.qcp5_row_other_id,users.fullname, exportcompanies.expname,productothers_interception_notice.created_at
from productothers_interception_notice
JOIN users on users.id = productothers_interception_notice.user_id
JOIN exportcompanies on exportcompanies.id = productothers_interception_notice.exportcompany_id
JOIN  packinglist_others on packinglist_others.id = productothers_interception_notice.packinglist_other_id
WHERE productothers_interception_notice.consignment_no = $1
`

type GetInterceptionNoticeOtherProductsRow struct {
	PackinglistOtherID int32           `json:"packinglist_other_id"`
	ConsignmentNo      string          `json:"consignment_no"`
	ExportcompanyID    int32           `json:"exportcompany_id"`
	Reason             string          `json:"reason"`
	Productname        string          `json:"productname"`
	Action             string          `json:"action"`
	Notes              string          `json:"notes"`
	UserID             int32           `json:"user_id"`
	WeightRejected     sql.NullFloat64 `json:"weight_rejected"`
	Qcp5RowOtherID     sql.NullInt32   `json:"qcp5_row_other_id"`
	Fullname           string          `json:"fullname"`
	Expname            string          `json:"expname"`
	CreatedAt          time.Time       `json:"created_at"`
}

func (q *Queries) GetInterceptionNoticeOtherProducts(ctx context.Context, consignmentNo string) ([]GetInterceptionNoticeOtherProductsRow, error) {
	rows, err := q.db.QueryContext(ctx, getInterceptionNoticeOtherProducts, consignmentNo)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []GetInterceptionNoticeOtherProductsRow{}
	for rows.Next() {
		var i GetInterceptionNoticeOtherProductsRow
		if err := rows.Scan(
			&i.PackinglistOtherID,
			&i.ConsignmentNo,
			&i.ExportcompanyID,
			&i.Reason,
			&i.Productname,
			&i.Action,
			&i.Notes,
			&i.UserID,
			&i.WeightRejected,
			&i.Qcp5RowOtherID,
			&i.Fullname,
			&i.Expname,
			&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 getInterceptionNoticeProducts = `-- name: GetInterceptionNoticeProducts :many
select product_interception_notice.packinglist_product_id,product_interception_notice.consignment_no,product_interception_notice.exportcompany_id,product_interception_notice.reason,
product_interception_notice.action,product_interception_notice.notes,product_interception_notice.weight_rejected,product_interception_notice.qcp5_row_id,product_interception_notice.user_id, users.fullname, exportcompanies.expname, crops.crophscode, crops.cropname, crops.variant, product_interception_notice.created_at from product_interception_notice
JOIN users on users.id = product_interception_notice.user_id
JOIN exportcompanies on exportcompanies.id = product_interception_notice.exportcompany_id
JOIN crops on crops.id  = product_interception_notice.packinglist_product_id
WHERE product_interception_notice.consignment_no = $1
`

type GetInterceptionNoticeProductsRow struct {
	PackinglistProductID int32           `json:"packinglist_product_id"`
	ConsignmentNo        string          `json:"consignment_no"`
	ExportcompanyID      int32           `json:"exportcompany_id"`
	Reason               string          `json:"reason"`
	Action               string          `json:"action"`
	Notes                string          `json:"notes"`
	WeightRejected       sql.NullFloat64 `json:"weight_rejected"`
	Qcp5RowID            sql.NullInt32   `json:"qcp5_row_id"`
	UserID               int32           `json:"user_id"`
	Fullname             string          `json:"fullname"`
	Expname              string          `json:"expname"`
	Crophscode           string          `json:"crophscode"`
	Cropname             string          `json:"cropname"`
	Variant              string          `json:"variant"`
	CreatedAt            time.Time       `json:"created_at"`
}

func (q *Queries) GetInterceptionNoticeProducts(ctx context.Context, consignmentNo string) ([]GetInterceptionNoticeProductsRow, error) {
	rows, err := q.db.QueryContext(ctx, getInterceptionNoticeProducts, consignmentNo)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []GetInterceptionNoticeProductsRow{}
	for rows.Next() {
		var i GetInterceptionNoticeProductsRow
		if err := rows.Scan(
			&i.PackinglistProductID,
			&i.ConsignmentNo,
			&i.ExportcompanyID,
			&i.Reason,
			&i.Action,
			&i.Notes,
			&i.WeightRejected,
			&i.Qcp5RowID,
			&i.UserID,
			&i.Fullname,
			&i.Expname,
			&i.Crophscode,
			&i.Cropname,
			&i.Variant,
			&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 getPackList = `-- name: GetPackList :one
SELECT id, status, user_id, exportcompany_id, order_id, updated_by, created_at FROM packinglist
WHERE id = $1 LIMIT 1
`

func (q *Queries) GetPackList(ctx context.Context, id int64) (Packinglist, error) {
	row := q.db.QueryRowContext(ctx, getPackList, id)
	var i Packinglist
	err := row.Scan(
		&i.ID,
		&i.Status,
		&i.UserID,
		&i.ExportcompanyID,
		&i.OrderID,
		&i.UpdatedBy,
		&i.CreatedAt,
	)
	return i, err
}

const getPackingListDetails = `-- name: GetPackingListDetails :one
SELECT packinglist.status,packinglist.created_at,clients.companyname,countries.countryname,exportcompanies.expname,exportcompanies.expregno,
packhouses.phname,orders.created_at order_created_at,packinglist.user_id user_id,
packinglist.created_at packinglist_created_at,orders.consignment_no,exportcompanies.id exportcompany_id FROM packinglist
JOIN orders             on orders.id          = packinglist.order_id
JOIN exportcompanies    on exportcompanies.id = packinglist.exportcompany_id
JOIN packhouse_exporter on packhouse_exporter.exportcompany_id = exportcompanies.id
JOIN packhouses         on packhouses.id      = packhouse_exporter.packhouse_id
JOIN clients            on clients.id         = orders.client_id
JOIN countries          on countries.id       = clients.country_id
WHERE packinglist.id = $1
`

type GetPackingListDetailsRow struct {
	Status               string         `json:"status"`
	CreatedAt            time.Time      `json:"created_at"`
	Companyname          string         `json:"companyname"`
	Countryname          string         `json:"countryname"`
	Expname              string         `json:"expname"`
	Expregno             string         `json:"expregno"`
	Phname               string         `json:"phname"`
	OrderCreatedAt       time.Time      `json:"order_created_at"`
	UserID               int32          `json:"user_id"`
	PackinglistCreatedAt time.Time      `json:"packinglist_created_at"`
	ConsignmentNo        sql.NullString `json:"consignment_no"`
	ExportcompanyID      int64          `json:"exportcompany_id"`
}

func (q *Queries) GetPackingListDetails(ctx context.Context, id int64) (GetPackingListDetailsRow, error) {
	row := q.db.QueryRowContext(ctx, getPackingListDetails, id)
	var i GetPackingListDetailsRow
	err := row.Scan(
		&i.Status,
		&i.CreatedAt,
		&i.Companyname,
		&i.Countryname,
		&i.Expname,
		&i.Expregno,
		&i.Phname,
		&i.OrderCreatedAt,
		&i.UserID,
		&i.PackinglistCreatedAt,
		&i.ConsignmentNo,
		&i.ExportcompanyID,
	)
	return i, err
}

const getPackingListOthers = `-- name: GetPackingListOthers :one
SELECT id, packinglist_id, productname, totalboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, created_at, status FROM packinglist_others
WHERE packinglist_id = $1 LIMIT 1
`

func (q *Queries) GetPackingListOthers(ctx context.Context, packinglistID int32) (PackinglistOther, error) {
	row := q.db.QueryRowContext(ctx, getPackingListOthers, packinglistID)
	var i PackinglistOther
	err := row.Scan(
		&i.ID,
		&i.PackinglistID,
		&i.Productname,
		&i.Totalboxes,
		&i.Boxweight,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.CreatedAt,
		&i.Status,
	)
	return i, err
}

const getPackinglistBatchRow = `-- name: GetPackinglistBatchRow :one
SELECT id, batchno, packinglist_id, order_id, receptionform_id, traceability_code, product_id, totalboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, created_at, status FROM packinglist_batch
WHERE product_id        = $1
AND   packinglist_id    = $2
AND   order_id          = $3
AND   traceability_code = $4
AND   boxweight         = $5
`

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

func (q *Queries) GetPackinglistBatchRow(ctx context.Context, arg GetPackinglistBatchRowParams) (PackinglistBatch, error) {
	row := q.db.QueryRowContext(ctx, getPackinglistBatchRow,
		arg.ProductID,
		arg.PackinglistID,
		arg.OrderID,
		arg.TraceabilityCode,
		arg.Boxweight,
	)
	var i PackinglistBatch
	err := row.Scan(
		&i.ID,
		&i.Batchno,
		&i.PackinglistID,
		&i.OrderID,
		&i.ReceptionformID,
		&i.TraceabilityCode,
		&i.ProductID,
		&i.Totalboxes,
		&i.Boxweight,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.CreatedAt,
		&i.Status,
	)
	return i, err
}

const getPackinglistProductStatusRow = `-- name: GetPackinglistProductStatusRow :one
SELECT id, packinglist_id, batchno, receptionform_id, order_id, traceability_code, product_id, boxweight, totalboxes, productnetweight, totalproductnetweight, totalproductgrossweight, created_at, status FROM packinglist_products
WHERE product_id        = $1
AND   packinglist_id    = $2
AND   order_id          = $3
AND   traceability_code = $4
AND   boxweight         = $5
`

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

func (q *Queries) GetPackinglistProductStatusRow(ctx context.Context, arg GetPackinglistProductStatusRowParams) (PackinglistProduct, error) {
	row := q.db.QueryRowContext(ctx, getPackinglistProductStatusRow,
		arg.ProductID,
		arg.PackinglistID,
		arg.OrderID,
		arg.TraceabilityCode,
		arg.Boxweight,
	)
	var i PackinglistProduct
	err := row.Scan(
		&i.ID,
		&i.PackinglistID,
		&i.Batchno,
		&i.ReceptionformID,
		&i.OrderID,
		&i.TraceabilityCode,
		&i.ProductID,
		&i.Boxweight,
		&i.Totalboxes,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.CreatedAt,
		&i.Status,
	)
	return i, err
}

const interceptOtherProductPackingList = `-- name: InterceptOtherProductPackingList :one
INSERT INTO productothers_interception_notice (
    packinglist_other_id,
    qcp5_row_other_id,
    weight_rejected,
    consignment_no,
    exportcompany_id,
    reason,
    action,
    notes,
    user_id
 ) VALUES (
      $1,
      $2,
      $3,
      $4,
      $5,
      $6,
      $7,
      $8,
      $9
 ) RETURNING id, packinglist_other_id, consignment_no, exportcompany_id, reason, action, notes, user_id, created_at, weight_rejected, qcp5_row_other_id
`

type InterceptOtherProductPackingListParams struct {
	PackinglistOtherID int32           `json:"packinglist_other_id"`
	Qcp5RowOtherID     sql.NullInt32   `json:"qcp5_row_other_id"`
	WeightRejected     sql.NullFloat64 `json:"weight_rejected"`
	ConsignmentNo      string          `json:"consignment_no"`
	ExportcompanyID    int32           `json:"exportcompany_id"`
	Reason             string          `json:"reason"`
	Action             string          `json:"action"`
	Notes              string          `json:"notes"`
	UserID             int32           `json:"user_id"`
}

func (q *Queries) InterceptOtherProductPackingList(ctx context.Context, arg InterceptOtherProductPackingListParams) (ProductothersInterceptionNotice, error) {
	row := q.db.QueryRowContext(ctx, interceptOtherProductPackingList,
		arg.PackinglistOtherID,
		arg.Qcp5RowOtherID,
		arg.WeightRejected,
		arg.ConsignmentNo,
		arg.ExportcompanyID,
		arg.Reason,
		arg.Action,
		arg.Notes,
		arg.UserID,
	)
	var i ProductothersInterceptionNotice
	err := row.Scan(
		&i.ID,
		&i.PackinglistOtherID,
		&i.ConsignmentNo,
		&i.ExportcompanyID,
		&i.Reason,
		&i.Action,
		&i.Notes,
		&i.UserID,
		&i.CreatedAt,
		&i.WeightRejected,
		&i.Qcp5RowOtherID,
	)
	return i, err
}

const interceptProductPackingList = `-- name: InterceptProductPackingList :one
INSERT INTO product_interception_notice (
    packinglist_product_id,
    consignment_no,
    weight_rejected,
    qcp5_row_id,
    exportcompany_id,
    reason,
    action,
    notes,
    user_id
 ) VALUES (
      $1,
      $2,
      $3,
      $4,
      $5,
      $6,
      $7,
      $8,
      $9
 ) RETURNING id, packinglist_product_id, consignment_no, exportcompany_id, reason, action, notes, user_id, created_at, weight_rejected, qcp5_row_id
`

type InterceptProductPackingListParams struct {
	PackinglistProductID int32           `json:"packinglist_product_id"`
	ConsignmentNo        string          `json:"consignment_no"`
	WeightRejected       sql.NullFloat64 `json:"weight_rejected"`
	Qcp5RowID            sql.NullInt32   `json:"qcp5_row_id"`
	ExportcompanyID      int32           `json:"exportcompany_id"`
	Reason               string          `json:"reason"`
	Action               string          `json:"action"`
	Notes                string          `json:"notes"`
	UserID               int32           `json:"user_id"`
}

func (q *Queries) InterceptProductPackingList(ctx context.Context, arg InterceptProductPackingListParams) (ProductInterceptionNotice, error) {
	row := q.db.QueryRowContext(ctx, interceptProductPackingList,
		arg.PackinglistProductID,
		arg.ConsignmentNo,
		arg.WeightRejected,
		arg.Qcp5RowID,
		arg.ExportcompanyID,
		arg.Reason,
		arg.Action,
		arg.Notes,
		arg.UserID,
	)
	var i ProductInterceptionNotice
	err := row.Scan(
		&i.ID,
		&i.PackinglistProductID,
		&i.ConsignmentNo,
		&i.ExportcompanyID,
		&i.Reason,
		&i.Action,
		&i.Notes,
		&i.UserID,
		&i.CreatedAt,
		&i.WeightRejected,
		&i.Qcp5RowID,
	)
	return i, err
}

const listExporterOrderPackingLists = `-- name: ListExporterOrderPackingLists :many
SELECT packinglist.order_id,countries.countryname destination,clients.companyname, packinglist.created_at,
packinglist.id packinglists_id,packinglist.status packinglist_status, users.id user_id, users.fullname, exportcompanies.expname,
packhouses.phname,exportcompanies.expregno,orders.created_at as order_date FROM packinglist
JOIN orders    on orders.id                = packinglist.order_id
JOIN clients   on clients.id               = orders.client_id
JOIN users     on users.id                 = packinglist.user_id
JOIN countries on countries.id             = clients.country_id
JOIN exportcompanies    on exportcompanies.id = packinglist.exportcompany_id
JOIN packhouse_exporter on packhouse_exporter.exportcompany_id = exportcompanies.id
JOIN packhouses         on packhouses.id   = packhouse_exporter.packhouse_id
WHERE packinglist.order_id    = $3
AND   packinglist.status              = $4
ORDER BY packinglist.id DESC LIMIT $1 OFFSET $2
`

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

type ListExporterOrderPackingListsRow struct {
	OrderID           int32     `json:"order_id"`
	Destination       string    `json:"destination"`
	Companyname       string    `json:"companyname"`
	CreatedAt         time.Time `json:"created_at"`
	PackinglistsID    int64     `json:"packinglists_id"`
	PackinglistStatus string    `json:"packinglist_status"`
	UserID            int64     `json:"user_id"`
	Fullname          string    `json:"fullname"`
	Expname           string    `json:"expname"`
	Phname            string    `json:"phname"`
	Expregno          string    `json:"expregno"`
	OrderDate         time.Time `json:"order_date"`
}

func (q *Queries) ListExporterOrderPackingLists(ctx context.Context, arg ListExporterOrderPackingListsParams) ([]ListExporterOrderPackingListsRow, error) {
	rows, err := q.db.QueryContext(ctx, listExporterOrderPackingLists,
		arg.Limit,
		arg.Offset,
		arg.OrderID,
		arg.Status,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListExporterOrderPackingListsRow{}
	for rows.Next() {
		var i ListExporterOrderPackingListsRow
		if err := rows.Scan(
			&i.OrderID,
			&i.Destination,
			&i.Companyname,
			&i.CreatedAt,
			&i.PackinglistsID,
			&i.PackinglistStatus,
			&i.UserID,
			&i.Fullname,
			&i.Expname,
			&i.Phname,
			&i.Expregno,
			&i.OrderDate,
		); 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 listExporterPackingLists = `-- name: ListExporterPackingLists :many
SELECT packinglist.order_id,countries.countryname destination,clients.companyname, packinglist.created_at,
packinglist.id packinglists_id,packinglist.status packinglist_status, users.id user_id, users.fullname, exportcompanies.expname,
packhouses.phname,exportcompanies.expregno,orders.created_at as order_date FROM packinglist
JOIN orders    on orders.id                = packinglist.order_id
JOIN clients   on clients.id               = orders.client_id
JOIN users     on users.id                 = packinglist.user_id
JOIN countries on countries.id             = clients.country_id
JOIN exportcompanies    on exportcompanies.id = packinglist.exportcompany_id
JOIN packhouse_exporter on packhouse_exporter.exportcompany_id = exportcompanies.id
JOIN packhouses         on packhouses.id   = packhouse_exporter.packhouse_id
WHERE packinglist.exportcompany_id    = $3
AND   packinglist.status              = $4
ORDER BY packinglist.id DESC LIMIT $1 OFFSET $2
`

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

type ListExporterPackingListsRow struct {
	OrderID           int32     `json:"order_id"`
	Destination       string    `json:"destination"`
	Companyname       string    `json:"companyname"`
	CreatedAt         time.Time `json:"created_at"`
	PackinglistsID    int64     `json:"packinglists_id"`
	PackinglistStatus string    `json:"packinglist_status"`
	UserID            int64     `json:"user_id"`
	Fullname          string    `json:"fullname"`
	Expname           string    `json:"expname"`
	Phname            string    `json:"phname"`
	Expregno          string    `json:"expregno"`
	OrderDate         time.Time `json:"order_date"`
}

func (q *Queries) ListExporterPackingLists(ctx context.Context, arg ListExporterPackingListsParams) ([]ListExporterPackingListsRow, error) {
	rows, err := q.db.QueryContext(ctx, listExporterPackingLists,
		arg.Limit,
		arg.Offset,
		arg.ExportcompanyID,
		arg.Status,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListExporterPackingListsRow{}
	for rows.Next() {
		var i ListExporterPackingListsRow
		if err := rows.Scan(
			&i.OrderID,
			&i.Destination,
			&i.Companyname,
			&i.CreatedAt,
			&i.PackinglistsID,
			&i.PackinglistStatus,
			&i.UserID,
			&i.Fullname,
			&i.Expname,
			&i.Phname,
			&i.Expregno,
			&i.OrderDate,
		); 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 listFarmersOnPackingList = `-- name: ListFarmersOnPackingList :many
SELECT crops.cropname,crops.crophscode,farmers.fmname,crops.variant,farmers.fmphone from packinglist_products
JOIN packinglist  on packinglist.id                 = packinglist_products.packinglist_id
JOIN orders       on orders.id                      = packinglist.order_id
JOIN farmer_farms on farmer_farms.traceability_code = packinglist_products.traceability_code
JOIN farmers      on farmers.id                     = farmer_farms.farmer_id
JOIN crops        on crops.id                       = farmer_farms.crop_id
Where orders.consignment_no = $1
`

type ListFarmersOnPackingListRow struct {
	Cropname   string `json:"cropname"`
	Crophscode string `json:"crophscode"`
	Fmname     string `json:"fmname"`
	Variant    string `json:"variant"`
	Fmphone    string `json:"fmphone"`
}

func (q *Queries) ListFarmersOnPackingList(ctx context.Context, consignmentNo sql.NullString) ([]ListFarmersOnPackingListRow, error) {
	rows, err := q.db.QueryContext(ctx, listFarmersOnPackingList, consignmentNo)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListFarmersOnPackingListRow{}
	for rows.Next() {
		var i ListFarmersOnPackingListRow
		if err := rows.Scan(
			&i.Cropname,
			&i.Crophscode,
			&i.Fmname,
			&i.Variant,
			&i.Fmphone,
		); 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 listPackLists = `-- name: ListPackLists :many
SELECT id, status, user_id, exportcompany_id, order_id, updated_by, created_at FROM packinglist
ORDER BY id LIMIT $1
OFFSET $2
`

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

func (q *Queries) ListPackLists(ctx context.Context, arg ListPackListsParams) ([]Packinglist, error) {
	rows, err := q.db.QueryContext(ctx, listPackLists, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Packinglist{}
	for rows.Next() {
		var i Packinglist
		if err := rows.Scan(
			&i.ID,
			&i.Status,
			&i.UserID,
			&i.ExportcompanyID,
			&i.OrderID,
			&i.UpdatedBy,
			&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 listPackingListsBatch = `-- name: ListPackingListsBatch :many
SELECT id, batchno, packinglist_id, order_id, receptionform_id, traceability_code, product_id, totalboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, created_at, status FROM packinglist_batch
ORDER BY id LIMIT $1
OFFSET $2
`

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

func (q *Queries) ListPackingListsBatch(ctx context.Context, arg ListPackingListsBatchParams) ([]PackinglistBatch, error) {
	rows, err := q.db.QueryContext(ctx, listPackingListsBatch, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []PackinglistBatch{}
	for rows.Next() {
		var i PackinglistBatch
		if err := rows.Scan(
			&i.ID,
			&i.Batchno,
			&i.PackinglistID,
			&i.OrderID,
			&i.ReceptionformID,
			&i.TraceabilityCode,
			&i.ProductID,
			&i.Totalboxes,
			&i.Boxweight,
			&i.Productnetweight,
			&i.Totalproductnetweight,
			&i.Totalproductgrossweight,
			&i.CreatedAt,
			&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 listPackingListsOthers = `-- name: ListPackingListsOthers :many
SELECT id, packinglist_id, productname, totalboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, created_at, status FROM packinglist_others
ORDER BY packinglist_id LIMIT $1
OFFSET $2
`

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

func (q *Queries) ListPackingListsOthers(ctx context.Context, arg ListPackingListsOthersParams) ([]PackinglistOther, error) {
	rows, err := q.db.QueryContext(ctx, listPackingListsOthers, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []PackinglistOther{}
	for rows.Next() {
		var i PackinglistOther
		if err := rows.Scan(
			&i.ID,
			&i.PackinglistID,
			&i.Productname,
			&i.Totalboxes,
			&i.Boxweight,
			&i.Productnetweight,
			&i.Totalproductnetweight,
			&i.Totalproductgrossweight,
			&i.CreatedAt,
			&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 listPackingListsProducts = `-- name: ListPackingListsProducts :many
SELECT id, packinglist_id, batchno, receptionform_id, order_id, traceability_code, product_id, boxweight, totalboxes, productnetweight, totalproductnetweight, totalproductgrossweight, created_at, status FROM packinglist_products
ORDER BY id LIMIT $1
OFFSET $2
`

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

func (q *Queries) ListPackingListsProducts(ctx context.Context, arg ListPackingListsProductsParams) ([]PackinglistProduct, error) {
	rows, err := q.db.QueryContext(ctx, listPackingListsProducts, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []PackinglistProduct{}
	for rows.Next() {
		var i PackinglistProduct
		if err := rows.Scan(
			&i.ID,
			&i.PackinglistID,
			&i.Batchno,
			&i.ReceptionformID,
			&i.OrderID,
			&i.TraceabilityCode,
			&i.ProductID,
			&i.Boxweight,
			&i.Totalboxes,
			&i.Productnetweight,
			&i.Totalproductnetweight,
			&i.Totalproductgrossweight,
			&i.CreatedAt,
			&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 matchOrderIDTraceability = `-- name: MatchOrderIDTraceability :one
SELECT EXISTS (
    SELECT 1 FROM packinglist_products
    WHERE packinglist_products.order_id = $1
    AND   packinglist_products.traceability_code = $2
    AND   packinglist_products.product_id = $3
)
`

type MatchOrderIDTraceabilityParams struct {
	OrderID          int32  `json:"order_id"`
	TraceabilityCode string `json:"traceability_code"`
	ProductID        int32  `json:"product_id"`
}

func (q *Queries) MatchOrderIDTraceability(ctx context.Context, arg MatchOrderIDTraceabilityParams) (bool, error) {
	row := q.db.QueryRowContext(ctx, matchOrderIDTraceability, arg.OrderID, arg.TraceabilityCode, arg.ProductID)
	var exists bool
	err := row.Scan(&exists)
	return exists, err
}

const packingListBatchDetails = `-- name: PackingListBatchDetails :one
SELECT packinglist_batch.order_id,packinglist_batch.packinglist_id pklist_id,
packinglist_batch.traceability_code,packinglist_batch.receptionform_id,
packinglist_batch.product_id crop_id,clients.companyname,crops.cropname,
totalboxes,users.fullname,countries.countryname, users.id puser_id,
boxweight,productnetweight,totalproductnetweight,totalproductgrossweight,
packinglist_batch.id plpid FROM packinglist_batch
JOIN  packinglist on   packinglist.id      =  packinglist_batch.packinglist_id
JOIN  users       on   users.id            =  packinglist.user_id
JOIN  crops       on   crops.id            =  packinglist_batch.product_id
JOIN  orders      on   orders.id           =  packinglist_batch.order_id
JOIN  clients     on   clients.id          =  orders.client_id
JOIN  countries   on   countries.id        =  clients.country_id
WHERE packinglist_batch.id = $1
`

type PackingListBatchDetailsRow struct {
	OrderID                 int32           `json:"order_id"`
	PklistID                int32           `json:"pklist_id"`
	TraceabilityCode        string          `json:"traceability_code"`
	ReceptionformID         int32           `json:"receptionform_id"`
	CropID                  int32           `json:"crop_id"`
	Companyname             string          `json:"companyname"`
	Cropname                string          `json:"cropname"`
	Totalboxes              sql.NullInt32   `json:"totalboxes"`
	Fullname                string          `json:"fullname"`
	Countryname             string          `json:"countryname"`
	PuserID                 int64           `json:"puser_id"`
	Boxweight               sql.NullFloat64 `json:"boxweight"`
	Productnetweight        sql.NullFloat64 `json:"productnetweight"`
	Totalproductnetweight   sql.NullFloat64 `json:"totalproductnetweight"`
	Totalproductgrossweight sql.NullFloat64 `json:"totalproductgrossweight"`
	Plpid                   int64           `json:"plpid"`
}

func (q *Queries) PackingListBatchDetails(ctx context.Context, id int64) (PackingListBatchDetailsRow, error) {
	row := q.db.QueryRowContext(ctx, packingListBatchDetails, id)
	var i PackingListBatchDetailsRow
	err := row.Scan(
		&i.OrderID,
		&i.PklistID,
		&i.TraceabilityCode,
		&i.ReceptionformID,
		&i.CropID,
		&i.Companyname,
		&i.Cropname,
		&i.Totalboxes,
		&i.Fullname,
		&i.Countryname,
		&i.PuserID,
		&i.Boxweight,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.Plpid,
	)
	return i, err
}

const packingListOrderSum = `-- name: PackingListOrderSum :one
SELECT COUNT(id) FROM  packinglist
WHERE packinglist.order_id = $1
AND   packinglist.status IN ('Pending','Resorting','AwaitingResort')
`

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

const packingListOtherDetails = `-- name: PackingListOtherDetails :many
SELECT productname product_name,totalboxes,boxweight,status,
productnetweight,totalproductnetweight,totalproductgrossweight,id FROM packinglist_others
WHERE packinglist_others.packinglist_id = $1
`

type PackingListOtherDetailsRow struct {
	ProductName             string         `json:"product_name"`
	Totalboxes              int32          `json:"totalboxes"`
	Boxweight               float64        `json:"boxweight"`
	Status                  sql.NullString `json:"status"`
	Productnetweight        float64        `json:"productnetweight"`
	Totalproductnetweight   float64        `json:"totalproductnetweight"`
	Totalproductgrossweight float64        `json:"totalproductgrossweight"`
	ID                      int64          `json:"id"`
}

func (q *Queries) PackingListOtherDetails(ctx context.Context, packinglistID int32) ([]PackingListOtherDetailsRow, error) {
	rows, err := q.db.QueryContext(ctx, packingListOtherDetails, packinglistID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []PackingListOtherDetailsRow{}
	for rows.Next() {
		var i PackingListOtherDetailsRow
		if err := rows.Scan(
			&i.ProductName,
			&i.Totalboxes,
			&i.Boxweight,
			&i.Status,
			&i.Productnetweight,
			&i.Totalproductnetweight,
			&i.Totalproductgrossweight,
			&i.ID,
		); 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 packingListOthersPerConsignment = `-- name: PackingListOthersPerConsignment :many
SELECT productname product_name,packinglist_others.totalboxes,packinglist_others.boxweight,packinglist_others.status,
packinglist_others.productnetweight,packinglist_others.totalproductnetweight,packinglist_others.totalproductgrossweight,
packinglist_others.id FROM  packinglist_others
JOIN  packinglist on packinglist.id  = packinglist_others.packinglist_id
JOIN  orders      on orders.id       = packinglist.order_id
WHERE orders.consignment_no = $1
`

type PackingListOthersPerConsignmentRow struct {
	ProductName             string         `json:"product_name"`
	Totalboxes              int32          `json:"totalboxes"`
	Boxweight               float64        `json:"boxweight"`
	Status                  sql.NullString `json:"status"`
	Productnetweight        float64        `json:"productnetweight"`
	Totalproductnetweight   float64        `json:"totalproductnetweight"`
	Totalproductgrossweight float64        `json:"totalproductgrossweight"`
	ID                      int64          `json:"id"`
}

func (q *Queries) PackingListOthersPerConsignment(ctx context.Context, consignmentNo sql.NullString) ([]PackingListOthersPerConsignmentRow, error) {
	rows, err := q.db.QueryContext(ctx, packingListOthersPerConsignment, consignmentNo)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []PackingListOthersPerConsignmentRow{}
	for rows.Next() {
		var i PackingListOthersPerConsignmentRow
		if err := rows.Scan(
			&i.ProductName,
			&i.Totalboxes,
			&i.Boxweight,
			&i.Status,
			&i.Productnetweight,
			&i.Totalproductnetweight,
			&i.Totalproductgrossweight,
			&i.ID,
		); 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 packingListPerConsignment = `-- name: PackingListPerConsignment :many
SELECT packinglist_products.order_id,packinglist_products.packinglist_id pklist_id,packinglist_products.traceability_code,
packinglist_products.product_id crop_id,clients.companyname,crops.cropname,totalboxes,users.fullname,users.id puser_id,boxweight,
productnetweight,totalproductnetweight,totalproductgrossweight,packinglist_products.id row_id  FROM packinglist_products
JOIN  packinglist on    packinglist.id     =  packinglist_products.packinglist_id
JOIN  users       on    users.id           =  packinglist.user_id
JOIN  crops       on    crops.id           =  packinglist_products.product_id
JOIN  orders      on    orders.id          =  packinglist_products.order_id
JOIN  clients     on    clients.id         =  orders.client_id
WHERE orders.consignment_no = $1
`

type PackingListPerConsignmentRow struct {
	OrderID                 int32           `json:"order_id"`
	PklistID                int32           `json:"pklist_id"`
	TraceabilityCode        string          `json:"traceability_code"`
	CropID                  int32           `json:"crop_id"`
	Companyname             string          `json:"companyname"`
	Cropname                string          `json:"cropname"`
	Totalboxes              sql.NullInt32   `json:"totalboxes"`
	Fullname                string          `json:"fullname"`
	PuserID                 int64           `json:"puser_id"`
	Boxweight               sql.NullFloat64 `json:"boxweight"`
	Productnetweight        sql.NullFloat64 `json:"productnetweight"`
	Totalproductnetweight   sql.NullFloat64 `json:"totalproductnetweight"`
	Totalproductgrossweight sql.NullFloat64 `json:"totalproductgrossweight"`
	RowID                   int64           `json:"row_id"`
}

func (q *Queries) PackingListPerConsignment(ctx context.Context, consignmentNo sql.NullString) ([]PackingListPerConsignmentRow, error) {
	rows, err := q.db.QueryContext(ctx, packingListPerConsignment, consignmentNo)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []PackingListPerConsignmentRow{}
	for rows.Next() {
		var i PackingListPerConsignmentRow
		if err := rows.Scan(
			&i.OrderID,
			&i.PklistID,
			&i.TraceabilityCode,
			&i.CropID,
			&i.Companyname,
			&i.Cropname,
			&i.Totalboxes,
			&i.Fullname,
			&i.PuserID,
			&i.Boxweight,
			&i.Productnetweight,
			&i.Totalproductnetweight,
			&i.Totalproductgrossweight,
			&i.RowID,
		); 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 packingListProductDetails = `-- name: PackingListProductDetails :many
SELECT packinglist_products.order_id,packinglist_products.packinglist_id pklist_id,packinglist_products.receptionform_id,
packinglist_products.traceability_code,packinglist_products.product_id crop_id,clients.companyname,crops.cropname,crops.crophscode,crops.riskstatus,
totalboxes,users.fullname,users.id puser_id, packinglist.status,packinglist_products.status as packinglist_product_status,
packinglist_products.boxweight,packinglist_products.productnetweight,packinglist_products.totalproductgrossweight,packinglist_products.totalproductnetweight, packinglist_products.id plpid,
countries.countryname,packinglist.exportcompany_id FROM packinglist_products
JOIN  packinglist on   packinglist.id     =  packinglist_products.packinglist_id
JOIN  users       on   users.id           =  packinglist.user_id
JOIN  crops       on   crops.id           =  packinglist_products.product_id
JOIN  orders      on   orders.id          =  packinglist_products.order_id
JOIN  clients     on   clients.id         =  orders.client_id
JOIN  countries   on   countries.id       = clients.country_id
WHERE packinglist_products.packinglist_id = $1
`

type PackingListProductDetailsRow struct {
	OrderID                  int32           `json:"order_id"`
	PklistID                 int32           `json:"pklist_id"`
	ReceptionformID          int32           `json:"receptionform_id"`
	TraceabilityCode         string          `json:"traceability_code"`
	CropID                   int32           `json:"crop_id"`
	Companyname              string          `json:"companyname"`
	Cropname                 string          `json:"cropname"`
	Crophscode               string          `json:"crophscode"`
	Riskstatus               string          `json:"riskstatus"`
	Totalboxes               sql.NullInt32   `json:"totalboxes"`
	Fullname                 string          `json:"fullname"`
	PuserID                  int64           `json:"puser_id"`
	Status                   string          `json:"status"`
	PackinglistProductStatus sql.NullString  `json:"packinglist_product_status"`
	Boxweight                sql.NullFloat64 `json:"boxweight"`
	Productnetweight         sql.NullFloat64 `json:"productnetweight"`
	Totalproductgrossweight  sql.NullFloat64 `json:"totalproductgrossweight"`
	Totalproductnetweight    sql.NullFloat64 `json:"totalproductnetweight"`
	Plpid                    int64           `json:"plpid"`
	Countryname              string          `json:"countryname"`
	ExportcompanyID          int32           `json:"exportcompany_id"`
}

func (q *Queries) PackingListProductDetails(ctx context.Context, packinglistID int32) ([]PackingListProductDetailsRow, error) {
	rows, err := q.db.QueryContext(ctx, packingListProductDetails, packinglistID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []PackingListProductDetailsRow{}
	for rows.Next() {
		var i PackingListProductDetailsRow
		if err := rows.Scan(
			&i.OrderID,
			&i.PklistID,
			&i.ReceptionformID,
			&i.TraceabilityCode,
			&i.CropID,
			&i.Companyname,
			&i.Cropname,
			&i.Crophscode,
			&i.Riskstatus,
			&i.Totalboxes,
			&i.Fullname,
			&i.PuserID,
			&i.Status,
			&i.PackinglistProductStatus,
			&i.Boxweight,
			&i.Productnetweight,
			&i.Totalproductgrossweight,
			&i.Totalproductnetweight,
			&i.Plpid,
			&i.Countryname,
			&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 packingListProductsPerConsignment = `-- name: PackingListProductsPerConsignment :many
SELECT packinglist_products.packinglist_id,
packinglist_products.order_id,packinglist_products.receptionform_id,
packinglist_products.batchno,packinglist_products.traceability_code,
packinglist_products.product_id,packinglist_products.totalboxes,
packinglist_products.boxweight,packinglist_products.productnetweight,
packinglist_products.totalproductnetweight,crops.cropname as product,
packinglist_products.totalproductgrossweight FROM  packinglist_products
JOIN  packinglist on packinglist.id  = packinglist_products.packinglist_id
JOIN  orders      on orders.id       = packinglist.order_id
JOIN  crops       on crops.id        = packinglist_products.product_id
WHERE orders.consignment_no = $1
`

type PackingListProductsPerConsignmentRow struct {
	PackinglistID           int32           `json:"packinglist_id"`
	OrderID                 int32           `json:"order_id"`
	ReceptionformID         int32           `json:"receptionform_id"`
	Batchno                 sql.NullString  `json:"batchno"`
	TraceabilityCode        string          `json:"traceability_code"`
	ProductID               int32           `json:"product_id"`
	Totalboxes              sql.NullInt32   `json:"totalboxes"`
	Boxweight               sql.NullFloat64 `json:"boxweight"`
	Productnetweight        sql.NullFloat64 `json:"productnetweight"`
	Totalproductnetweight   sql.NullFloat64 `json:"totalproductnetweight"`
	Product                 string          `json:"product"`
	Totalproductgrossweight sql.NullFloat64 `json:"totalproductgrossweight"`
}

func (q *Queries) PackingListProductsPerConsignment(ctx context.Context, consignmentNo sql.NullString) ([]PackingListProductsPerConsignmentRow, error) {
	rows, err := q.db.QueryContext(ctx, packingListProductsPerConsignment, consignmentNo)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []PackingListProductsPerConsignmentRow{}
	for rows.Next() {
		var i PackingListProductsPerConsignmentRow
		if err := rows.Scan(
			&i.PackinglistID,
			&i.OrderID,
			&i.ReceptionformID,
			&i.Batchno,
			&i.TraceabilityCode,
			&i.ProductID,
			&i.Totalboxes,
			&i.Boxweight,
			&i.Productnetweight,
			&i.Totalproductnetweight,
			&i.Product,
			&i.Totalproductgrossweight,
		); 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 packingListSum = `-- name: PackingListSum :one
SELECT COUNT(id) FROM  packinglist
WHERE packinglist.exportcompany_id = $1
AND   packinglist.status IN ('Pending','Resorting','AwaitingResort')
`

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

const packingListWithResort = `-- name: PackingListWithResort :one
SELECT EXISTS(
SELECT 1 FROM packinglist_products
   WHERE packinglist_products.status = $1
   AND   packinglist_products.id = $2
)
`

type PackingListWithResortParams struct {
	Status sql.NullString `json:"status"`
	ID     int64          `json:"id"`
}

func (q *Queries) PackingListWithResort(ctx context.Context, arg PackingListWithResortParams) (bool, error) {
	row := q.db.QueryRowContext(ctx, packingListWithResort, arg.Status, arg.ID)
	var exists bool
	err := row.Scan(&exists)
	return exists, err
}

const packinglistPerOrder = `-- name: PackinglistPerOrder :one
SELECT packinglist_products.order_id,packinglist_products.packinglist_id pklist_id,packinglist_products.traceability_code,
packinglist_products.product_id crop_id,clients.companyname,crops.cropname,crops.crophscode,crops.riskstatus,packinglist_products.receptionform_id
totalboxes,users.fullname,users.id puser_id,packinglist.status,countries.countryname as destination,
packinglist_products.boxweight,packinglist_products.productnetweight,packinglist_products.totalproductgrossweight,packinglist_products.totalproductnetweight, packinglist_products.id plpid FROM packinglist_products
JOIN  packinglist on   packinglist.id     =  packinglist_products.packinglist_id
JOIN  users       on   users.id           =  packinglist.user_id
JOIN  crops       on   crops.id           =  packinglist_products.product_id
JOIN  orders      on   orders.id          =  packinglist_products.order_id
JOIN  clients     on   clients.id         =  orders.client_id
JOIN  countries   on   countries.id       =  clients.country_id
WHERE packinglist_products.order_id = $1  LIMIT 1
`

type PackinglistPerOrderRow struct {
	OrderID                 int32           `json:"order_id"`
	PklistID                int32           `json:"pklist_id"`
	TraceabilityCode        string          `json:"traceability_code"`
	CropID                  int32           `json:"crop_id"`
	Companyname             string          `json:"companyname"`
	Cropname                string          `json:"cropname"`
	Crophscode              string          `json:"crophscode"`
	Riskstatus              string          `json:"riskstatus"`
	Totalboxes              int32           `json:"totalboxes"`
	Fullname                string          `json:"fullname"`
	PuserID                 int64           `json:"puser_id"`
	Status                  string          `json:"status"`
	Destination             string          `json:"destination"`
	Boxweight               sql.NullFloat64 `json:"boxweight"`
	Productnetweight        sql.NullFloat64 `json:"productnetweight"`
	Totalproductgrossweight sql.NullFloat64 `json:"totalproductgrossweight"`
	Totalproductnetweight   sql.NullFloat64 `json:"totalproductnetweight"`
	Plpid                   int64           `json:"plpid"`
}

func (q *Queries) PackinglistPerOrder(ctx context.Context, orderID int32) (PackinglistPerOrderRow, error) {
	row := q.db.QueryRowContext(ctx, packinglistPerOrder, orderID)
	var i PackinglistPerOrderRow
	err := row.Scan(
		&i.OrderID,
		&i.PklistID,
		&i.TraceabilityCode,
		&i.CropID,
		&i.Companyname,
		&i.Cropname,
		&i.Crophscode,
		&i.Riskstatus,
		&i.Totalboxes,
		&i.Fullname,
		&i.PuserID,
		&i.Status,
		&i.Destination,
		&i.Boxweight,
		&i.Productnetweight,
		&i.Totalproductgrossweight,
		&i.Totalproductnetweight,
		&i.Plpid,
	)
	return i, err
}

const returnBatchPackingListByBatchNo = `-- name: ReturnBatchPackingListByBatchNo :many
SELECT packinglist_batch.order_id,packinglist_batch.packinglist_id pklist_id,packinglist_batch.traceability_code,
packinglist_batch.product_id crop_id,clients.companyname,crops.cropname,packinglist_batch.receptionform_id,
totalboxes,users.fullname,countries.countryname, users.id puser_id,
boxweight,productnetweight,totalproductnetweight,totalproductgrossweight,
packinglist_batch.id plpid, packinglist_batch.status FROM packinglist_batch
JOIN  packinglist on   packinglist.id      =  packinglist_batch.packinglist_id
JOIN  users       on   users.id            =  packinglist.user_id
JOIN  crops       on   crops.id            =  packinglist_batch.product_id
JOIN  orders      on   orders.id           =  packinglist_batch.order_id
JOIN  clients     on   clients.id          =  orders.client_id
JOIN  countries   on   countries.id        =  clients.country_id
WHERE packinglist_batch.batchno = $1
`

type ReturnBatchPackingListByBatchNoRow struct {
	OrderID                 int32           `json:"order_id"`
	PklistID                int32           `json:"pklist_id"`
	TraceabilityCode        string          `json:"traceability_code"`
	CropID                  int32           `json:"crop_id"`
	Companyname             string          `json:"companyname"`
	Cropname                string          `json:"cropname"`
	ReceptionformID         int32           `json:"receptionform_id"`
	Totalboxes              sql.NullInt32   `json:"totalboxes"`
	Fullname                string          `json:"fullname"`
	Countryname             string          `json:"countryname"`
	PuserID                 int64           `json:"puser_id"`
	Boxweight               sql.NullFloat64 `json:"boxweight"`
	Productnetweight        sql.NullFloat64 `json:"productnetweight"`
	Totalproductnetweight   sql.NullFloat64 `json:"totalproductnetweight"`
	Totalproductgrossweight sql.NullFloat64 `json:"totalproductgrossweight"`
	Plpid                   int64           `json:"plpid"`
	Status                  sql.NullString  `json:"status"`
}

func (q *Queries) ReturnBatchPackingListByBatchNo(ctx context.Context, batchno string) ([]ReturnBatchPackingListByBatchNoRow, error) {
	rows, err := q.db.QueryContext(ctx, returnBatchPackingListByBatchNo, batchno)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ReturnBatchPackingListByBatchNoRow{}
	for rows.Next() {
		var i ReturnBatchPackingListByBatchNoRow
		if err := rows.Scan(
			&i.OrderID,
			&i.PklistID,
			&i.TraceabilityCode,
			&i.CropID,
			&i.Companyname,
			&i.Cropname,
			&i.ReceptionformID,
			&i.Totalboxes,
			&i.Fullname,
			&i.Countryname,
			&i.PuserID,
			&i.Boxweight,
			&i.Productnetweight,
			&i.Totalproductnetweight,
			&i.Totalproductgrossweight,
			&i.Plpid,
			&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 returnNetWeight = `-- name: ReturnNetWeight :one
SELECT totalproductnetweight,
productnetweight,totalproductgrossweight
from packinglist_products
WHERE  packinglist_id = $3
AND    order_id       = $2
AND    product_id     = $4
AND    boxweight      = $5
AND    traceability_code = $1
`

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

type ReturnNetWeightRow struct {
	Totalproductnetweight   sql.NullFloat64 `json:"totalproductnetweight"`
	Productnetweight        sql.NullFloat64 `json:"productnetweight"`
	Totalproductgrossweight sql.NullFloat64 `json:"totalproductgrossweight"`
}

func (q *Queries) ReturnNetWeight(ctx context.Context, arg ReturnNetWeightParams) (ReturnNetWeightRow, error) {
	row := q.db.QueryRowContext(ctx, returnNetWeight,
		arg.TraceabilityCode,
		arg.OrderID,
		arg.PackinglistID,
		arg.ProductID,
		arg.Boxweight,
	)
	var i ReturnNetWeightRow
	err := row.Scan(&i.Totalproductnetweight, &i.Productnetweight, &i.Totalproductgrossweight)
	return i, err
}

const returnPackingListByOrderID = `-- name: ReturnPackingListByOrderID :one
SELECT id FROM packinglist where order_id = $1
`

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

const returnProductsOnPackinglist = `-- name: ReturnProductsOnPackinglist :many
SELECT packinglist_products.packinglist_id,
packinglist_products.order_id,packinglist_products.receptionform_id,
packinglist_products.batchno,packinglist_products.traceability_code,
packinglist_products.product_id,packinglist_products.totalboxes,
packinglist_products.boxweight,packinglist_products.productnetweight,
packinglist_products.totalproductnetweight,
packinglist_products.totalproductgrossweight
FROM  packinglist_products
WHERE packinglist_products.packinglist_id = $1
`

type ReturnProductsOnPackinglistRow struct {
	PackinglistID           int32           `json:"packinglist_id"`
	OrderID                 int32           `json:"order_id"`
	ReceptionformID         int32           `json:"receptionform_id"`
	Batchno                 sql.NullString  `json:"batchno"`
	TraceabilityCode        string          `json:"traceability_code"`
	ProductID               int32           `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"`
}

func (q *Queries) ReturnProductsOnPackinglist(ctx context.Context, packinglistID int32) ([]ReturnProductsOnPackinglistRow, error) {
	rows, err := q.db.QueryContext(ctx, returnProductsOnPackinglist, packinglistID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ReturnProductsOnPackinglistRow{}
	for rows.Next() {
		var i ReturnProductsOnPackinglistRow
		if err := rows.Scan(
			&i.PackinglistID,
			&i.OrderID,
			&i.ReceptionformID,
			&i.Batchno,
			&i.TraceabilityCode,
			&i.ProductID,
			&i.Totalboxes,
			&i.Boxweight,
			&i.Productnetweight,
			&i.Totalproductnetweight,
			&i.Totalproductgrossweight,
		); 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 returnReceptionIDPackingList = `-- name: ReturnReceptionIDPackingList :one
SELECT receptionform.id reception_id, receptionform.traceability_code, receptionform.order_id FROM packinglist
LEFT JOIN receptionform on receptionform.id = packinglist.reception_id
WHERE packinglist.id = $1
`

type ReturnReceptionIDPackingListRow struct {
	ReceptionID      sql.NullInt64  `json:"reception_id"`
	TraceabilityCode sql.NullString `json:"traceability_code"`
	OrderID          sql.NullInt32  `json:"order_id"`
}

func (q *Queries) ReturnReceptionIDPackingList(ctx context.Context, id int64) (ReturnReceptionIDPackingListRow, error) {
	row := q.db.QueryRowContext(ctx, returnReceptionIDPackingList, id)
	var i ReturnReceptionIDPackingListRow
	err := row.Scan(&i.ReceptionID, &i.TraceabilityCode, &i.OrderID)
	return i, err
}

const selectPackingListTotalBoxes = `-- name: SelectPackingListTotalBoxes :one
SELECT totalboxes from packinglist_products
WHERE  packinglist_id = $3
AND    order_id       = $2
AND    product_id     = $4
AND    boxweight      = $5
AND    traceability_code = $1
`

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

func (q *Queries) SelectPackingListTotalBoxes(ctx context.Context, arg SelectPackingListTotalBoxesParams) (sql.NullInt32, error) {
	row := q.db.QueryRowContext(ctx, selectPackingListTotalBoxes,
		arg.TraceabilityCode,
		arg.OrderID,
		arg.PackinglistID,
		arg.ProductID,
		arg.Boxweight,
	)
	var totalboxes sql.NullInt32
	err := row.Scan(&totalboxes)
	return totalboxes, err
}

const selectPackingListWeight = `-- name: SelectPackingListWeight :one
SELECT totalproductnetweight from packinglist_products
WHERE  packinglist_id = $3
AND    order_id       = $2
AND    product_id     = $4
AND    boxweight      = $5
AND    traceability_code = $1
`

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

func (q *Queries) SelectPackingListWeight(ctx context.Context, arg SelectPackingListWeightParams) (sql.NullFloat64, error) {
	row := q.db.QueryRowContext(ctx, selectPackingListWeight,
		arg.TraceabilityCode,
		arg.OrderID,
		arg.PackinglistID,
		arg.ProductID,
		arg.Boxweight,
	)
	var totalproductnetweight sql.NullFloat64
	err := row.Scan(&totalproductnetweight)
	return totalproductnetweight, err
}

const updatePackList = `-- name: UpdatePackList :one
UPDATE packinglist
  set
    status   = $2
WHERE id = $1
RETURNING id, status, user_id, exportcompany_id, order_id, updated_by, created_at
`

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

func (q *Queries) UpdatePackList(ctx context.Context, arg UpdatePackListParams) (Packinglist, error) {
	row := q.db.QueryRowContext(ctx, updatePackList, arg.ID, arg.Status)
	var i Packinglist
	err := row.Scan(
		&i.ID,
		&i.Status,
		&i.UserID,
		&i.ExportcompanyID,
		&i.OrderID,
		&i.UpdatedBy,
		&i.CreatedAt,
	)
	return i, err
}

const updatePackingBatchStatus = `-- name: UpdatePackingBatchStatus :one
UPDATE  packinglist_batch
   set
      status  = $2
WHERE id = $1
RETURNING id, batchno, packinglist_id, order_id, receptionform_id, traceability_code, product_id, totalboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, created_at, status
`

type UpdatePackingBatchStatusParams struct {
	ID     int64          `json:"id"`
	Status sql.NullString `json:"status"`
}

func (q *Queries) UpdatePackingBatchStatus(ctx context.Context, arg UpdatePackingBatchStatusParams) (PackinglistBatch, error) {
	row := q.db.QueryRowContext(ctx, updatePackingBatchStatus, arg.ID, arg.Status)
	var i PackinglistBatch
	err := row.Scan(
		&i.ID,
		&i.Batchno,
		&i.PackinglistID,
		&i.OrderID,
		&i.ReceptionformID,
		&i.TraceabilityCode,
		&i.ProductID,
		&i.Totalboxes,
		&i.Boxweight,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.CreatedAt,
		&i.Status,
	)
	return i, err
}

const updatePackingListBatch = `-- name: UpdatePackingListBatch :one
UPDATE packinglist_batch
  set
      packinglist_id          = $2,
      order_id                = $3,
      traceability_code       = $4,
      product_id              = $5,
      totalboxes              = $6,
      batchno                 = $7,
      boxweight               = $8,
      productnetweight        = $9,
      totalproductnetweight   = $10,
      totalproductgrossweight = $11
WHERE id = $1
RETURNING id, batchno, packinglist_id, order_id, receptionform_id, traceability_code, product_id, totalboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, created_at, status
`

type UpdatePackingListBatchParams struct {
	ID                      int64           `json:"id"`
	PackinglistID           int32           `json:"packinglist_id"`
	OrderID                 int32           `json:"order_id"`
	TraceabilityCode        string          `json:"traceability_code"`
	ProductID               int32           `json:"product_id"`
	Totalboxes              sql.NullInt32   `json:"totalboxes"`
	Batchno                 string          `json:"batchno"`
	Boxweight               sql.NullFloat64 `json:"boxweight"`
	Productnetweight        sql.NullFloat64 `json:"productnetweight"`
	Totalproductnetweight   sql.NullFloat64 `json:"totalproductnetweight"`
	Totalproductgrossweight sql.NullFloat64 `json:"totalproductgrossweight"`
}

func (q *Queries) UpdatePackingListBatch(ctx context.Context, arg UpdatePackingListBatchParams) (PackinglistBatch, error) {
	row := q.db.QueryRowContext(ctx, updatePackingListBatch,
		arg.ID,
		arg.PackinglistID,
		arg.OrderID,
		arg.TraceabilityCode,
		arg.ProductID,
		arg.Totalboxes,
		arg.Batchno,
		arg.Boxweight,
		arg.Productnetweight,
		arg.Totalproductnetweight,
		arg.Totalproductgrossweight,
	)
	var i PackinglistBatch
	err := row.Scan(
		&i.ID,
		&i.Batchno,
		&i.PackinglistID,
		&i.OrderID,
		&i.ReceptionformID,
		&i.TraceabilityCode,
		&i.ProductID,
		&i.Totalboxes,
		&i.Boxweight,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.CreatedAt,
		&i.Status,
	)
	return i, err
}

const updatePackingListBatchDetails = `-- name: UpdatePackingListBatchDetails :one
UPDATE  packinglist_batch
   set
      totalboxes               = $2,
      boxweight                = $3,
      productnetweight         = $4,
      totalproductnetweight    = $5,
      totalproductgrossweight  = $6,
      status                   = $7
WHERE id = $1
RETURNING id, batchno, packinglist_id, order_id, receptionform_id, traceability_code, product_id, totalboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, created_at, status
`

type UpdatePackingListBatchDetailsParams struct {
	ID                      int64           `json:"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"`
	Status                  sql.NullString  `json:"status"`
}

func (q *Queries) UpdatePackingListBatchDetails(ctx context.Context, arg UpdatePackingListBatchDetailsParams) (PackinglistBatch, error) {
	row := q.db.QueryRowContext(ctx, updatePackingListBatchDetails,
		arg.ID,
		arg.Totalboxes,
		arg.Boxweight,
		arg.Productnetweight,
		arg.Totalproductnetweight,
		arg.Totalproductgrossweight,
		arg.Status,
	)
	var i PackinglistBatch
	err := row.Scan(
		&i.ID,
		&i.Batchno,
		&i.PackinglistID,
		&i.OrderID,
		&i.ReceptionformID,
		&i.TraceabilityCode,
		&i.ProductID,
		&i.Totalboxes,
		&i.Boxweight,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.CreatedAt,
		&i.Status,
	)
	return i, err
}

const updatePackingListOthers = `-- name: UpdatePackingListOthers :one
UPDATE packinglist_others
  set
     packinglist_id          = $2,
     productname             = $3,
     totalboxes              = $4,
     boxweight               = $5,
     productnetweight        = $6,
     totalproductnetweight   = $7,
     totalproductgrossweight = $8
WHERE id = $1
RETURNING id, packinglist_id, productname, totalboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, created_at, status
`

type UpdatePackingListOthersParams struct {
	ID                      int64   `json:"id"`
	PackinglistID           int32   `json:"packinglist_id"`
	Productname             string  `json:"productname"`
	Totalboxes              int32   `json:"totalboxes"`
	Boxweight               float64 `json:"boxweight"`
	Productnetweight        float64 `json:"productnetweight"`
	Totalproductnetweight   float64 `json:"totalproductnetweight"`
	Totalproductgrossweight float64 `json:"totalproductgrossweight"`
}

func (q *Queries) UpdatePackingListOthers(ctx context.Context, arg UpdatePackingListOthersParams) (PackinglistOther, error) {
	row := q.db.QueryRowContext(ctx, updatePackingListOthers,
		arg.ID,
		arg.PackinglistID,
		arg.Productname,
		arg.Totalboxes,
		arg.Boxweight,
		arg.Productnetweight,
		arg.Totalproductnetweight,
		arg.Totalproductgrossweight,
	)
	var i PackinglistOther
	err := row.Scan(
		&i.ID,
		&i.PackinglistID,
		&i.Productname,
		&i.Totalboxes,
		&i.Boxweight,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.CreatedAt,
		&i.Status,
	)
	return i, err
}

const updatePackingListProducts = `-- name: UpdatePackingListProducts :one
UPDATE packinglist_products
  set
      packinglist_id          =  $2,
      order_id                =  $3,
      traceability_code       =  $4,
      product_id              =  $5,
      totalboxes              =  $6,
      boxweight               =  $7,
      productnetweight        =  $8,
      totalproductnetweight   =  $9,
      totalproductgrossweight =  $10
WHERE id = $1
RETURNING id, packinglist_id, batchno, receptionform_id, order_id, traceability_code, product_id, boxweight, totalboxes, productnetweight, totalproductnetweight, totalproductgrossweight, created_at, status
`

type UpdatePackingListProductsParams struct {
	ID                      int64           `json:"id"`
	PackinglistID           int32           `json:"packinglist_id"`
	OrderID                 int32           `json:"order_id"`
	TraceabilityCode        string          `json:"traceability_code"`
	ProductID               int32           `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"`
}

func (q *Queries) UpdatePackingListProducts(ctx context.Context, arg UpdatePackingListProductsParams) (PackinglistProduct, error) {
	row := q.db.QueryRowContext(ctx, updatePackingListProducts,
		arg.ID,
		arg.PackinglistID,
		arg.OrderID,
		arg.TraceabilityCode,
		arg.ProductID,
		arg.Totalboxes,
		arg.Boxweight,
		arg.Productnetweight,
		arg.Totalproductnetweight,
		arg.Totalproductgrossweight,
	)
	var i PackinglistProduct
	err := row.Scan(
		&i.ID,
		&i.PackinglistID,
		&i.Batchno,
		&i.ReceptionformID,
		&i.OrderID,
		&i.TraceabilityCode,
		&i.ProductID,
		&i.Boxweight,
		&i.Totalboxes,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.CreatedAt,
		&i.Status,
	)
	return i, err
}

const updatePackingListProductsWithSameOrderAndTraceability = `-- name: UpdatePackingListProductsWithSameOrderAndTraceability :exec
UPDATE packinglist_products
  set
        totalboxes               = $4,
        boxweight                = $5,
        batchno                  = $6,
        totalproductnetweight    = $7,
        totalproductgrossweight  = $8,
        productnetweight         = $9
  WHERE packinglist_id = $1
  AND   product_id     = $2
  AND   order_id       = $3
`

type UpdatePackingListProductsWithSameOrderAndTraceabilityParams struct {
	PackinglistID           int32           `json:"packinglist_id"`
	ProductID               int32           `json:"product_id"`
	OrderID                 int32           `json:"order_id"`
	Totalboxes              sql.NullInt32   `json:"totalboxes"`
	Boxweight               sql.NullFloat64 `json:"boxweight"`
	Batchno                 sql.NullString  `json:"batchno"`
	Totalproductnetweight   sql.NullFloat64 `json:"totalproductnetweight"`
	Totalproductgrossweight sql.NullFloat64 `json:"totalproductgrossweight"`
	Productnetweight        sql.NullFloat64 `json:"productnetweight"`
}

func (q *Queries) UpdatePackingListProductsWithSameOrderAndTraceability(ctx context.Context, arg UpdatePackingListProductsWithSameOrderAndTraceabilityParams) error {
	_, err := q.db.ExecContext(ctx, updatePackingListProductsWithSameOrderAndTraceability,
		arg.PackinglistID,
		arg.ProductID,
		arg.OrderID,
		arg.Totalboxes,
		arg.Boxweight,
		arg.Batchno,
		arg.Totalproductnetweight,
		arg.Totalproductgrossweight,
		arg.Productnetweight,
	)
	return err
}

const updatePackingListTotalBoxes = `-- name: UpdatePackingListTotalBoxes :one
UPDATE packinglist_products
       SET
       totalboxes = $4,
       totalproductnetweight = $5,
       totalproductgrossweight = $8,
       productnetweight = $6
WHERE  packinglist_id = $3
AND    order_id       = $2
AND    traceability_code = $1
AND    boxweight         = $7
RETURNING id, packinglist_id, batchno, receptionform_id, order_id, traceability_code, product_id, boxweight, totalboxes, productnetweight, totalproductnetweight, totalproductgrossweight, created_at, status
`

type UpdatePackingListTotalBoxesParams struct {
	TraceabilityCode        string          `json:"traceability_code"`
	OrderID                 int32           `json:"order_id"`
	PackinglistID           int32           `json:"packinglist_id"`
	Totalboxes              sql.NullInt32   `json:"totalboxes"`
	Totalproductnetweight   sql.NullFloat64 `json:"totalproductnetweight"`
	Productnetweight        sql.NullFloat64 `json:"productnetweight"`
	Boxweight               sql.NullFloat64 `json:"boxweight"`
	Totalproductgrossweight sql.NullFloat64 `json:"totalproductgrossweight"`
}

func (q *Queries) UpdatePackingListTotalBoxes(ctx context.Context, arg UpdatePackingListTotalBoxesParams) (PackinglistProduct, error) {
	row := q.db.QueryRowContext(ctx, updatePackingListTotalBoxes,
		arg.TraceabilityCode,
		arg.OrderID,
		arg.PackinglistID,
		arg.Totalboxes,
		arg.Totalproductnetweight,
		arg.Productnetweight,
		arg.Boxweight,
		arg.Totalproductgrossweight,
	)
	var i PackinglistProduct
	err := row.Scan(
		&i.ID,
		&i.PackinglistID,
		&i.Batchno,
		&i.ReceptionformID,
		&i.OrderID,
		&i.TraceabilityCode,
		&i.ProductID,
		&i.Boxweight,
		&i.Totalboxes,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.CreatedAt,
		&i.Status,
	)
	return i, err
}

const updatePackingListWeight = `-- name: UpdatePackingListWeight :one
UPDATE packinglist_products
       SET
       totalproductnetweight = $4
WHERE  packinglist_id = $3
AND    order_id       = $2
AND    traceability_code = $1
RETURNING id, packinglist_id, batchno, receptionform_id, order_id, traceability_code, product_id, boxweight, totalboxes, productnetweight, totalproductnetweight, totalproductgrossweight, created_at, status
`

type UpdatePackingListWeightParams struct {
	TraceabilityCode      string          `json:"traceability_code"`
	OrderID               int32           `json:"order_id"`
	PackinglistID         int32           `json:"packinglist_id"`
	Totalproductnetweight sql.NullFloat64 `json:"totalproductnetweight"`
}

func (q *Queries) UpdatePackingListWeight(ctx context.Context, arg UpdatePackingListWeightParams) (PackinglistProduct, error) {
	row := q.db.QueryRowContext(ctx, updatePackingListWeight,
		arg.TraceabilityCode,
		arg.OrderID,
		arg.PackinglistID,
		arg.Totalproductnetweight,
	)
	var i PackinglistProduct
	err := row.Scan(
		&i.ID,
		&i.PackinglistID,
		&i.Batchno,
		&i.ReceptionformID,
		&i.OrderID,
		&i.TraceabilityCode,
		&i.ProductID,
		&i.Boxweight,
		&i.Totalboxes,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.CreatedAt,
		&i.Status,
	)
	return i, err
}

const updatePackingListWithResort = `-- name: UpdatePackingListWithResort :one
UPDATE packinglist_products
  set
    status   = $2
WHERE id = $1
RETURNING id, packinglist_id, batchno, receptionform_id, order_id, traceability_code, product_id, boxweight, totalboxes, productnetweight, totalproductnetweight, totalproductgrossweight, created_at, status
`

type UpdatePackingListWithResortParams struct {
	ID     int64          `json:"id"`
	Status sql.NullString `json:"status"`
}

func (q *Queries) UpdatePackingListWithResort(ctx context.Context, arg UpdatePackingListWithResortParams) (PackinglistProduct, error) {
	row := q.db.QueryRowContext(ctx, updatePackingListWithResort, arg.ID, arg.Status)
	var i PackinglistProduct
	err := row.Scan(
		&i.ID,
		&i.PackinglistID,
		&i.Batchno,
		&i.ReceptionformID,
		&i.OrderID,
		&i.TraceabilityCode,
		&i.ProductID,
		&i.Boxweight,
		&i.Totalboxes,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.CreatedAt,
		&i.Status,
	)
	return i, err
}

const updatePackinglistOthersProductStatusRow = `-- name: UpdatePackinglistOthersProductStatusRow :one
UPDATE packinglist_others
    SET
    status = $4
WHERE productname       = $1
AND   packinglist_id    = $2
AND   boxweight         = $3
RETURNING id, packinglist_id, productname, totalboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, created_at, status
`

type UpdatePackinglistOthersProductStatusRowParams struct {
	Productname   string         `json:"productname"`
	PackinglistID int32          `json:"packinglist_id"`
	Boxweight     float64        `json:"boxweight"`
	Status        sql.NullString `json:"status"`
}

func (q *Queries) UpdatePackinglistOthersProductStatusRow(ctx context.Context, arg UpdatePackinglistOthersProductStatusRowParams) (PackinglistOther, error) {
	row := q.db.QueryRowContext(ctx, updatePackinglistOthersProductStatusRow,
		arg.Productname,
		arg.PackinglistID,
		arg.Boxweight,
		arg.Status,
	)
	var i PackinglistOther
	err := row.Scan(
		&i.ID,
		&i.PackinglistID,
		&i.Productname,
		&i.Totalboxes,
		&i.Boxweight,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.CreatedAt,
		&i.Status,
	)
	return i, err
}

const updatePackinglistOthersStatusRow = `-- name: UpdatePackinglistOthersStatusRow :exec
UPDATE packinglist_others
    SET
      status            = $4
WHERE productname       = $1
AND   packinglist_id    = $2
AND   boxweight         = $3
RETURNING id, packinglist_id, productname, totalboxes, boxweight, productnetweight, totalproductnetweight, totalproductgrossweight, created_at, status
`

type UpdatePackinglistOthersStatusRowParams struct {
	Productname   string         `json:"productname"`
	PackinglistID int32          `json:"packinglist_id"`
	Boxweight     float64        `json:"boxweight"`
	Status        sql.NullString `json:"status"`
}

func (q *Queries) UpdatePackinglistOthersStatusRow(ctx context.Context, arg UpdatePackinglistOthersStatusRowParams) error {
	_, err := q.db.ExecContext(ctx, updatePackinglistOthersStatusRow,
		arg.Productname,
		arg.PackinglistID,
		arg.Boxweight,
		arg.Status,
	)
	return err
}

const updatePackinglistProductStatusRow = `-- name: UpdatePackinglistProductStatusRow :one
UPDATE packinglist_products
    SET
    status = $5
WHERE product_id        = $1
AND   packinglist_id    = $2
AND   order_id          = $3
AND   traceability_code = $4
AND   boxweight         = $6
RETURNING id, packinglist_id, batchno, receptionform_id, order_id, traceability_code, product_id, boxweight, totalboxes, productnetweight, totalproductnetweight, totalproductgrossweight, created_at, status
`

type UpdatePackinglistProductStatusRowParams struct {
	ProductID        int32           `json:"product_id"`
	PackinglistID    int32           `json:"packinglist_id"`
	OrderID          int32           `json:"order_id"`
	TraceabilityCode string          `json:"traceability_code"`
	Status           sql.NullString  `json:"status"`
	Boxweight        sql.NullFloat64 `json:"boxweight"`
}

func (q *Queries) UpdatePackinglistProductStatusRow(ctx context.Context, arg UpdatePackinglistProductStatusRowParams) (PackinglistProduct, error) {
	row := q.db.QueryRowContext(ctx, updatePackinglistProductStatusRow,
		arg.ProductID,
		arg.PackinglistID,
		arg.OrderID,
		arg.TraceabilityCode,
		arg.Status,
		arg.Boxweight,
	)
	var i PackinglistProduct
	err := row.Scan(
		&i.ID,
		&i.PackinglistID,
		&i.Batchno,
		&i.ReceptionformID,
		&i.OrderID,
		&i.TraceabilityCode,
		&i.ProductID,
		&i.Boxweight,
		&i.Totalboxes,
		&i.Productnetweight,
		&i.Totalproductnetweight,
		&i.Totalproductgrossweight,
		&i.CreatedAt,
		&i.Status,
	)
	return i, err
}

const updateStatusonQcpProduct = `-- name: UpdateStatusonQcpProduct :exec
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 UpdateStatusonQcpProductParams struct {
	ID     int64  `json:"id"`
	Status string `json:"status"`
}

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