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

package db

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

const createReceptionForm = `-- name: CreateReceptionForm :one
INSERT INTO receptionform (
    supplier_id,
    traceability_code,
    order_id,
    crop_id,
    batches,
    netweight,
    status,
    phytostatus,
    modeoftransport_id,
    quantityrejected,
    previousharvestbalance,
    finalharvestbalance,
    driversname,
    carnumberplate,
    deliverytime,
    packhouse_id,
    exportcompany_id,
    score,
    user_id
 ) VALUES (
     $1, $2, $3,
     $4, $5, $6,
     $7, $8, $9,
     $10,$11,$12,
     $13,$14,$15,
     $16,$17,$18,
     $19
    )
RETURNING id, supplier_id, traceability_code, order_id, crop_id, batches, netweight, phytostatus, status, modeoftransport_id, quantityrejected, previousharvestbalance, finalharvestbalance, driversname, carnumberplate, deliverytime, score, user_id, packhouse_id, exportcompany_id, created_at
`

type CreateReceptionFormParams struct {
	SupplierID             int32     `json:"supplier_id"`
	TraceabilityCode       string    `json:"traceability_code"`
	OrderID                int32     `json:"order_id"`
	CropID                 int32     `json:"crop_id"`
	Batches                int32     `json:"batches"`
	Netweight              float64   `json:"netweight"`
	Status                 string    `json:"status"`
	Phytostatus            string    `json:"phytostatus"`
	ModeoftransportID      int32     `json:"modeoftransport_id"`
	Quantityrejected       float64   `json:"quantityrejected"`
	Previousharvestbalance float64   `json:"previousharvestbalance"`
	Finalharvestbalance    float64   `json:"finalharvestbalance"`
	Driversname            string    `json:"driversname"`
	Carnumberplate         string    `json:"carnumberplate"`
	Deliverytime           time.Time `json:"deliverytime"`
	PackhouseID            int32     `json:"packhouse_id"`
	ExportcompanyID        int32     `json:"exportcompany_id"`
	Score                  int32     `json:"score"`
	UserID                 int32     `json:"user_id"`
}

func (q *Queries) CreateReceptionForm(ctx context.Context, arg CreateReceptionFormParams) (Receptionform, error) {
	row := q.db.QueryRowContext(ctx, createReceptionForm,
		arg.SupplierID,
		arg.TraceabilityCode,
		arg.OrderID,
		arg.CropID,
		arg.Batches,
		arg.Netweight,
		arg.Status,
		arg.Phytostatus,
		arg.ModeoftransportID,
		arg.Quantityrejected,
		arg.Previousharvestbalance,
		arg.Finalharvestbalance,
		arg.Driversname,
		arg.Carnumberplate,
		arg.Deliverytime,
		arg.PackhouseID,
		arg.ExportcompanyID,
		arg.Score,
		arg.UserID,
	)
	var i Receptionform
	err := row.Scan(
		&i.ID,
		&i.SupplierID,
		&i.TraceabilityCode,
		&i.OrderID,
		&i.CropID,
		&i.Batches,
		&i.Netweight,
		&i.Phytostatus,
		&i.Status,
		&i.ModeoftransportID,
		&i.Quantityrejected,
		&i.Previousharvestbalance,
		&i.Finalharvestbalance,
		&i.Driversname,
		&i.Carnumberplate,
		&i.Deliverytime,
		&i.Score,
		&i.UserID,
		&i.PackhouseID,
		&i.ExportcompanyID,
		&i.CreatedAt,
	)
	return i, err
}

const deleteReceptionForm = `-- name: DeleteReceptionForm :exec
DELETE FROM receptionform WHERE id= $1
`

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

const getExporterStampAndStamp = `-- name: GetExporterStampAndStamp :one
SELECT users.signature, users.stamp FROM users
INNER  JOIN user_exporter on user_exporter.user_id = users.id
WHERE  users.user_type = 'EXPORTER'
AND    user_exporter.exportcompany_id = $1
`

type GetExporterStampAndStampRow struct {
	Signature sql.NullString `json:"signature"`
	Stamp     sql.NullString `json:"stamp"`
}

func (q *Queries) GetExporterStampAndStamp(ctx context.Context, exportcompanyID int32) (GetExporterStampAndStampRow, error) {
	row := q.db.QueryRowContext(ctx, getExporterStampAndStamp, exportcompanyID)
	var i GetExporterStampAndStampRow
	err := row.Scan(&i.Signature, &i.Stamp)
	return i, err
}

const getReceptionAttributesPerReception = `-- name: GetReceptionAttributesPerReception :many
SELECT reception_attributes.qtyremoved,reception_attributes.qtytaken,qualityattributes.description,
reception_attributes.percentage,reception_attributes.created_at from reception_attributes
JOIN  qualityattributes on qualityattributes.id = reception_attributes.qualityattribute_id
where reception_attributes.receptionform_id = $1
`

type GetReceptionAttributesPerReceptionRow struct {
	Qtyremoved  float64   `json:"qtyremoved"`
	Qtytaken    float64   `json:"qtytaken"`
	Description string    `json:"description"`
	Percentage  float64   `json:"percentage"`
	CreatedAt   time.Time `json:"created_at"`
}

func (q *Queries) GetReceptionAttributesPerReception(ctx context.Context, receptionformID int32) ([]GetReceptionAttributesPerReceptionRow, error) {
	rows, err := q.db.QueryContext(ctx, getReceptionAttributesPerReception, receptionformID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []GetReceptionAttributesPerReceptionRow{}
	for rows.Next() {
		var i GetReceptionAttributesPerReceptionRow
		if err := rows.Scan(
			&i.Qtyremoved,
			&i.Qtytaken,
			&i.Description,
			&i.Percentage,
			&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 getReceptionDocumentsPerReception = `-- name: GetReceptionDocumentsPerReception :many
SELECT reception_documents.receptionform_id, reception_documents.created_at,documents.description,reception_documents.document from reception_documents
JOIN   documents on documents.id = reception_documents.document_id
where  reception_documents.receptionform_id = $1
`

type GetReceptionDocumentsPerReceptionRow struct {
	ReceptionformID int32     `json:"receptionform_id"`
	CreatedAt       time.Time `json:"created_at"`
	Description     string    `json:"description"`
	Document        string    `json:"document"`
}

func (q *Queries) GetReceptionDocumentsPerReception(ctx context.Context, receptionformID int32) ([]GetReceptionDocumentsPerReceptionRow, error) {
	rows, err := q.db.QueryContext(ctx, getReceptionDocumentsPerReception, receptionformID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []GetReceptionDocumentsPerReceptionRow{}
	for rows.Next() {
		var i GetReceptionDocumentsPerReceptionRow
		if err := rows.Scan(
			&i.ReceptionformID,
			&i.CreatedAt,
			&i.Description,
			&i.Document,
		); 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 getReceptionForm = `-- name: GetReceptionForm :one
SELECT id, supplier_id, traceability_code, order_id, crop_id, batches, netweight, phytostatus, status, modeoftransport_id, quantityrejected, previousharvestbalance, finalharvestbalance, driversname, carnumberplate, deliverytime, score, user_id, packhouse_id, exportcompany_id, created_at FROM receptionform
WHERE id = $1 LIMIT 1
`

func (q *Queries) GetReceptionForm(ctx context.Context, id int64) (Receptionform, error) {
	row := q.db.QueryRowContext(ctx, getReceptionForm, id)
	var i Receptionform
	err := row.Scan(
		&i.ID,
		&i.SupplierID,
		&i.TraceabilityCode,
		&i.OrderID,
		&i.CropID,
		&i.Batches,
		&i.Netweight,
		&i.Phytostatus,
		&i.Status,
		&i.ModeoftransportID,
		&i.Quantityrejected,
		&i.Previousharvestbalance,
		&i.Finalharvestbalance,
		&i.Driversname,
		&i.Carnumberplate,
		&i.Deliverytime,
		&i.Score,
		&i.UserID,
		&i.PackhouseID,
		&i.ExportcompanyID,
		&i.CreatedAt,
	)
	return i, err
}

const getReceptionFormDetails = `-- name: GetReceptionFormDetails :one
 SELECT receptionform.supplier_id,receptionform.traceability_code,receptionform.order_id,
 receptionform.crop_id,receptionform.batches,receptionform.netweight,receptionform.status,
 receptionform.phytostatus,receptionform.modeoftransport_id,receptionform.quantityrejected,
 receptionform.previousharvestbalance,receptionform.finalharvestbalance,receptionform.driversname,
 receptionform.carnumberplate,receptionform.deliverytime,receptionform.packhouse_id,
 receptionform.exportcompany_id,receptionform.score,receptionform.user_id,
 reception_documents.document,reception_attributes.qualityattribute_id,
 reception_attributes.qtyremoved,reception_attributes.qtytaken,reception_attributes.others,reception_attributes.percentage,
 qualityattributes.description,farmers.fmname,
 crops.cropname,exportcompanies.expname FROM receptionform
 LEFT JOIN reception_documents  on reception_documents.receptionform_id  = receptionform.id
 LEFT JOIN reception_attributes on reception_attributes.receptionform_id = receptionform.id
 LEFT JOIN exportcompanies      on exportcompanies.id    = receptionform.exportcompany_id
 LEFT JOIN users                on users.id              = receptionform.user_id
 LEFT JOIN farmers              on farmers.id            = receptionform.supplier_id
 LEFT JOIN crops                on crops.id              = receptionform.crop_id
 LEFT JOIN user_exporter        on user_exporter.user_id = users.id
 LEFT JOIN qualityattributes    on qualityattributes.id = reception_attributes.qualityattribute_id
 WHERE users.user_type = 'EXPORTER' AND receptionform.id = $1
`

type GetReceptionFormDetailsRow struct {
	SupplierID             int32           `json:"supplier_id"`
	TraceabilityCode       string          `json:"traceability_code"`
	OrderID                int32           `json:"order_id"`
	CropID                 int32           `json:"crop_id"`
	Batches                int32           `json:"batches"`
	Netweight              float64         `json:"netweight"`
	Status                 string          `json:"status"`
	Phytostatus            string          `json:"phytostatus"`
	ModeoftransportID      int32           `json:"modeoftransport_id"`
	Quantityrejected       float64         `json:"quantityrejected"`
	Previousharvestbalance float64         `json:"previousharvestbalance"`
	Finalharvestbalance    float64         `json:"finalharvestbalance"`
	Driversname            string          `json:"driversname"`
	Carnumberplate         string          `json:"carnumberplate"`
	Deliverytime           time.Time       `json:"deliverytime"`
	PackhouseID            int32           `json:"packhouse_id"`
	ExportcompanyID        int32           `json:"exportcompany_id"`
	Score                  int32           `json:"score"`
	UserID                 int32           `json:"user_id"`
	Document               sql.NullString  `json:"document"`
	QualityattributeID     sql.NullInt32   `json:"qualityattribute_id"`
	Qtyremoved             sql.NullFloat64 `json:"qtyremoved"`
	Qtytaken               sql.NullFloat64 `json:"qtytaken"`
	Others                 sql.NullString  `json:"others"`
	Percentage             sql.NullFloat64 `json:"percentage"`
	Description            sql.NullString  `json:"description"`
	Fmname                 sql.NullString  `json:"fmname"`
	Cropname               sql.NullString  `json:"cropname"`
	Expname                sql.NullString  `json:"expname"`
}

func (q *Queries) GetReceptionFormDetails(ctx context.Context, id int64) (GetReceptionFormDetailsRow, error) {
	row := q.db.QueryRowContext(ctx, getReceptionFormDetails, id)
	var i GetReceptionFormDetailsRow
	err := row.Scan(
		&i.SupplierID,
		&i.TraceabilityCode,
		&i.OrderID,
		&i.CropID,
		&i.Batches,
		&i.Netweight,
		&i.Status,
		&i.Phytostatus,
		&i.ModeoftransportID,
		&i.Quantityrejected,
		&i.Previousharvestbalance,
		&i.Finalharvestbalance,
		&i.Driversname,
		&i.Carnumberplate,
		&i.Deliverytime,
		&i.PackhouseID,
		&i.ExportcompanyID,
		&i.Score,
		&i.UserID,
		&i.Document,
		&i.QualityattributeID,
		&i.Qtyremoved,
		&i.Qtytaken,
		&i.Others,
		&i.Percentage,
		&i.Description,
		&i.Fmname,
		&i.Cropname,
		&i.Expname,
	)
	return i, err
}

const getReceptionFormReport = `-- name: GetReceptionFormReport :one
 SELECT farmers.fmname,farmers.fmphone,users.fullname,countries.countryname,packhouses.phname as packhouse_name,users.signature as qc_signature,exportcompanies.expname, receptionform.traceability_code,receptionform.order_id,
 clients.companyname,crops.cropname,receptionform.batches,receptionform.netweight,receptionform.status,
 receptionform.phytostatus,receptionform.modeoftransport_id,receptionform.quantityrejected,
 receptionform.previousharvestbalance,receptionform.finalharvestbalance,receptionform.driversname,
 receptionform.carnumberplate,receptionform.deliverytime,receptionform.packhouse_id,
 receptionform.exportcompany_id,modesoftransport.motdescription,receptionform.score,receptionform.created_at,
 exportcompanies.logo FROM receptionform
 LEFT JOIN exportcompanies          on exportcompanies.id         = receptionform.exportcompany_id
 LEFT JOIN users                    on users.id                   = receptionform.user_id
 LEFT JOIN orders                   on orders.id                  = receptionform.order_id
 LEFT JOIN clients                  on clients.id                 = orders.client_id
 LEFT JOIN crops                    on crops.id                   = receptionform.crop_id
 LEFT JOIN packhouses               on packhouses.id              = receptionform.packhouse_id
 LEFT JOIN farmers                  on farmers.id                 = receptionform.supplier_id
 LEFT JOIN countries                on countries.id               = clients.country_id
 LEFT JOIN modesoftransport         on modesoftransport.id        = receptionform.modeoftransport_id
 WHERE receptionform.id     = $1
`

type GetReceptionFormReportRow struct {
	Fmname                 sql.NullString `json:"fmname"`
	Fmphone                sql.NullString `json:"fmphone"`
	Fullname               sql.NullString `json:"fullname"`
	Countryname            sql.NullString `json:"countryname"`
	PackhouseName          sql.NullString `json:"packhouse_name"`
	QcSignature            sql.NullString `json:"qc_signature"`
	Expname                sql.NullString `json:"expname"`
	TraceabilityCode       string         `json:"traceability_code"`
	OrderID                int32          `json:"order_id"`
	Companyname            sql.NullString `json:"companyname"`
	Cropname               sql.NullString `json:"cropname"`
	Batches                int32          `json:"batches"`
	Netweight              float64        `json:"netweight"`
	Status                 string         `json:"status"`
	Phytostatus            string         `json:"phytostatus"`
	ModeoftransportID      int32          `json:"modeoftransport_id"`
	Quantityrejected       float64        `json:"quantityrejected"`
	Previousharvestbalance float64        `json:"previousharvestbalance"`
	Finalharvestbalance    float64        `json:"finalharvestbalance"`
	Driversname            string         `json:"driversname"`
	Carnumberplate         string         `json:"carnumberplate"`
	Deliverytime           time.Time      `json:"deliverytime"`
	PackhouseID            int32          `json:"packhouse_id"`
	ExportcompanyID        int32          `json:"exportcompany_id"`
	Motdescription         sql.NullString `json:"motdescription"`
	Score                  int32          `json:"score"`
	CreatedAt              time.Time      `json:"created_at"`
	Logo                   sql.NullString `json:"logo"`
}

func (q *Queries) GetReceptionFormReport(ctx context.Context, id int64) (GetReceptionFormReportRow, error) {
	row := q.db.QueryRowContext(ctx, getReceptionFormReport, id)
	var i GetReceptionFormReportRow
	err := row.Scan(
		&i.Fmname,
		&i.Fmphone,
		&i.Fullname,
		&i.Countryname,
		&i.PackhouseName,
		&i.QcSignature,
		&i.Expname,
		&i.TraceabilityCode,
		&i.OrderID,
		&i.Companyname,
		&i.Cropname,
		&i.Batches,
		&i.Netweight,
		&i.Status,
		&i.Phytostatus,
		&i.ModeoftransportID,
		&i.Quantityrejected,
		&i.Previousharvestbalance,
		&i.Finalharvestbalance,
		&i.Driversname,
		&i.Carnumberplate,
		&i.Deliverytime,
		&i.PackhouseID,
		&i.ExportcompanyID,
		&i.Motdescription,
		&i.Score,
		&i.CreatedAt,
		&i.Logo,
	)
	return i, err
}

const getReceptionFormsPerOrder = `-- name: GetReceptionFormsPerOrder :many
SELECT receptionform.traceability_code,receptionform.batches,receptionform.id,
receptionform.netweight,receptionform.phytostatus,
receptionform.status,receptionform.quantityrejected,
receptionform.previousharvestbalance,
receptionform.finalharvestbalance,receptionform.driversname,
receptionform.carnumberplate,receptionform.deliverytime,
receptionform.score,receptionform.created_at,packhouses.phname,
exportcompanies.expname,users.fullname,crops.cropname,crops.variant,
farmers.fmname,modesoftransport.motdescription
from  receptionform
JOIN  packhouses       on packhouses.id           = receptionform.packhouse_id
JOIN  users            on users.id                = receptionform.user_id
JOIN  exportcompanies  on exportcompanies.id      = receptionform.exportcompany_id
JOIN  modesoftransport on modesoftransport.id     = receptionform.modeoftransport_id
JOIN  crops            on crops.id                = receptionform.crop_id
JOIN  farmers          on farmers.id              = receptionform.supplier_id
where receptionform.order_id = $1
`

type GetReceptionFormsPerOrderRow struct {
	TraceabilityCode       string    `json:"traceability_code"`
	Batches                int32     `json:"batches"`
	ID                     int64     `json:"id"`
	Netweight              float64   `json:"netweight"`
	Phytostatus            string    `json:"phytostatus"`
	Status                 string    `json:"status"`
	Quantityrejected       float64   `json:"quantityrejected"`
	Previousharvestbalance float64   `json:"previousharvestbalance"`
	Finalharvestbalance    float64   `json:"finalharvestbalance"`
	Driversname            string    `json:"driversname"`
	Carnumberplate         string    `json:"carnumberplate"`
	Deliverytime           time.Time `json:"deliverytime"`
	Score                  int32     `json:"score"`
	CreatedAt              time.Time `json:"created_at"`
	Phname                 string    `json:"phname"`
	Expname                string    `json:"expname"`
	Fullname               string    `json:"fullname"`
	Cropname               string    `json:"cropname"`
	Variant                string    `json:"variant"`
	Fmname                 string    `json:"fmname"`
	Motdescription         string    `json:"motdescription"`
}

func (q *Queries) GetReceptionFormsPerOrder(ctx context.Context, orderID int32) ([]GetReceptionFormsPerOrderRow, error) {
	rows, err := q.db.QueryContext(ctx, getReceptionFormsPerOrder, orderID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []GetReceptionFormsPerOrderRow{}
	for rows.Next() {
		var i GetReceptionFormsPerOrderRow
		if err := rows.Scan(
			&i.TraceabilityCode,
			&i.Batches,
			&i.ID,
			&i.Netweight,
			&i.Phytostatus,
			&i.Status,
			&i.Quantityrejected,
			&i.Previousharvestbalance,
			&i.Finalharvestbalance,
			&i.Driversname,
			&i.Carnumberplate,
			&i.Deliverytime,
			&i.Score,
			&i.CreatedAt,
			&i.Phname,
			&i.Expname,
			&i.Fullname,
			&i.Cropname,
			&i.Variant,
			&i.Fmname,
			&i.Motdescription,
		); 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 listExporterReceptionForms = `-- name: ListExporterReceptionForms :many
SELECT receptionform.supplier_id,receptionform.traceability_code,farmers.fmname,
receptionform.order_id,receptionform.crop_id,crops.cropname,receptionform.batches,
receptionform.netweight,receptionform.status,receptionform.modeoftransport_id,
receptionform.created_at,receptionform.quantityrejected,receptionform.id receptionform_id,
clients.companyname,countries.countryname as destination,receptionform.previousharvestbalance,
receptionform.finalharvestbalance,receptionform.driversname,receptionform.carnumberplate,
receptionform.deliverytime,receptionform.packhouse_id,receptionform.exportcompany_id,
receptionform.score,receptionform.user_id FROM receptionform
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 farmers   on   farmers.id   = receptionform.supplier_id
WHERE receptionform.exportcompany_id = $1
AND   receptionform.status = $4
ORDER BY receptionform.created_at DESC
LIMIT $2 OFFSET $3
`

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

type ListExporterReceptionFormsRow struct {
	SupplierID             int32          `json:"supplier_id"`
	TraceabilityCode       string         `json:"traceability_code"`
	Fmname                 sql.NullString `json:"fmname"`
	OrderID                int32          `json:"order_id"`
	CropID                 int32          `json:"crop_id"`
	Cropname               sql.NullString `json:"cropname"`
	Batches                int32          `json:"batches"`
	Netweight              float64        `json:"netweight"`
	Status                 string         `json:"status"`
	ModeoftransportID      int32          `json:"modeoftransport_id"`
	CreatedAt              time.Time      `json:"created_at"`
	Quantityrejected       float64        `json:"quantityrejected"`
	ReceptionformID        int64          `json:"receptionform_id"`
	Companyname            sql.NullString `json:"companyname"`
	Destination            sql.NullString `json:"destination"`
	Previousharvestbalance float64        `json:"previousharvestbalance"`
	Finalharvestbalance    float64        `json:"finalharvestbalance"`
	Driversname            string         `json:"driversname"`
	Carnumberplate         string         `json:"carnumberplate"`
	Deliverytime           time.Time      `json:"deliverytime"`
	PackhouseID            int32          `json:"packhouse_id"`
	ExportcompanyID        int32          `json:"exportcompany_id"`
	Score                  int32          `json:"score"`
	UserID                 int32          `json:"user_id"`
}

func (q *Queries) ListExporterReceptionForms(ctx context.Context, arg ListExporterReceptionFormsParams) ([]ListExporterReceptionFormsRow, error) {
	rows, err := q.db.QueryContext(ctx, listExporterReceptionForms,
		arg.ExportcompanyID,
		arg.Limit,
		arg.Offset,
		arg.Status,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListExporterReceptionFormsRow{}
	for rows.Next() {
		var i ListExporterReceptionFormsRow
		if err := rows.Scan(
			&i.SupplierID,
			&i.TraceabilityCode,
			&i.Fmname,
			&i.OrderID,
			&i.CropID,
			&i.Cropname,
			&i.Batches,
			&i.Netweight,
			&i.Status,
			&i.ModeoftransportID,
			&i.CreatedAt,
			&i.Quantityrejected,
			&i.ReceptionformID,
			&i.Companyname,
			&i.Destination,
			&i.Previousharvestbalance,
			&i.Finalharvestbalance,
			&i.Driversname,
			&i.Carnumberplate,
			&i.Deliverytime,
			&i.PackhouseID,
			&i.ExportcompanyID,
			&i.Score,
			&i.UserID,
		); 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 listReceptionForms = `-- name: ListReceptionForms :many
SELECT id, supplier_id, traceability_code, order_id, crop_id, batches, netweight, phytostatus, status, modeoftransport_id, quantityrejected, previousharvestbalance, finalharvestbalance, driversname, carnumberplate, deliverytime, score, user_id, packhouse_id, exportcompany_id, created_at FROM receptionform
ORDER BY id LIMIT $1
OFFSET $2
`

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

func (q *Queries) ListReceptionForms(ctx context.Context, arg ListReceptionFormsParams) ([]Receptionform, error) {
	rows, err := q.db.QueryContext(ctx, listReceptionForms, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Receptionform{}
	for rows.Next() {
		var i Receptionform
		if err := rows.Scan(
			&i.ID,
			&i.SupplierID,
			&i.TraceabilityCode,
			&i.OrderID,
			&i.CropID,
			&i.Batches,
			&i.Netweight,
			&i.Phytostatus,
			&i.Status,
			&i.ModeoftransportID,
			&i.Quantityrejected,
			&i.Previousharvestbalance,
			&i.Finalharvestbalance,
			&i.Driversname,
			&i.Carnumberplate,
			&i.Deliverytime,
			&i.Score,
			&i.UserID,
			&i.PackhouseID,
			&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 pendingReceptionFormsCount = `-- name: PendingReceptionFormsCount :one
SELECT COUNT(id) from receptionform
where status = 'Pending' AND exportcompany_id = $1
`

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

const rejectedReceptionFormsCount = `-- name: RejectedReceptionFormsCount :one
SELECT COUNT(id) from receptionform
where status = 'Rejected'  AND exportcompany_id = $1
`

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

const returnOrderIDForReception = `-- name: ReturnOrderIDForReception :one
SELECT order_id,traceability_code,crop_id FROM receptionform WHERE id= $1
`

type ReturnOrderIDForReceptionRow struct {
	OrderID          int32  `json:"order_id"`
	TraceabilityCode string `json:"traceability_code"`
	CropID           int32  `json:"crop_id"`
}

func (q *Queries) ReturnOrderIDForReception(ctx context.Context, id int64) (ReturnOrderIDForReceptionRow, error) {
	row := q.db.QueryRowContext(ctx, returnOrderIDForReception, id)
	var i ReturnOrderIDForReceptionRow
	err := row.Scan(&i.OrderID, &i.TraceabilityCode, &i.CropID)
	return i, err
}

const returnProductIDForReception = `-- name: ReturnProductIDForReception :one
SELECT crop_id FROM receptionform WHERE id= $1
`

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

const submittedReceptionFormsCount = `-- name: SubmittedReceptionFormsCount :one
SELECT COUNT(id) from receptionform
where status = 'Submitted' AND exportcompany_id = $1
`

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

const updateReceptionForm = `-- name: UpdateReceptionForm :one
UPDATE receptionform
  set
    supplier_id=$2,
    traceability_code=$3,
    order_id=$4,
    crop_id=$5,
    batches=$6,
    netWeight=$7,
    phytostatus=$8,
    modeoftransport_id=$9,
    driversname= $10,
    carnumberplate= $11,
    deliverytime= $12,
    score= $13,
    quantityrejected=$14,
    previousharvestbalance= $15,
    finalharvestbalance= $16,
    user_id= $17,
    packhouse_id = $18,
    exportcompany_id = $19
WHERE id = $1
RETURNING id, supplier_id, traceability_code, order_id, crop_id, batches, netweight, phytostatus, status, modeoftransport_id, quantityrejected, previousharvestbalance, finalharvestbalance, driversname, carnumberplate, deliverytime, score, user_id, packhouse_id, exportcompany_id, created_at
`

type UpdateReceptionFormParams struct {
	ID                     int64     `json:"id"`
	SupplierID             int32     `json:"supplier_id"`
	TraceabilityCode       string    `json:"traceability_code"`
	OrderID                int32     `json:"order_id"`
	CropID                 int32     `json:"crop_id"`
	Batches                int32     `json:"batches"`
	Netweight              float64   `json:"netweight"`
	Phytostatus            string    `json:"phytostatus"`
	ModeoftransportID      int32     `json:"modeoftransport_id"`
	Driversname            string    `json:"driversname"`
	Carnumberplate         string    `json:"carnumberplate"`
	Deliverytime           time.Time `json:"deliverytime"`
	Score                  int32     `json:"score"`
	Quantityrejected       float64   `json:"quantityrejected"`
	Previousharvestbalance float64   `json:"previousharvestbalance"`
	Finalharvestbalance    float64   `json:"finalharvestbalance"`
	UserID                 int32     `json:"user_id"`
	PackhouseID            int32     `json:"packhouse_id"`
	ExportcompanyID        int32     `json:"exportcompany_id"`
}

func (q *Queries) UpdateReceptionForm(ctx context.Context, arg UpdateReceptionFormParams) (Receptionform, error) {
	row := q.db.QueryRowContext(ctx, updateReceptionForm,
		arg.ID,
		arg.SupplierID,
		arg.TraceabilityCode,
		arg.OrderID,
		arg.CropID,
		arg.Batches,
		arg.Netweight,
		arg.Phytostatus,
		arg.ModeoftransportID,
		arg.Driversname,
		arg.Carnumberplate,
		arg.Deliverytime,
		arg.Score,
		arg.Quantityrejected,
		arg.Previousharvestbalance,
		arg.Finalharvestbalance,
		arg.UserID,
		arg.PackhouseID,
		arg.ExportcompanyID,
	)
	var i Receptionform
	err := row.Scan(
		&i.ID,
		&i.SupplierID,
		&i.TraceabilityCode,
		&i.OrderID,
		&i.CropID,
		&i.Batches,
		&i.Netweight,
		&i.Phytostatus,
		&i.Status,
		&i.ModeoftransportID,
		&i.Quantityrejected,
		&i.Previousharvestbalance,
		&i.Finalharvestbalance,
		&i.Driversname,
		&i.Carnumberplate,
		&i.Deliverytime,
		&i.Score,
		&i.UserID,
		&i.PackhouseID,
		&i.ExportcompanyID,
		&i.CreatedAt,
	)
	return i, err
}

const updateReceptionStatus = `-- name: UpdateReceptionStatus :exec
UPDATE receptionform
  set
    status = $2
WHERE id = $1
RETURNING id, supplier_id, traceability_code, order_id, crop_id, batches, netweight, phytostatus, status, modeoftransport_id, quantityrejected, previousharvestbalance, finalharvestbalance, driversname, carnumberplate, deliverytime, score, user_id, packhouse_id, exportcompany_id, created_at
`

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

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