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

package db

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

	"github.com/lib/pq"
)

const acceptedPlannedConsignmentsSum = `-- name: AcceptedPlannedConsignmentsSum :one
SELECT COUNT(id)
FROM  plannedconsignments
WHERE plannedconsignments.status in ('Accepted','AwaitingUpdate')
AND   plannedconsignments.exportcompany_id = $1
`

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

const allPlannedConsignmentDocuments = `-- name: AllPlannedConsignmentDocuments :many
SELECT plannedconsignments_documents.document_id,
plannedconsignments_documents.document as doc,
documents.name,documents.description
from   plannedconsignments_documents
JOIN   documents on documents.id       = plannedconsignments_documents.document_id
WHERE  plannedconsignments_documents.plc_id = $1
`

type AllPlannedConsignmentDocumentsRow struct {
	DocumentID  int32  `json:"document_id"`
	Doc         string `json:"doc"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

func (q *Queries) AllPlannedConsignmentDocuments(ctx context.Context, plcID string) ([]AllPlannedConsignmentDocumentsRow, error) {
	rows, err := q.db.QueryContext(ctx, allPlannedConsignmentDocuments, plcID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []AllPlannedConsignmentDocumentsRow{}
	for rows.Next() {
		var i AllPlannedConsignmentDocumentsRow
		if err := rows.Scan(
			&i.DocumentID,
			&i.Doc,
			&i.Name,
			&i.Description,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Close(); err != nil {
		return nil, err
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const allReceptionConsignmentDocuments = `-- name: AllReceptionConsignmentDocuments :many
SELECT reception_documents.document_id,reception_documents.document,
documents.name,documents.description from reception_documents
JOIN  receptionform          on receptionform.id       = reception_documents.receptionform_id
JOIN  orders                 on orders.id              = receptionform.order_id
JOIN  plannedconsignments    on plannedconsignments.id = orders.consignment_no
JOIN  documents              on documents.id           = reception_documents.document_id
WHERE plannedconsignments.id = $1
`

type AllReceptionConsignmentDocumentsRow struct {
	DocumentID  int32  `json:"document_id"`
	Document    string `json:"document"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

func (q *Queries) AllReceptionConsignmentDocuments(ctx context.Context, id string) ([]AllReceptionConsignmentDocumentsRow, error) {
	rows, err := q.db.QueryContext(ctx, allReceptionConsignmentDocuments, id)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []AllReceptionConsignmentDocumentsRow{}
	for rows.Next() {
		var i AllReceptionConsignmentDocumentsRow
		if err := rows.Scan(
			&i.DocumentID,
			&i.Document,
			&i.Name,
			&i.Description,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Close(); err != nil {
		return nil, err
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const awaitingBorderPlannedConsignmentsSum = `-- name: AwaitingBorderPlannedConsignmentsSum :one
SELECT COUNT(id)
FROM plannedconsignments
WHERE plannedconsignments.status= 'AwaitingBorderInspection'
AND exportcompany_id = $1
`

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

const awaitingPlannedConsignmentsSum = `-- name: AwaitingPlannedConsignmentsSum :one
SELECT COUNT(id)
FROM  plannedconsignments
WHERE plannedconsignments.status
IN ('AwaitingUpdateDestination','AwaitingBorderInspection', 'AwaitingPackinglistUpdate','FitForExport','AwaitingReDocumentation')
`

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

const completedBoarderPlannedConsignmentsSum = `-- name: CompletedBoarderPlannedConsignmentsSum :one
SELECT COUNT(id)
FROM plannedconsignments
WHERE plannedconsignments.status = 'Completed'
`

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

const completedPlannedConsignmentsSum = `-- name: CompletedPlannedConsignmentsSum :one
SELECT COUNT(id)
FROM plannedconsignments
WHERE plannedconsignments.status= 'Completed'
AND exportcompany_id = $1
`

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

const consignmentRegimes = `-- name: ConsignmentRegimes :many
SELECT DISTINCT plannedconsignments.id, orders.consignment_no FROM plannedconsignments
LEFT JOIN orders                 on orders.consignment_no        = plannedconsignments.id
LEFT JOIN order_crops            on order_crops.order_id         = orders.id
LEFT JOIN crops                  on crops.id                     = order_crops.crop_id
LEFT JOIN receptionform          on receptionform.id             = orders.id
LEFT JOIN qcp1                   on qcp1.receptionform_id        = receptionform.id
LEFT JOIN qcp1_attributes        on qcp1_attributes.qcp1_id      = qcp1.id
LEFT JOIN qcp1_recommendation    on qcp1_recommendation.qcp1_id  = qcp1.id
LEFT JOIN qcp2                   on qcp2.reception_id            =  receptionform.id
LEFT JOIN qcp2_attributes        on qcp2_attributes.qcp2_id      =  qcp2.id
LEFT JOIN qcp2_recommendation    on qcp2_recommendation.qcp2_id  =  qcp2.id
LEFT JOIN qcp3                   on qcp3.reception_id            =  receptionform.id
LEFT JOIN qcp3_attributes        on qcp3_attributes.qcp3_id      =  qcp3.id
LEFT JOIN qcp3_recommendation    on qcp3_recommendation.qcp3_id  =  qcp3.id
LEFT JOIN packinglist            on packinglist.receptionform_id =  receptionform.id
LEFT JOIN qcp4                   on qcp4.packinglist_id          =  packinglist.id
LEFT JOIN qcp4_attributes        on qcp4_attributes.qcp4_id      =  qcp4.id
LEFT JOIN qcp4_recommendations   on qcp4_recommendations.qcp4_id  =  qcp4.id
LEFT JOIN qcp5                   on qcp5.packinglist_id          =  packinglist.id
LEFT JOIN qcp5_attributes        on qcp5_attributes.qcp5_id      =  qcp5.id
LEFT JOIN qcp5_recommendations   on qcp5_recommendations.qcp5_id  =  qcp5.id
`

type ConsignmentRegimesRow struct {
	ID            string         `json:"id"`
	ConsignmentNo sql.NullString `json:"consignment_no"`
}

func (q *Queries) ConsignmentRegimes(ctx context.Context) ([]ConsignmentRegimesRow, error) {
	rows, err := q.db.QueryContext(ctx, consignmentRegimes)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ConsignmentRegimesRow{}
	for rows.Next() {
		var i ConsignmentRegimesRow
		if err := rows.Scan(&i.ID, &i.ConsignmentNo); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Close(); err != nil {
		return nil, err
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const consignmentReport = `-- name: ConsignmentReport :many
SELECT plannedconsignments.start_date,packhouses.phname,
exportcompanies.expregno,exportcompanies.exprexno,
exithandlers.exhdescription,exitpoints.expdescription,
countries.countryname,modesoftransport.motdescription,airlines.airlinename,
plannedconsignments_tpdetails.country_id,plannedconsignments_tpdetails.modesoftransport_id,
plannedconsignments_tpdetails.exit_date,plannedconsignments_tpdetails.exitpoint_id,
plannedconsignments_tpdetails.airline_id,plannedconsignments_tpdetails.exithandler_id,
plannedconsignments.end_date,plannedconsignments.user_id,plannedconsignments.exportcompany_id,
plannedconsignments.status,orders.id order_id,exportcompanies.expname,exportcompanies.logo FROM plannedconsignments
LEFT JOIN  plannedconsignments_tpdetails on plannedconsignments_tpdetails.plannedconsignments_id = plannedconsignments.id
LEFT JOIN  orders             on orders.consignment_no         = plannedconsignments.id
LEFT JOIN  exitpoints         on exitpoints.id                 = plannedconsignments_tpdetails.exitpoint_id
LEFT JOIN  airlines           on airlines.id                   = plannedconsignments_tpdetails.airline_id
LEFT JOIN  exithandlers       on exithandlers.id               = plannedconsignments_tpdetails.exithandler_id
LEFT JOIN  countries          on countries.id                  = plannedconsignments_tpdetails.country_id
LEFT JOIN  modesoftransport   on modesoftransport.id                    = plannedconsignments_tpdetails.modesoftransport_id
LEFT JOIN  exportcompanies    on exportcompanies.id                     = plannedconsignments.exportcompany_id
LEFT JOIN  packhouse_exporter on packhouse_exporter.exportcompany_id    = plannedconsignments.exportcompany_id
LEFT JOIN  packhouses         on packhouses.id    = packhouse_exporter.packhouse_id
WHERE      plannedconsignments.id  = $1
`

type ConsignmentReportRow struct {
	StartDate          string         `json:"start_date"`
	Phname             sql.NullString `json:"phname"`
	Expregno           sql.NullString `json:"expregno"`
	Exprexno           sql.NullString `json:"exprexno"`
	Exhdescription     sql.NullString `json:"exhdescription"`
	Expdescription     sql.NullString `json:"expdescription"`
	Countryname        sql.NullString `json:"countryname"`
	Motdescription     sql.NullString `json:"motdescription"`
	Airlinename        sql.NullString `json:"airlinename"`
	CountryID          sql.NullInt32  `json:"country_id"`
	ModesoftransportID sql.NullInt32  `json:"modesoftransport_id"`
	ExitDate           sql.NullTime   `json:"exit_date"`
	ExitpointID        sql.NullInt32  `json:"exitpoint_id"`
	AirlineID          sql.NullInt32  `json:"airline_id"`
	ExithandlerID      sql.NullInt32  `json:"exithandler_id"`
	EndDate            string         `json:"end_date"`
	UserID             int32          `json:"user_id"`
	ExportcompanyID    int32          `json:"exportcompany_id"`
	Status             string         `json:"status"`
	OrderID            sql.NullInt64  `json:"order_id"`
	Expname            sql.NullString `json:"expname"`
	Logo               sql.NullString `json:"logo"`
}

func (q *Queries) ConsignmentReport(ctx context.Context, id string) ([]ConsignmentReportRow, error) {
	rows, err := q.db.QueryContext(ctx, consignmentReport, id)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ConsignmentReportRow{}
	for rows.Next() {
		var i ConsignmentReportRow
		if err := rows.Scan(
			&i.StartDate,
			&i.Phname,
			&i.Expregno,
			&i.Exprexno,
			&i.Exhdescription,
			&i.Expdescription,
			&i.Countryname,
			&i.Motdescription,
			&i.Airlinename,
			&i.CountryID,
			&i.ModesoftransportID,
			&i.ExitDate,
			&i.ExitpointID,
			&i.AirlineID,
			&i.ExithandlerID,
			&i.EndDate,
			&i.UserID,
			&i.ExportcompanyID,
			&i.Status,
			&i.OrderID,
			&i.Expname,
			&i.Logo,
		); 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 createPlannedConsignment = `-- name: CreatePlannedConsignment :one
INSERT INTO plannedconsignments (
    id,
    start_date,
    end_date,
    user_id,
    exportcompany_id,
    status
 ) VALUES (
    $1,
    $2,
    $3,
    $4,
    $5,
    $6
)
RETURNING id, start_date, end_date, status, exportcompany_id, user_id, created_at
`

type CreatePlannedConsignmentParams struct {
	ID              string `json:"id"`
	StartDate       string `json:"start_date"`
	EndDate         string `json:"end_date"`
	UserID          int32  `json:"user_id"`
	ExportcompanyID int32  `json:"exportcompany_id"`
	Status          string `json:"status"`
}

func (q *Queries) CreatePlannedConsignment(ctx context.Context, arg CreatePlannedConsignmentParams) (Plannedconsignment, error) {
	row := q.db.QueryRowContext(ctx, createPlannedConsignment,
		arg.ID,
		arg.StartDate,
		arg.EndDate,
		arg.UserID,
		arg.ExportcompanyID,
		arg.Status,
	)
	var i Plannedconsignment
	err := row.Scan(
		&i.ID,
		&i.StartDate,
		&i.EndDate,
		&i.Status,
		&i.ExportcompanyID,
		&i.UserID,
		&i.CreatedAt,
	)
	return i, err
}

const createPlannedOtherDocs = `-- name: CreatePlannedOtherDocs :one
INSERT INTO plannedconsignments_otherdocuments (
    plannedconsignments_id,
    name,
    description
 ) VALUES (
    $1,
    $2,
    $3
)
RETURNING id, plannedconsignments_id, name, description, created_at
`

type CreatePlannedOtherDocsParams struct {
	PlannedconsignmentsID string `json:"plannedconsignments_id"`
	Name                  string `json:"name"`
	Description           string `json:"description"`
}

func (q *Queries) CreatePlannedOtherDocs(ctx context.Context, arg CreatePlannedOtherDocsParams) (PlannedconsignmentsOtherdocument, error) {
	row := q.db.QueryRowContext(ctx, createPlannedOtherDocs, arg.PlannedconsignmentsID, arg.Name, arg.Description)
	var i PlannedconsignmentsOtherdocument
	err := row.Scan(
		&i.ID,
		&i.PlannedconsignmentsID,
		&i.Name,
		&i.Description,
		&i.CreatedAt,
	)
	return i, err
}

const deletePlannedConsigment = `-- name: DeletePlannedConsigment :exec
DELETE FROM plannedconsignments WHERE id= $1
`

func (q *Queries) DeletePlannedConsigment(ctx context.Context, id string) error {
	_, err := q.db.ExecContext(ctx, deletePlannedConsigment, id)
	return err
}

const destroyedPlannedConsignmentsSum = `-- name: DestroyedPlannedConsignmentsSum :one
SELECT COUNT(id)
FROM plannedconsignments
WHERE plannedconsignments.status= 'Destroyed'
AND exportcompany_id = $1
`

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

const getCheckAwaitingStatus = `-- name: GetCheckAwaitingStatus :one
SELECT EXISTS (
  SELECT 1 FROM plannedconsignments
  LEFT JOIN orders on orders.consignment_no = plannedconsignments.id
  WHERE plannedconsignments.status = 'AwaitingUpdate' AND orders.id = $1
)
`

func (q *Queries) GetCheckAwaitingStatus(ctx context.Context, id int64) (bool, error) {
	row := q.db.QueryRowContext(ctx, getCheckAwaitingStatus, id)
	var exists bool
	err := row.Scan(&exists)
	return exists, err
}

const getPackinglistsUnderConsignment = `-- name: GetPackinglistsUnderConsignment :many
SELECT DISTINCT packinglist.id FROM packinglist
JOIN  orders        on orders.id        = packinglist.order_id
WHERE orders.consignment_no = $1
`

func (q *Queries) GetPackinglistsUnderConsignment(ctx context.Context, consignmentNo sql.NullString) ([]int64, error) {
	rows, err := q.db.QueryContext(ctx, getPackinglistsUnderConsignment, consignmentNo)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []int64{}
	for rows.Next() {
		var id int64
		if err := rows.Scan(&id); err != nil {
			return nil, err
		}
		items = append(items, id)
	}
	if err := rows.Close(); err != nil {
		return nil, err
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const getPl = `-- name: GetPl :one
Select plannedconsignments.id, start_date, end_date, plannedconsignments.status, plannedconsignments.exportcompany_id, plannedconsignments.user_id, plannedconsignments.created_at, orders.id, client_id, orders.exportcompany_id, consignment_no, orders.status, orders.user_id, orders.created_at FROM plannedconsignments
LEFT JOIN orders on orders.consignment_no = plannedconsignments.id
WHERE status = 'AwaitingUpdate' AND orders.id = $1
`

type GetPlRow struct {
	ID                string         `json:"id"`
	StartDate         string         `json:"start_date"`
	EndDate           string         `json:"end_date"`
	Status            string         `json:"status"`
	ExportcompanyID   int32          `json:"exportcompany_id"`
	UserID            int32          `json:"user_id"`
	CreatedAt         time.Time      `json:"created_at"`
	ID_2              sql.NullInt64  `json:"id_2"`
	ClientID          sql.NullInt32  `json:"client_id"`
	ExportcompanyID_2 sql.NullInt32  `json:"exportcompany_id_2"`
	ConsignmentNo     sql.NullString `json:"consignment_no"`
	Status_2          sql.NullString `json:"status_2"`
	UserID_2          sql.NullInt32  `json:"user_id_2"`
	CreatedAt_2       sql.NullTime   `json:"created_at_2"`
}

func (q *Queries) GetPl(ctx context.Context, id int64) (GetPlRow, error) {
	row := q.db.QueryRowContext(ctx, getPl, id)
	var i GetPlRow
	err := row.Scan(
		&i.ID,
		&i.StartDate,
		&i.EndDate,
		&i.Status,
		&i.ExportcompanyID,
		&i.UserID,
		&i.CreatedAt,
		&i.ID_2,
		&i.ClientID,
		&i.ExportcompanyID_2,
		&i.ConsignmentNo,
		&i.Status_2,
		&i.UserID_2,
		&i.CreatedAt_2,
	)
	return i, err
}

const getPlExitPoint = `-- name: GetPlExitPoint :many
SELECT plannedconsignments.start_date,plannedconsignments.end_date,plannedconsignments.id consignment_no,
plannedconsignments.created_at,plannedconsignments.status,exportcompanies.expname,packhouses.phname FROM plannedconsignments
JOIN exportcompanies on exportcompanies.id = plannedconsignments.exportcompany_id
JOIN packhouse_exporter on packhouse_exporter.exportcompany_id = exportcompanies.id
JOIN packhouses on packhouses.id = packhouse_exporter.packhouse_id
JOIN plannedconsignments_tpdetails on plannedconsignments_tpdetails.plannedconsignments_id = plannedconsignments.id
WHERE plannedconsignments_tpdetails.exitpoint_id = $1
AND plannedconsignments.status = 'AwaitingBorderInspection'
`

type GetPlExitPointRow struct {
	StartDate     string    `json:"start_date"`
	EndDate       string    `json:"end_date"`
	ConsignmentNo string    `json:"consignment_no"`
	CreatedAt     time.Time `json:"created_at"`
	Status        string    `json:"status"`
	Expname       string    `json:"expname"`
	Phname        string    `json:"phname"`
}

func (q *Queries) GetPlExitPoint(ctx context.Context, exitpointID int32) ([]GetPlExitPointRow, error) {
	rows, err := q.db.QueryContext(ctx, getPlExitPoint, exitpointID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []GetPlExitPointRow{}
	for rows.Next() {
		var i GetPlExitPointRow
		if err := rows.Scan(
			&i.StartDate,
			&i.EndDate,
			&i.ConsignmentNo,
			&i.CreatedAt,
			&i.Status,
			&i.Expname,
			&i.Phname,
		); 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 getPlannedConsignment = `-- name: GetPlannedConsignment :one
SELECT plannedconsignments.start_date,packhouses.phname,
exportcompanies.expregno,exportcompanies.exprexno,
exithandlers.exhdescription,exitpoints.expdescription,
countries.countryname,modesoftransport.motdescription,airlines.airlinename,
plannedconsignments_tpdetails.country_id,plannedconsignments_tpdetails.modesoftransport_id,
plannedconsignments_tpdetails.exit_date,plannedconsignments_tpdetails.exitpoint_id,
plannedconsignments_tpdetails.airline_id,plannedconsignments_tpdetails.exithandler_id,
plannedconsignments.end_date,plannedconsignments.user_id,plannedconsignments.exportcompany_id,
plannedconsignments.status,orders.id order_id,exportcompanies.expname,plannedconsignments.created_at FROM plannedconsignments
LEFT JOIN  plannedconsignments_tpdetails on plannedconsignments_tpdetails.plannedconsignments_id = plannedconsignments.id
LEFT JOIN  orders             on orders.consignment_no         = plannedconsignments.id
LEFT JOIN  exitpoints         on exitpoints.id                 = plannedconsignments_tpdetails.exitpoint_id
LEFT JOIN  airlines           on airlines.id                   = plannedconsignments_tpdetails.airline_id
LEFT JOIN  exithandlers       on exithandlers.id               = plannedconsignments_tpdetails.exithandler_id
LEFT JOIN  countries          on countries.id                  = plannedconsignments_tpdetails.country_id
LEFT JOIN  modesoftransport   on modesoftransport.id                    = plannedconsignments_tpdetails.modesoftransport_id
LEFT JOIN  exportcompanies    on exportcompanies.id                     = plannedconsignments.exportcompany_id
LEFT JOIN  packhouse_exporter on packhouse_exporter.exportcompany_id    = plannedconsignments.exportcompany_id
LEFT JOIN  packhouses         on packhouses.id    = packhouse_exporter.packhouse_id
WHERE plannedconsignments.id        = $1
LIMIT 1
`

type GetPlannedConsignmentRow struct {
	StartDate          string         `json:"start_date"`
	Phname             sql.NullString `json:"phname"`
	Expregno           sql.NullString `json:"expregno"`
	Exprexno           sql.NullString `json:"exprexno"`
	Exhdescription     sql.NullString `json:"exhdescription"`
	Expdescription     sql.NullString `json:"expdescription"`
	Countryname        sql.NullString `json:"countryname"`
	Motdescription     sql.NullString `json:"motdescription"`
	Airlinename        sql.NullString `json:"airlinename"`
	CountryID          sql.NullInt32  `json:"country_id"`
	ModesoftransportID sql.NullInt32  `json:"modesoftransport_id"`
	ExitDate           sql.NullTime   `json:"exit_date"`
	ExitpointID        sql.NullInt32  `json:"exitpoint_id"`
	AirlineID          sql.NullInt32  `json:"airline_id"`
	ExithandlerID      sql.NullInt32  `json:"exithandler_id"`
	EndDate            string         `json:"end_date"`
	UserID             int32          `json:"user_id"`
	ExportcompanyID    int32          `json:"exportcompany_id"`
	Status             string         `json:"status"`
	OrderID            sql.NullInt64  `json:"order_id"`
	Expname            sql.NullString `json:"expname"`
	CreatedAt          time.Time      `json:"created_at"`
}

func (q *Queries) GetPlannedConsignment(ctx context.Context, id string) (GetPlannedConsignmentRow, error) {
	row := q.db.QueryRowContext(ctx, getPlannedConsignment, id)
	var i GetPlannedConsignmentRow
	err := row.Scan(
		&i.StartDate,
		&i.Phname,
		&i.Expregno,
		&i.Exprexno,
		&i.Exhdescription,
		&i.Expdescription,
		&i.Countryname,
		&i.Motdescription,
		&i.Airlinename,
		&i.CountryID,
		&i.ModesoftransportID,
		&i.ExitDate,
		&i.ExitpointID,
		&i.AirlineID,
		&i.ExithandlerID,
		&i.EndDate,
		&i.UserID,
		&i.ExportcompanyID,
		&i.Status,
		&i.OrderID,
		&i.Expname,
		&i.CreatedAt,
	)
	return i, err
}

const listAcceptedApprovalConsigments = `-- name: ListAcceptedApprovalConsigments :many
SELECT DISTINCT plannedconsignments.id consignment_no,plannedconsignments.start_date,plannedconsignments.end_date,
plannedconsignments.created_at,plannedconsignments.status,exportcompanies.expname,packhouses.phname FROM plannedconsignments
LEFT JOIN exportcompanies on exportcompanies.id = plannedconsignments.exportcompany_id
LEFT JOIN packhouse_exporter on packhouse_exporter.exportcompany_id = exportcompanies.id
LEFT JOIN packhouses on packhouses.id = packhouse_exporter.packhouse_id
WHERE plannedconsignments.exportcompany_id = $1
AND   plannedconsignments.status in ('Accepted','AwaitingUpdate')
ORDER BY plannedconsignments.created_at DESC
LIMIT $2 OFFSET $3
`

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

type ListAcceptedApprovalConsigmentsRow struct {
	ConsignmentNo string         `json:"consignment_no"`
	StartDate     string         `json:"start_date"`
	EndDate       string         `json:"end_date"`
	CreatedAt     time.Time      `json:"created_at"`
	Status        string         `json:"status"`
	Expname       sql.NullString `json:"expname"`
	Phname        sql.NullString `json:"phname"`
}

func (q *Queries) ListAcceptedApprovalConsigments(ctx context.Context, arg ListAcceptedApprovalConsigmentsParams) ([]ListAcceptedApprovalConsigmentsRow, error) {
	rows, err := q.db.QueryContext(ctx, listAcceptedApprovalConsigments, arg.ExportcompanyID, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAcceptedApprovalConsigmentsRow{}
	for rows.Next() {
		var i ListAcceptedApprovalConsigmentsRow
		if err := rows.Scan(
			&i.ConsignmentNo,
			&i.StartDate,
			&i.EndDate,
			&i.CreatedAt,
			&i.Status,
			&i.Expname,
			&i.Phname,
		); 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 listAcceptedPlannedConsigments = `-- name: ListAcceptedPlannedConsigments :many
SELECT DISTINCT plannedconsignments.id consignment_no,plannedconsignments.start_date,plannedconsignments.end_date,
plannedconsignments.created_at,plannedconsignments.status,exportcompanies.expname,packhouses.phname FROM plannedconsignments
LEFT JOIN exportcompanies on exportcompanies.id = plannedconsignments.exportcompany_id
LEFT JOIN packhouse_exporter on packhouse_exporter.exportcompany_id = exportcompanies.id
LEFT JOIN packhouses on packhouses.id = packhouse_exporter.packhouse_id
WHERE plannedconsignments.exportcompany_id = $1
AND   plannedconsignments.status = $2
ORDER BY plannedconsignments.created_at DESC
LIMIT $3 OFFSET $4
`

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

type ListAcceptedPlannedConsigmentsRow struct {
	ConsignmentNo string         `json:"consignment_no"`
	StartDate     string         `json:"start_date"`
	EndDate       string         `json:"end_date"`
	CreatedAt     time.Time      `json:"created_at"`
	Status        string         `json:"status"`
	Expname       sql.NullString `json:"expname"`
	Phname        sql.NullString `json:"phname"`
}

func (q *Queries) ListAcceptedPlannedConsigments(ctx context.Context, arg ListAcceptedPlannedConsigmentsParams) ([]ListAcceptedPlannedConsigmentsRow, error) {
	rows, err := q.db.QueryContext(ctx, listAcceptedPlannedConsigments,
		arg.ExportcompanyID,
		arg.Status,
		arg.Limit,
		arg.Offset,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAcceptedPlannedConsigmentsRow{}
	for rows.Next() {
		var i ListAcceptedPlannedConsigmentsRow
		if err := rows.Scan(
			&i.ConsignmentNo,
			&i.StartDate,
			&i.EndDate,
			&i.CreatedAt,
			&i.Status,
			&i.Expname,
			&i.Phname,
		); 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 listAllBoarderPlannedConsigmentsByStatus = `-- name: ListAllBoarderPlannedConsigmentsByStatus :many
SELECT plannedconsignments.start_date,plannedconsignments_tpdetails.exit_date,plannedconsignments.end_date,plannedconsignments.id consignment_no,
plannedconsignments.created_at,plannedconsignments.status,exportcompanies.expname,packhouses.phname FROM plannedconsignments
LEFT JOIN plannedconsignments_tpdetails on plannedconsignments_tpdetails.plannedconsignments_id = plannedconsignments.id
LEFT JOIN exportcompanies on exportcompanies.id = plannedconsignments.exportcompany_id
LEFT JOIN packhouse_exporter on packhouse_exporter.exportcompany_id = exportcompanies.id
LEFT JOIN packhouses on packhouses.id  = packhouse_exporter.packhouse_id
WHERE plannedconsignments.status = $3
ORDER BY plannedconsignments.created_at
DESC LIMIT $1 OFFSET $2
`

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

type ListAllBoarderPlannedConsigmentsByStatusRow struct {
	StartDate     string         `json:"start_date"`
	ExitDate      sql.NullTime   `json:"exit_date"`
	EndDate       string         `json:"end_date"`
	ConsignmentNo string         `json:"consignment_no"`
	CreatedAt     time.Time      `json:"created_at"`
	Status        string         `json:"status"`
	Expname       sql.NullString `json:"expname"`
	Phname        sql.NullString `json:"phname"`
}

func (q *Queries) ListAllBoarderPlannedConsigmentsByStatus(ctx context.Context, arg ListAllBoarderPlannedConsigmentsByStatusParams) ([]ListAllBoarderPlannedConsigmentsByStatusRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllBoarderPlannedConsigmentsByStatus, arg.Limit, arg.Offset, arg.Status)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllBoarderPlannedConsigmentsByStatusRow{}
	for rows.Next() {
		var i ListAllBoarderPlannedConsigmentsByStatusRow
		if err := rows.Scan(
			&i.StartDate,
			&i.ExitDate,
			&i.EndDate,
			&i.ConsignmentNo,
			&i.CreatedAt,
			&i.Status,
			&i.Expname,
			&i.Phname,
		); 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 listAllCompaniesAllFiltersConsignmentReports = `-- name: ListAllCompaniesAllFiltersConsignmentReports :many
SELECT plannedconsignments.start_date,packhouses.phname,
exportcompanies.expregno,exportcompanies.exprexno,
plannedconsignments.id as consignment_no,
exithandlers.exhdescription,exitpoints.expdescription,
countries.countryname,modesoftransport.motdescription,airlines.airlinename,
plannedconsignments_tpdetails.country_id,plannedconsignments_tpdetails.modesoftransport_id,
plannedconsignments_tpdetails.exit_date,plannedconsignments_tpdetails.exitpoint_id,
plannedconsignments_tpdetails.airline_id,plannedconsignments_tpdetails.exithandler_id,
plannedconsignments.end_date,plannedconsignments.user_id,plannedconsignments.exportcompany_id,
plannedconsignments.status,plannedconsignments.created_at,orders.id order_id,exportcompanies.expname,exportcompanies.logo FROM plannedconsignments
LEFT JOIN  plannedconsignments_tpdetails on plannedconsignments_tpdetails.plannedconsignments_id = plannedconsignments.id
LEFT JOIN  orders             on orders.consignment_no         = plannedconsignments.id
LEFT JOIN  exitpoints         on exitpoints.id                 = plannedconsignments_tpdetails.exitpoint_id
LEFT JOIN  airlines           on airlines.id                   = plannedconsignments_tpdetails.airline_id
LEFT JOIN  exithandlers       on exithandlers.id               = plannedconsignments_tpdetails.exithandler_id
LEFT JOIN  countries          on countries.id                  = plannedconsignments_tpdetails.country_id
LEFT JOIN  modesoftransport   on modesoftransport.id                    = plannedconsignments_tpdetails.modesoftransport_id
LEFT JOIN  exportcompanies    on exportcompanies.id                     = plannedconsignments.exportcompany_id
LEFT JOIN  packhouse_exporter on packhouse_exporter.exportcompany_id    = plannedconsignments.exportcompany_id
LEFT JOIN  packhouses         on packhouses.id    = packhouse_exporter.packhouse_id
WHERE plannedconsignments.status = ANY($1::text[])
AND   plannedconsignments.created_at BETWEEN TO_TIMESTAMP($2, 'YYYY-MM-DD HH24:MI:SS')
AND   TO_TIMESTAMP($3, 'YYYY-MM-DD HH24:MI:SS')
ORDER BY plannedconsignments.created_at DESC LIMIT $4 OFFSET $5
`

type ListAllCompaniesAllFiltersConsignmentReportsParams struct {
	Column1       []string `json:"column_1"`
	ToTimestamp   string   `json:"to_timestamp"`
	ToTimestamp_2 string   `json:"to_timestamp_2"`
	Limit         int32    `json:"limit"`
	Offset        int32    `json:"offset"`
}

type ListAllCompaniesAllFiltersConsignmentReportsRow struct {
	StartDate          string         `json:"start_date"`
	Phname             sql.NullString `json:"phname"`
	Expregno           sql.NullString `json:"expregno"`
	Exprexno           sql.NullString `json:"exprexno"`
	ConsignmentNo      string         `json:"consignment_no"`
	Exhdescription     sql.NullString `json:"exhdescription"`
	Expdescription     sql.NullString `json:"expdescription"`
	Countryname        sql.NullString `json:"countryname"`
	Motdescription     sql.NullString `json:"motdescription"`
	Airlinename        sql.NullString `json:"airlinename"`
	CountryID          sql.NullInt32  `json:"country_id"`
	ModesoftransportID sql.NullInt32  `json:"modesoftransport_id"`
	ExitDate           sql.NullTime   `json:"exit_date"`
	ExitpointID        sql.NullInt32  `json:"exitpoint_id"`
	AirlineID          sql.NullInt32  `json:"airline_id"`
	ExithandlerID      sql.NullInt32  `json:"exithandler_id"`
	EndDate            string         `json:"end_date"`
	UserID             int32          `json:"user_id"`
	ExportcompanyID    int32          `json:"exportcompany_id"`
	Status             string         `json:"status"`
	CreatedAt          time.Time      `json:"created_at"`
	OrderID            sql.NullInt64  `json:"order_id"`
	Expname            sql.NullString `json:"expname"`
	Logo               sql.NullString `json:"logo"`
}

func (q *Queries) ListAllCompaniesAllFiltersConsignmentReports(ctx context.Context, arg ListAllCompaniesAllFiltersConsignmentReportsParams) ([]ListAllCompaniesAllFiltersConsignmentReportsRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesAllFiltersConsignmentReports,
		pq.Array(arg.Column1),
		arg.ToTimestamp,
		arg.ToTimestamp_2,
		arg.Limit,
		arg.Offset,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesAllFiltersConsignmentReportsRow{}
	for rows.Next() {
		var i ListAllCompaniesAllFiltersConsignmentReportsRow
		if err := rows.Scan(
			&i.StartDate,
			&i.Phname,
			&i.Expregno,
			&i.Exprexno,
			&i.ConsignmentNo,
			&i.Exhdescription,
			&i.Expdescription,
			&i.Countryname,
			&i.Motdescription,
			&i.Airlinename,
			&i.CountryID,
			&i.ModesoftransportID,
			&i.ExitDate,
			&i.ExitpointID,
			&i.AirlineID,
			&i.ExithandlerID,
			&i.EndDate,
			&i.UserID,
			&i.ExportcompanyID,
			&i.Status,
			&i.CreatedAt,
			&i.OrderID,
			&i.Expname,
			&i.Logo,
		); 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 listAllCompaniesConsignmentReports = `-- name: ListAllCompaniesConsignmentReports :many
SELECT plannedconsignments.start_date,packhouses.phname,
exportcompanies.expregno,exportcompanies.exprexno,
plannedconsignments.id as consignment_no,
exithandlers.exhdescription,exitpoints.expdescription,
countries.countryname,modesoftransport.motdescription,airlines.airlinename,
plannedconsignments_tpdetails.country_id,plannedconsignments_tpdetails.modesoftransport_id,
plannedconsignments_tpdetails.exit_date,plannedconsignments_tpdetails.exitpoint_id,
plannedconsignments_tpdetails.airline_id,plannedconsignments_tpdetails.exithandler_id,
plannedconsignments.end_date,plannedconsignments.user_id,plannedconsignments.exportcompany_id,
plannedconsignments.status,plannedconsignments.created_at,orders.id order_id,exportcompanies.expname,exportcompanies.logo FROM plannedconsignments
LEFT JOIN  plannedconsignments_tpdetails on plannedconsignments_tpdetails.plannedconsignments_id = plannedconsignments.id
LEFT JOIN  orders             on orders.consignment_no         = plannedconsignments.id
LEFT JOIN  exitpoints         on exitpoints.id                 = plannedconsignments_tpdetails.exitpoint_id
LEFT JOIN  airlines           on airlines.id                   = plannedconsignments_tpdetails.airline_id
LEFT JOIN  exithandlers       on exithandlers.id               = plannedconsignments_tpdetails.exithandler_id
LEFT JOIN  countries          on countries.id                  = plannedconsignments_tpdetails.country_id
LEFT JOIN  modesoftransport   on modesoftransport.id                    = plannedconsignments_tpdetails.modesoftransport_id
LEFT JOIN  exportcompanies    on exportcompanies.id                     = plannedconsignments.exportcompany_id
LEFT JOIN  packhouse_exporter on packhouse_exporter.exportcompany_id    = plannedconsignments.exportcompany_id
LEFT JOIN  packhouses         on packhouses.id    = packhouse_exporter.packhouse_id
WHERE plannedconsignments.status =  ANY($1::text[])
AND   plannedconsignments.created_at BETWEEN TO_TIMESTAMP($2, 'YYYY-MM-DD HH24:MI:SS')
AND   TO_TIMESTAMP($3, 'YYYY-MM-DD HH24:MI:SS')
ORDER BY plannedconsignments.created_at DESC LIMIT $4 OFFSET $5
`

type ListAllCompaniesConsignmentReportsParams struct {
	Column1       []string `json:"column_1"`
	ToTimestamp   string   `json:"to_timestamp"`
	ToTimestamp_2 string   `json:"to_timestamp_2"`
	Limit         int32    `json:"limit"`
	Offset        int32    `json:"offset"`
}

type ListAllCompaniesConsignmentReportsRow struct {
	StartDate          string         `json:"start_date"`
	Phname             sql.NullString `json:"phname"`
	Expregno           sql.NullString `json:"expregno"`
	Exprexno           sql.NullString `json:"exprexno"`
	ConsignmentNo      string         `json:"consignment_no"`
	Exhdescription     sql.NullString `json:"exhdescription"`
	Expdescription     sql.NullString `json:"expdescription"`
	Countryname        sql.NullString `json:"countryname"`
	Motdescription     sql.NullString `json:"motdescription"`
	Airlinename        sql.NullString `json:"airlinename"`
	CountryID          sql.NullInt32  `json:"country_id"`
	ModesoftransportID sql.NullInt32  `json:"modesoftransport_id"`
	ExitDate           sql.NullTime   `json:"exit_date"`
	ExitpointID        sql.NullInt32  `json:"exitpoint_id"`
	AirlineID          sql.NullInt32  `json:"airline_id"`
	ExithandlerID      sql.NullInt32  `json:"exithandler_id"`
	EndDate            string         `json:"end_date"`
	UserID             int32          `json:"user_id"`
	ExportcompanyID    int32          `json:"exportcompany_id"`
	Status             string         `json:"status"`
	CreatedAt          time.Time      `json:"created_at"`
	OrderID            sql.NullInt64  `json:"order_id"`
	Expname            sql.NullString `json:"expname"`
	Logo               sql.NullString `json:"logo"`
}

func (q *Queries) ListAllCompaniesConsignmentReports(ctx context.Context, arg ListAllCompaniesConsignmentReportsParams) ([]ListAllCompaniesConsignmentReportsRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesConsignmentReports,
		pq.Array(arg.Column1),
		arg.ToTimestamp,
		arg.ToTimestamp_2,
		arg.Limit,
		arg.Offset,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesConsignmentReportsRow{}
	for rows.Next() {
		var i ListAllCompaniesConsignmentReportsRow
		if err := rows.Scan(
			&i.StartDate,
			&i.Phname,
			&i.Expregno,
			&i.Exprexno,
			&i.ConsignmentNo,
			&i.Exhdescription,
			&i.Expdescription,
			&i.Countryname,
			&i.Motdescription,
			&i.Airlinename,
			&i.CountryID,
			&i.ModesoftransportID,
			&i.ExitDate,
			&i.ExitpointID,
			&i.AirlineID,
			&i.ExithandlerID,
			&i.EndDate,
			&i.UserID,
			&i.ExportcompanyID,
			&i.Status,
			&i.CreatedAt,
			&i.OrderID,
			&i.Expname,
			&i.Logo,
		); 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 listAllCompaniesDateFiltersConsignmentReports = `-- name: ListAllCompaniesDateFiltersConsignmentReports :many
SELECT plannedconsignments.start_date,packhouses.phname,
exportcompanies.expregno,exportcompanies.exprexno,
plannedconsignments.id as consignment_no,
exithandlers.exhdescription,exitpoints.expdescription,
countries.countryname,modesoftransport.motdescription,airlines.airlinename,
plannedconsignments_tpdetails.country_id,plannedconsignments_tpdetails.modesoftransport_id,
plannedconsignments_tpdetails.exit_date,plannedconsignments_tpdetails.exitpoint_id,
plannedconsignments_tpdetails.airline_id,plannedconsignments_tpdetails.exithandler_id,
plannedconsignments.end_date,plannedconsignments.user_id,plannedconsignments.exportcompany_id,
plannedconsignments.status,plannedconsignments.created_at,orders.id order_id,exportcompanies.expname,exportcompanies.logo FROM plannedconsignments
LEFT JOIN  plannedconsignments_tpdetails on plannedconsignments_tpdetails.plannedconsignments_id = plannedconsignments.id
LEFT JOIN  orders             on orders.consignment_no         = plannedconsignments.id
LEFT JOIN  exitpoints         on exitpoints.id                 = plannedconsignments_tpdetails.exitpoint_id
LEFT JOIN  airlines           on airlines.id                   = plannedconsignments_tpdetails.airline_id
LEFT JOIN  exithandlers       on exithandlers.id               = plannedconsignments_tpdetails.exithandler_id
LEFT JOIN  countries          on countries.id                  = plannedconsignments_tpdetails.country_id
LEFT JOIN  modesoftransport   on modesoftransport.id                    = plannedconsignments_tpdetails.modesoftransport_id
LEFT JOIN  exportcompanies    on exportcompanies.id                     = plannedconsignments.exportcompany_id
LEFT JOIN  packhouse_exporter on packhouse_exporter.exportcompany_id    = plannedconsignments.exportcompany_id
LEFT JOIN  packhouses         on packhouses.id    = packhouse_exporter.packhouse_id
WHERE plannedconsignments.created_at BETWEEN TO_TIMESTAMP($1, 'YYYY-MM-DD HH24:MI:SS')
AND   TO_TIMESTAMP($2, 'YYYY-MM-DD HH24:MI:SS')
ORDER BY plannedconsignments.created_at DESC LIMIT $3 OFFSET $4
`

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

type ListAllCompaniesDateFiltersConsignmentReportsRow struct {
	StartDate          string         `json:"start_date"`
	Phname             sql.NullString `json:"phname"`
	Expregno           sql.NullString `json:"expregno"`
	Exprexno           sql.NullString `json:"exprexno"`
	ConsignmentNo      string         `json:"consignment_no"`
	Exhdescription     sql.NullString `json:"exhdescription"`
	Expdescription     sql.NullString `json:"expdescription"`
	Countryname        sql.NullString `json:"countryname"`
	Motdescription     sql.NullString `json:"motdescription"`
	Airlinename        sql.NullString `json:"airlinename"`
	CountryID          sql.NullInt32  `json:"country_id"`
	ModesoftransportID sql.NullInt32  `json:"modesoftransport_id"`
	ExitDate           sql.NullTime   `json:"exit_date"`
	ExitpointID        sql.NullInt32  `json:"exitpoint_id"`
	AirlineID          sql.NullInt32  `json:"airline_id"`
	ExithandlerID      sql.NullInt32  `json:"exithandler_id"`
	EndDate            string         `json:"end_date"`
	UserID             int32          `json:"user_id"`
	ExportcompanyID    int32          `json:"exportcompany_id"`
	Status             string         `json:"status"`
	CreatedAt          time.Time      `json:"created_at"`
	OrderID            sql.NullInt64  `json:"order_id"`
	Expname            sql.NullString `json:"expname"`
	Logo               sql.NullString `json:"logo"`
}

func (q *Queries) ListAllCompaniesDateFiltersConsignmentReports(ctx context.Context, arg ListAllCompaniesDateFiltersConsignmentReportsParams) ([]ListAllCompaniesDateFiltersConsignmentReportsRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesDateFiltersConsignmentReports,
		arg.ToTimestamp,
		arg.ToTimestamp_2,
		arg.Limit,
		arg.Offset,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesDateFiltersConsignmentReportsRow{}
	for rows.Next() {
		var i ListAllCompaniesDateFiltersConsignmentReportsRow
		if err := rows.Scan(
			&i.StartDate,
			&i.Phname,
			&i.Expregno,
			&i.Exprexno,
			&i.ConsignmentNo,
			&i.Exhdescription,
			&i.Expdescription,
			&i.Countryname,
			&i.Motdescription,
			&i.Airlinename,
			&i.CountryID,
			&i.ModesoftransportID,
			&i.ExitDate,
			&i.ExitpointID,
			&i.AirlineID,
			&i.ExithandlerID,
			&i.EndDate,
			&i.UserID,
			&i.ExportcompanyID,
			&i.Status,
			&i.CreatedAt,
			&i.OrderID,
			&i.Expname,
			&i.Logo,
		); 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 listAllCompaniesGlobalConsignmentReports = `-- name: ListAllCompaniesGlobalConsignmentReports :many
SELECT plannedconsignments.start_date,packhouses.phname,
exportcompanies.expregno,exportcompanies.exprexno,
plannedconsignments.id as consignment_no,
exithandlers.exhdescription,exitpoints.expdescription,
countries.countryname,modesoftransport.motdescription,airlines.airlinename,
plannedconsignments_tpdetails.country_id,plannedconsignments_tpdetails.modesoftransport_id,
plannedconsignments_tpdetails.exit_date,plannedconsignments_tpdetails.exitpoint_id,
plannedconsignments_tpdetails.airline_id,plannedconsignments_tpdetails.exithandler_id,
plannedconsignments.end_date,plannedconsignments.user_id,plannedconsignments.exportcompany_id,
plannedconsignments.status,plannedconsignments.created_at,orders.id order_id,exportcompanies.expname,exportcompanies.logo FROM plannedconsignments
LEFT JOIN  plannedconsignments_tpdetails on plannedconsignments_tpdetails.plannedconsignments_id = plannedconsignments.id
LEFT JOIN  orders             on orders.consignment_no         = plannedconsignments.id
LEFT JOIN  exitpoints         on exitpoints.id                 = plannedconsignments_tpdetails.exitpoint_id
LEFT JOIN  airlines           on airlines.id                   = plannedconsignments_tpdetails.airline_id
LEFT JOIN  exithandlers       on exithandlers.id               = plannedconsignments_tpdetails.exithandler_id
LEFT JOIN  countries          on countries.id                  = plannedconsignments_tpdetails.country_id
LEFT JOIN  modesoftransport   on modesoftransport.id                    = plannedconsignments_tpdetails.modesoftransport_id
LEFT JOIN  exportcompanies    on exportcompanies.id                     = plannedconsignments.exportcompany_id
LEFT JOIN  packhouse_exporter on packhouse_exporter.exportcompany_id    = plannedconsignments.exportcompany_id
LEFT JOIN  packhouses         on packhouses.id    = packhouse_exporter.packhouse_id
ORDER BY plannedconsignments.created_at DESC LIMIT $1 OFFSET $2
`

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

type ListAllCompaniesGlobalConsignmentReportsRow struct {
	StartDate          string         `json:"start_date"`
	Phname             sql.NullString `json:"phname"`
	Expregno           sql.NullString `json:"expregno"`
	Exprexno           sql.NullString `json:"exprexno"`
	ConsignmentNo      string         `json:"consignment_no"`
	Exhdescription     sql.NullString `json:"exhdescription"`
	Expdescription     sql.NullString `json:"expdescription"`
	Countryname        sql.NullString `json:"countryname"`
	Motdescription     sql.NullString `json:"motdescription"`
	Airlinename        sql.NullString `json:"airlinename"`
	CountryID          sql.NullInt32  `json:"country_id"`
	ModesoftransportID sql.NullInt32  `json:"modesoftransport_id"`
	ExitDate           sql.NullTime   `json:"exit_date"`
	ExitpointID        sql.NullInt32  `json:"exitpoint_id"`
	AirlineID          sql.NullInt32  `json:"airline_id"`
	ExithandlerID      sql.NullInt32  `json:"exithandler_id"`
	EndDate            string         `json:"end_date"`
	UserID             int32          `json:"user_id"`
	ExportcompanyID    int32          `json:"exportcompany_id"`
	Status             string         `json:"status"`
	CreatedAt          time.Time      `json:"created_at"`
	OrderID            sql.NullInt64  `json:"order_id"`
	Expname            sql.NullString `json:"expname"`
	Logo               sql.NullString `json:"logo"`
}

func (q *Queries) ListAllCompaniesGlobalConsignmentReports(ctx context.Context, arg ListAllCompaniesGlobalConsignmentReportsParams) ([]ListAllCompaniesGlobalConsignmentReportsRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesGlobalConsignmentReports, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesGlobalConsignmentReportsRow{}
	for rows.Next() {
		var i ListAllCompaniesGlobalConsignmentReportsRow
		if err := rows.Scan(
			&i.StartDate,
			&i.Phname,
			&i.Expregno,
			&i.Exprexno,
			&i.ConsignmentNo,
			&i.Exhdescription,
			&i.Expdescription,
			&i.Countryname,
			&i.Motdescription,
			&i.Airlinename,
			&i.CountryID,
			&i.ModesoftransportID,
			&i.ExitDate,
			&i.ExitpointID,
			&i.AirlineID,
			&i.ExithandlerID,
			&i.EndDate,
			&i.UserID,
			&i.ExportcompanyID,
			&i.Status,
			&i.CreatedAt,
			&i.OrderID,
			&i.Expname,
			&i.Logo,
		); 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 listAllCompaniesMultipleConsignmentReports = `-- name: ListAllCompaniesMultipleConsignmentReports :many
SELECT plannedconsignments.start_date,packhouses.phname,
exportcompanies.expregno,exportcompanies.exprexno,
plannedconsignments.id as consignment_no,
exithandlers.exhdescription,exitpoints.expdescription,
countries.countryname,modesoftransport.motdescription,airlines.airlinename,
plannedconsignments_tpdetails.country_id,plannedconsignments_tpdetails.modesoftransport_id,
plannedconsignments_tpdetails.exit_date,plannedconsignments_tpdetails.exitpoint_id,
plannedconsignments_tpdetails.airline_id,plannedconsignments_tpdetails.exithandler_id,
plannedconsignments.end_date,plannedconsignments.user_id,plannedconsignments.exportcompany_id,
plannedconsignments.status,plannedconsignments.created_at,orders.id order_id,exportcompanies.expname,exportcompanies.logo FROM plannedconsignments
LEFT JOIN  plannedconsignments_tpdetails on plannedconsignments_tpdetails.plannedconsignments_id = plannedconsignments.id
LEFT JOIN  orders             on orders.consignment_no         = plannedconsignments.id
LEFT JOIN  exitpoints         on exitpoints.id                 = plannedconsignments_tpdetails.exitpoint_id
LEFT JOIN  airlines           on airlines.id                   = plannedconsignments_tpdetails.airline_id
LEFT JOIN  exithandlers       on exithandlers.id               = plannedconsignments_tpdetails.exithandler_id
LEFT JOIN  countries          on countries.id                  = plannedconsignments_tpdetails.country_id
LEFT JOIN  modesoftransport   on modesoftransport.id                    = plannedconsignments_tpdetails.modesoftransport_id
LEFT JOIN  exportcompanies    on exportcompanies.id                     = plannedconsignments.exportcompany_id
LEFT JOIN  packhouse_exporter on packhouse_exporter.exportcompany_id    = plannedconsignments.exportcompany_id
LEFT JOIN  packhouses         on packhouses.id    = packhouse_exporter.packhouse_id
WHERE plannedconsignments.status =  ANY($1::text[])
ORDER BY plannedconsignments.created_at DESC LIMIT $2 OFFSET $3
`

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

type ListAllCompaniesMultipleConsignmentReportsRow struct {
	StartDate          string         `json:"start_date"`
	Phname             sql.NullString `json:"phname"`
	Expregno           sql.NullString `json:"expregno"`
	Exprexno           sql.NullString `json:"exprexno"`
	ConsignmentNo      string         `json:"consignment_no"`
	Exhdescription     sql.NullString `json:"exhdescription"`
	Expdescription     sql.NullString `json:"expdescription"`
	Countryname        sql.NullString `json:"countryname"`
	Motdescription     sql.NullString `json:"motdescription"`
	Airlinename        sql.NullString `json:"airlinename"`
	CountryID          sql.NullInt32  `json:"country_id"`
	ModesoftransportID sql.NullInt32  `json:"modesoftransport_id"`
	ExitDate           sql.NullTime   `json:"exit_date"`
	ExitpointID        sql.NullInt32  `json:"exitpoint_id"`
	AirlineID          sql.NullInt32  `json:"airline_id"`
	ExithandlerID      sql.NullInt32  `json:"exithandler_id"`
	EndDate            string         `json:"end_date"`
	UserID             int32          `json:"user_id"`
	ExportcompanyID    int32          `json:"exportcompany_id"`
	Status             string         `json:"status"`
	CreatedAt          time.Time      `json:"created_at"`
	OrderID            sql.NullInt64  `json:"order_id"`
	Expname            sql.NullString `json:"expname"`
	Logo               sql.NullString `json:"logo"`
}

func (q *Queries) ListAllCompaniesMultipleConsignmentReports(ctx context.Context, arg ListAllCompaniesMultipleConsignmentReportsParams) ([]ListAllCompaniesMultipleConsignmentReportsRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesMultipleConsignmentReports, pq.Array(arg.Column1), arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesMultipleConsignmentReportsRow{}
	for rows.Next() {
		var i ListAllCompaniesMultipleConsignmentReportsRow
		if err := rows.Scan(
			&i.StartDate,
			&i.Phname,
			&i.Expregno,
			&i.Exprexno,
			&i.ConsignmentNo,
			&i.Exhdescription,
			&i.Expdescription,
			&i.Countryname,
			&i.Motdescription,
			&i.Airlinename,
			&i.CountryID,
			&i.ModesoftransportID,
			&i.ExitDate,
			&i.ExitpointID,
			&i.AirlineID,
			&i.ExithandlerID,
			&i.EndDate,
			&i.UserID,
			&i.ExportcompanyID,
			&i.Status,
			&i.CreatedAt,
			&i.OrderID,
			&i.Expname,
			&i.Logo,
		); 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 listAllCompaniesSingleConsignmentReports = `-- name: ListAllCompaniesSingleConsignmentReports :many
SELECT plannedconsignments.start_date,packhouses.phname,
exportcompanies.expregno,exportcompanies.exprexno,
plannedconsignments.id as consignment_no,
exithandlers.exhdescription,exitpoints.expdescription,
countries.countryname,modesoftransport.motdescription,airlines.airlinename,
plannedconsignments_tpdetails.country_id,plannedconsignments_tpdetails.modesoftransport_id,
plannedconsignments_tpdetails.exit_date,plannedconsignments_tpdetails.exitpoint_id,
plannedconsignments_tpdetails.airline_id,plannedconsignments_tpdetails.exithandler_id,
plannedconsignments.end_date,plannedconsignments.user_id,plannedconsignments.exportcompany_id,
plannedconsignments.status,plannedconsignments.created_at,orders.id order_id,exportcompanies.expname,exportcompanies.logo FROM plannedconsignments
LEFT JOIN  plannedconsignments_tpdetails on plannedconsignments_tpdetails.plannedconsignments_id = plannedconsignments.id
LEFT JOIN  orders             on orders.consignment_no         = plannedconsignments.id
LEFT JOIN  exitpoints         on exitpoints.id                 = plannedconsignments_tpdetails.exitpoint_id
LEFT JOIN  airlines           on airlines.id                   = plannedconsignments_tpdetails.airline_id
LEFT JOIN  exithandlers       on exithandlers.id               = plannedconsignments_tpdetails.exithandler_id
LEFT JOIN  countries          on countries.id                  = plannedconsignments_tpdetails.country_id
LEFT JOIN  modesoftransport   on modesoftransport.id                    = plannedconsignments_tpdetails.modesoftransport_id
LEFT JOIN  exportcompanies    on exportcompanies.id                     = plannedconsignments.exportcompany_id
LEFT JOIN  packhouse_exporter on packhouse_exporter.exportcompany_id    = plannedconsignments.exportcompany_id
LEFT JOIN  packhouses         on packhouses.id    = packhouse_exporter.packhouse_id
WHERE plannedconsignments.status =  $1
ORDER BY plannedconsignments.created_at DESC LIMIT $2 OFFSET $3
`

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

type ListAllCompaniesSingleConsignmentReportsRow struct {
	StartDate          string         `json:"start_date"`
	Phname             sql.NullString `json:"phname"`
	Expregno           sql.NullString `json:"expregno"`
	Exprexno           sql.NullString `json:"exprexno"`
	ConsignmentNo      string         `json:"consignment_no"`
	Exhdescription     sql.NullString `json:"exhdescription"`
	Expdescription     sql.NullString `json:"expdescription"`
	Countryname        sql.NullString `json:"countryname"`
	Motdescription     sql.NullString `json:"motdescription"`
	Airlinename        sql.NullString `json:"airlinename"`
	CountryID          sql.NullInt32  `json:"country_id"`
	ModesoftransportID sql.NullInt32  `json:"modesoftransport_id"`
	ExitDate           sql.NullTime   `json:"exit_date"`
	ExitpointID        sql.NullInt32  `json:"exitpoint_id"`
	AirlineID          sql.NullInt32  `json:"airline_id"`
	ExithandlerID      sql.NullInt32  `json:"exithandler_id"`
	EndDate            string         `json:"end_date"`
	UserID             int32          `json:"user_id"`
	ExportcompanyID    int32          `json:"exportcompany_id"`
	Status             string         `json:"status"`
	CreatedAt          time.Time      `json:"created_at"`
	OrderID            sql.NullInt64  `json:"order_id"`
	Expname            sql.NullString `json:"expname"`
	Logo               sql.NullString `json:"logo"`
}

func (q *Queries) ListAllCompaniesSingleConsignmentReports(ctx context.Context, arg ListAllCompaniesSingleConsignmentReportsParams) ([]ListAllCompaniesSingleConsignmentReportsRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllCompaniesSingleConsignmentReports, arg.Status, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllCompaniesSingleConsignmentReportsRow{}
	for rows.Next() {
		var i ListAllCompaniesSingleConsignmentReportsRow
		if err := rows.Scan(
			&i.StartDate,
			&i.Phname,
			&i.Expregno,
			&i.Exprexno,
			&i.ConsignmentNo,
			&i.Exhdescription,
			&i.Expdescription,
			&i.Countryname,
			&i.Motdescription,
			&i.Airlinename,
			&i.CountryID,
			&i.ModesoftransportID,
			&i.ExitDate,
			&i.ExitpointID,
			&i.AirlineID,
			&i.ExithandlerID,
			&i.EndDate,
			&i.UserID,
			&i.ExportcompanyID,
			&i.Status,
			&i.CreatedAt,
			&i.OrderID,
			&i.Expname,
			&i.Logo,
		); 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 listAllPlannedConsigments = `-- name: ListAllPlannedConsigments :many
SELECT plannedconsignments.start_date,plannedconsignments.end_date, plannedconsignments.id consignment_no,
plannedconsignments.created_at,plannedconsignments.status,exportcompanies.expname,
packhouses.phname,orders.status order_status,clients.companyname,countries.countryname,orders.created_at order_created_at,orders.id FROM plannedconsignments
LEFT JOIN exportcompanies on exportcompanies.id = plannedconsignments.exportcompany_id
LEFT JOIN packhouse_exporter on packhouse_exporter.exportcompany_id = exportcompanies.id
LEFT JOIN packhouses on packhouses.id = packhouse_exporter.packhouse_id
LEFT JOIN orders     on orders.consignment_no = plannedconsignments.id
LEFT JOIN clients    on clients.id       = orders.client_id
LEFT JOIN countries  on countries.id     = clients.country_id
WHERE    plannedconsignments.exportcompany_id = $4
AND      plannedconsignments.status = $3
ORDER BY plannedconsignments.created_at DESC
LIMIT $1 OFFSET $2
`

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

type ListAllPlannedConsigmentsRow struct {
	StartDate      string         `json:"start_date"`
	EndDate        string         `json:"end_date"`
	ConsignmentNo  string         `json:"consignment_no"`
	CreatedAt      time.Time      `json:"created_at"`
	Status         string         `json:"status"`
	Expname        sql.NullString `json:"expname"`
	Phname         sql.NullString `json:"phname"`
	OrderStatus    sql.NullString `json:"order_status"`
	Companyname    sql.NullString `json:"companyname"`
	Countryname    sql.NullString `json:"countryname"`
	OrderCreatedAt sql.NullTime   `json:"order_created_at"`
	ID             sql.NullInt64  `json:"id"`
}

func (q *Queries) ListAllPlannedConsigments(ctx context.Context, arg ListAllPlannedConsigmentsParams) ([]ListAllPlannedConsigmentsRow, error) {
	rows, err := q.db.QueryContext(ctx, listAllPlannedConsigments,
		arg.Limit,
		arg.Offset,
		arg.Status,
		arg.ExportcompanyID,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAllPlannedConsigmentsRow{}
	for rows.Next() {
		var i ListAllPlannedConsigmentsRow
		if err := rows.Scan(
			&i.StartDate,
			&i.EndDate,
			&i.ConsignmentNo,
			&i.CreatedAt,
			&i.Status,
			&i.Expname,
			&i.Phname,
			&i.OrderStatus,
			&i.Companyname,
			&i.Countryname,
			&i.OrderCreatedAt,
			&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 listAwaitedBoarderPlannedConsigments = `-- name: ListAwaitedBoarderPlannedConsigments :many
SELECT plannedconsignments.start_date,plannedconsignments_tpdetails.exit_date,plannedconsignments.end_date,plannedconsignments.id consignment_no,
plannedconsignments.created_at,plannedconsignments.status,exportcompanies.expname,packhouses.phname FROM plannedconsignments
LEFT JOIN plannedconsignments_tpdetails on plannedconsignments_tpdetails.plannedconsignments_id = plannedconsignments.id
LEFT JOIN exportcompanies on exportcompanies.id = plannedconsignments.exportcompany_id
LEFT JOIN packhouse_exporter on packhouse_exporter.exportcompany_id = exportcompanies.id
LEFT JOIN packhouses on packhouses.id  = packhouse_exporter.packhouse_id
WHERE plannedconsignments.status IN ('AwaitingUpdateDestination','AwaitingBorderInspection', 'AwaitingPackinglistUpdate','FitForExport','AwaitingReDocumentation')
ORDER BY plannedconsignments.created_at DESC
`

type ListAwaitedBoarderPlannedConsigmentsRow struct {
	StartDate     string         `json:"start_date"`
	ExitDate      sql.NullTime   `json:"exit_date"`
	EndDate       string         `json:"end_date"`
	ConsignmentNo string         `json:"consignment_no"`
	CreatedAt     time.Time      `json:"created_at"`
	Status        string         `json:"status"`
	Expname       sql.NullString `json:"expname"`
	Phname        sql.NullString `json:"phname"`
}

func (q *Queries) ListAwaitedBoarderPlannedConsigments(ctx context.Context) ([]ListAwaitedBoarderPlannedConsigmentsRow, error) {
	rows, err := q.db.QueryContext(ctx, listAwaitedBoarderPlannedConsigments)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAwaitedBoarderPlannedConsigmentsRow{}
	for rows.Next() {
		var i ListAwaitedBoarderPlannedConsigmentsRow
		if err := rows.Scan(
			&i.StartDate,
			&i.ExitDate,
			&i.EndDate,
			&i.ConsignmentNo,
			&i.CreatedAt,
			&i.Status,
			&i.Expname,
			&i.Phname,
		); 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 listAwaitedBoarderPlannedConsigmentsPaginated = `-- name: ListAwaitedBoarderPlannedConsigmentsPaginated :many
SELECT DISTINCT ON (plannedconsignments.id)
    plannedconsignments.id AS consignment_no,
    plannedconsignments.start_date,
    plannedconsignments_tpdetails.exit_date,
    plannedconsignments.end_date,
    plannedconsignments.created_at,
    plannedconsignments.status,
    exportcompanies.expname,
    packhouses.phname
FROM plannedconsignments
LEFT JOIN plannedconsignments_tpdetails
    ON plannedconsignments_tpdetails.plannedconsignments_id = plannedconsignments.id
LEFT JOIN exportcompanies
    ON exportcompanies.id = plannedconsignments.exportcompany_id
LEFT JOIN packhouse_exporter
    ON packhouse_exporter.exportcompany_id = exportcompanies.id
LEFT JOIN packhouses
    ON packhouses.id = packhouse_exporter.packhouse_id
WHERE plannedconsignments.status IN (
    'AwaitingUpdateDestination',
    'AwaitingBorderInspection',
    'AwaitingPackinglistUpdate',
    'FitForExport',
    'AwaitingReDocumentation'
)
ORDER BY plannedconsignments.id, plannedconsignments.created_at DESC
LIMIT $1 OFFSET $2
`

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

type ListAwaitedBoarderPlannedConsigmentsPaginatedRow struct {
	ConsignmentNo string         `json:"consignment_no"`
	StartDate     string         `json:"start_date"`
	ExitDate      sql.NullTime   `json:"exit_date"`
	EndDate       string         `json:"end_date"`
	CreatedAt     time.Time      `json:"created_at"`
	Status        string         `json:"status"`
	Expname       sql.NullString `json:"expname"`
	Phname        sql.NullString `json:"phname"`
}

func (q *Queries) ListAwaitedBoarderPlannedConsigmentsPaginated(ctx context.Context, arg ListAwaitedBoarderPlannedConsigmentsPaginatedParams) ([]ListAwaitedBoarderPlannedConsigmentsPaginatedRow, error) {
	rows, err := q.db.QueryContext(ctx, listAwaitedBoarderPlannedConsigmentsPaginated, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAwaitedBoarderPlannedConsigmentsPaginatedRow{}
	for rows.Next() {
		var i ListAwaitedBoarderPlannedConsigmentsPaginatedRow
		if err := rows.Scan(
			&i.ConsignmentNo,
			&i.StartDate,
			&i.ExitDate,
			&i.EndDate,
			&i.CreatedAt,
			&i.Status,
			&i.Expname,
			&i.Phname,
		); 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 listAwaitingBorderInspectionConsigments = `-- name: ListAwaitingBorderInspectionConsigments :many
SELECT DISTINCT plannedconsignments.id consignment_no,plannedconsignments.start_date,plannedconsignments.end_date,
plannedconsignments.created_at,plannedconsignments.status,exportcompanies.expname,packhouses.phname FROM plannedconsignments
LEFT JOIN exportcompanies on exportcompanies.id = plannedconsignments.exportcompany_id
LEFT JOIN packhouse_exporter on packhouse_exporter.exportcompany_id = exportcompanies.id
LEFT JOIN packhouses on packhouses.id = packhouse_exporter.packhouse_id
WHERE plannedconsignments.exportcompany_id = $1
AND   plannedconsignments.status = 'AwaitingBorderInspection'
ORDER BY plannedconsignments.created_at DESC
LIMIT $2 OFFSET $3
`

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

type ListAwaitingBorderInspectionConsigmentsRow struct {
	ConsignmentNo string         `json:"consignment_no"`
	StartDate     string         `json:"start_date"`
	EndDate       string         `json:"end_date"`
	CreatedAt     time.Time      `json:"created_at"`
	Status        string         `json:"status"`
	Expname       sql.NullString `json:"expname"`
	Phname        sql.NullString `json:"phname"`
}

func (q *Queries) ListAwaitingBorderInspectionConsigments(ctx context.Context, arg ListAwaitingBorderInspectionConsigmentsParams) ([]ListAwaitingBorderInspectionConsigmentsRow, error) {
	rows, err := q.db.QueryContext(ctx, listAwaitingBorderInspectionConsigments, arg.ExportcompanyID, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListAwaitingBorderInspectionConsigmentsRow{}
	for rows.Next() {
		var i ListAwaitingBorderInspectionConsigmentsRow
		if err := rows.Scan(
			&i.ConsignmentNo,
			&i.StartDate,
			&i.EndDate,
			&i.CreatedAt,
			&i.Status,
			&i.Expname,
			&i.Phname,
		); 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 listCompletedBoarderPlannedConsigments = `-- name: ListCompletedBoarderPlannedConsigments :many
SELECT plannedconsignments.start_date,plannedconsignments_tpdetails.exit_date,plannedconsignments.end_date,plannedconsignments.id consignment_no,
plannedconsignments.created_at,plannedconsignments.status,exportcompanies.expname,packhouses.phname FROM plannedconsignments
LEFT JOIN plannedconsignments_tpdetails on plannedconsignments_tpdetails.plannedconsignments_id = plannedconsignments.id
LEFT JOIN exportcompanies on exportcompanies.id = plannedconsignments.exportcompany_id
LEFT JOIN packhouse_exporter on packhouse_exporter.exportcompany_id = exportcompanies.id
LEFT JOIN packhouses on packhouses.id  = packhouse_exporter.packhouse_id
WHERE plannedconsignments.status = 'Completed'
ORDER BY plannedconsignments.created_at DESC
`

type ListCompletedBoarderPlannedConsigmentsRow struct {
	StartDate     string         `json:"start_date"`
	ExitDate      sql.NullTime   `json:"exit_date"`
	EndDate       string         `json:"end_date"`
	ConsignmentNo string         `json:"consignment_no"`
	CreatedAt     time.Time      `json:"created_at"`
	Status        string         `json:"status"`
	Expname       sql.NullString `json:"expname"`
	Phname        sql.NullString `json:"phname"`
}

func (q *Queries) ListCompletedBoarderPlannedConsigments(ctx context.Context) ([]ListCompletedBoarderPlannedConsigmentsRow, error) {
	rows, err := q.db.QueryContext(ctx, listCompletedBoarderPlannedConsigments)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListCompletedBoarderPlannedConsigmentsRow{}
	for rows.Next() {
		var i ListCompletedBoarderPlannedConsigmentsRow
		if err := rows.Scan(
			&i.StartDate,
			&i.ExitDate,
			&i.EndDate,
			&i.ConsignmentNo,
			&i.CreatedAt,
			&i.Status,
			&i.Expname,
			&i.Phname,
		); 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 listCompletedBoarderPlannedConsigmentsPaginated = `-- name: ListCompletedBoarderPlannedConsigmentsPaginated :many
SELECT plannedconsignments.start_date,plannedconsignments_tpdetails.exit_date,plannedconsignments.end_date,plannedconsignments.id consignment_no,
plannedconsignments.created_at,plannedconsignments.status,exportcompanies.expname,packhouses.phname FROM plannedconsignments
LEFT JOIN plannedconsignments_tpdetails on plannedconsignments_tpdetails.plannedconsignments_id = plannedconsignments.id
LEFT JOIN exportcompanies on exportcompanies.id = plannedconsignments.exportcompany_id
LEFT JOIN packhouse_exporter on packhouse_exporter.exportcompany_id = exportcompanies.id
LEFT JOIN packhouses on packhouses.id  = packhouse_exporter.packhouse_id
WHERE
    plannedconsignments.status IN ('Completed')
ORDER BY
    plannedconsignments.created_at DESC
LIMIT
    $1 OFFSET $2
`

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

type ListCompletedBoarderPlannedConsigmentsPaginatedRow struct {
	StartDate     string         `json:"start_date"`
	ExitDate      sql.NullTime   `json:"exit_date"`
	EndDate       string         `json:"end_date"`
	ConsignmentNo string         `json:"consignment_no"`
	CreatedAt     time.Time      `json:"created_at"`
	Status        string         `json:"status"`
	Expname       sql.NullString `json:"expname"`
	Phname        sql.NullString `json:"phname"`
}

func (q *Queries) ListCompletedBoarderPlannedConsigmentsPaginated(ctx context.Context, arg ListCompletedBoarderPlannedConsigmentsPaginatedParams) ([]ListCompletedBoarderPlannedConsigmentsPaginatedRow, error) {
	rows, err := q.db.QueryContext(ctx, listCompletedBoarderPlannedConsigmentsPaginated, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListCompletedBoarderPlannedConsigmentsPaginatedRow{}
	for rows.Next() {
		var i ListCompletedBoarderPlannedConsigmentsPaginatedRow
		if err := rows.Scan(
			&i.StartDate,
			&i.ExitDate,
			&i.EndDate,
			&i.ConsignmentNo,
			&i.CreatedAt,
			&i.Status,
			&i.Expname,
			&i.Phname,
		); 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 listCompletedPlannedConsigments = `-- name: ListCompletedPlannedConsigments :many
SELECT plannedconsignments.start_date,plannedconsignments.end_date,plannedconsignments.id consignment_no,
plannedconsignments.created_at,plannedconsignments.status,exportcompanies.expname,packhouses.phname FROM plannedconsignments
LEFT JOIN exportcompanies on exportcompanies.id = plannedconsignments.exportcompany_id
LEFT JOIN packhouse_exporter on packhouse_exporter.exportcompany_id = exportcompanies.id
LEFT JOIN packhouses on packhouses.id = packhouse_exporter.packhouse_id
WHERE plannedconsignments.exportcompany_id = $1
AND plannedconsignments.status = $2
ORDER BY plannedconsignments.created_at DESC
`

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

type ListCompletedPlannedConsigmentsRow struct {
	StartDate     string         `json:"start_date"`
	EndDate       string         `json:"end_date"`
	ConsignmentNo string         `json:"consignment_no"`
	CreatedAt     time.Time      `json:"created_at"`
	Status        string         `json:"status"`
	Expname       sql.NullString `json:"expname"`
	Phname        sql.NullString `json:"phname"`
}

func (q *Queries) ListCompletedPlannedConsigments(ctx context.Context, arg ListCompletedPlannedConsigmentsParams) ([]ListCompletedPlannedConsigmentsRow, error) {
	rows, err := q.db.QueryContext(ctx, listCompletedPlannedConsigments, arg.ExportcompanyID, arg.Status)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListCompletedPlannedConsigmentsRow{}
	for rows.Next() {
		var i ListCompletedPlannedConsigmentsRow
		if err := rows.Scan(
			&i.StartDate,
			&i.EndDate,
			&i.ConsignmentNo,
			&i.CreatedAt,
			&i.Status,
			&i.Expname,
			&i.Phname,
		); 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 listPlannedConsigments = `-- name: ListPlannedConsigments :many
SELECT plannedconsignments.start_date,plannedconsignments.end_date,plannedconsignments.id consignment_no,
plannedconsignments.created_at,plannedconsignments.status,exportcompanies.expname FROM plannedconsignments
JOIN  exportcompanies    on exportcompanies.id                  = plannedconsignments.exportcompany_id
JOIN  packhouse_exporter on packhouse_exporter.exportcompany_id = plannedconsignments.exportcompany_id
JOIN  packhouses         on packhouses.id                       = packhouse_exporter.packhouse_id
WHERE plannedconsignments.exportcompany_id              = $1
AND   plannedconsignments.status  = $2
ORDER BY plannedconsignments.created_at DESC
LIMIT $3 OFFSET $4
`

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

type ListPlannedConsigmentsRow struct {
	StartDate     string    `json:"start_date"`
	EndDate       string    `json:"end_date"`
	ConsignmentNo string    `json:"consignment_no"`
	CreatedAt     time.Time `json:"created_at"`
	Status        string    `json:"status"`
	Expname       string    `json:"expname"`
}

func (q *Queries) ListPlannedConsigments(ctx context.Context, arg ListPlannedConsigmentsParams) ([]ListPlannedConsigmentsRow, error) {
	rows, err := q.db.QueryContext(ctx, listPlannedConsigments,
		arg.ExportcompanyID,
		arg.Status,
		arg.Limit,
		arg.Offset,
	)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListPlannedConsigmentsRow{}
	for rows.Next() {
		var i ListPlannedConsigmentsRow
		if err := rows.Scan(
			&i.StartDate,
			&i.EndDate,
			&i.ConsignmentNo,
			&i.CreatedAt,
			&i.Status,
			&i.Expname,
		); 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 listQueriedPlannedConsigments = `-- name: ListQueriedPlannedConsigments :many
SELECT plannedconsignments.start_date,plannedconsignments.end_date,plannedconsignments.id consignment_no,
plannedconsignments.created_at,plannedconsignments.status,exportcompanies.expname,packhouses.phname FROM plannedconsignments
LEFT JOIN exportcompanies on exportcompanies.id = plannedconsignments.exportcompany_id
LEFT JOIN packhouse_exporter on packhouse_exporter.exportcompany_id = exportcompanies.id
LEFT JOIN packhouses on packhouses.id = packhouse_exporter.packhouse_id
WHERE plannedconsignments.exportcompany_id = $1
AND plannedconsignments.status = $2
ORDER BY plannedconsignments.created_at DESC
`

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

type ListQueriedPlannedConsigmentsRow struct {
	StartDate     string         `json:"start_date"`
	EndDate       string         `json:"end_date"`
	ConsignmentNo string         `json:"consignment_no"`
	CreatedAt     time.Time      `json:"created_at"`
	Status        string         `json:"status"`
	Expname       sql.NullString `json:"expname"`
	Phname        sql.NullString `json:"phname"`
}

func (q *Queries) ListQueriedPlannedConsigments(ctx context.Context, arg ListQueriedPlannedConsigmentsParams) ([]ListQueriedPlannedConsigmentsRow, error) {
	rows, err := q.db.QueryContext(ctx, listQueriedPlannedConsigments, arg.ExportcompanyID, arg.Status)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListQueriedPlannedConsigmentsRow{}
	for rows.Next() {
		var i ListQueriedPlannedConsigmentsRow
		if err := rows.Scan(
			&i.StartDate,
			&i.EndDate,
			&i.ConsignmentNo,
			&i.CreatedAt,
			&i.Status,
			&i.Expname,
			&i.Phname,
		); 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 listRejectedPlannedConsigments = `-- name: ListRejectedPlannedConsigments :many
SELECT plannedconsignments.start_date,plannedconsignments.end_date,plannedconsignments.id consignment_no,
plannedconsignments.created_at,plannedconsignments.status,exportcompanies.expname,packhouses.phname FROM plannedconsignments
LEFT JOIN exportcompanies on exportcompanies.id = plannedconsignments.exportcompany_id
LEFT JOIN packhouse_exporter on packhouse_exporter.exportcompany_id = exportcompanies.id
LEFT JOIN packhouses on packhouses.id = packhouse_exporter.packhouse_id
WHERE plannedconsignments.exportcompany_id = $1
AND plannedconsignments.status = $2
ORDER BY plannedconsignments.created_at DESC
`

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

type ListRejectedPlannedConsigmentsRow struct {
	StartDate     string         `json:"start_date"`
	EndDate       string         `json:"end_date"`
	ConsignmentNo string         `json:"consignment_no"`
	CreatedAt     time.Time      `json:"created_at"`
	Status        string         `json:"status"`
	Expname       sql.NullString `json:"expname"`
	Phname        sql.NullString `json:"phname"`
}

func (q *Queries) ListRejectedPlannedConsigments(ctx context.Context, arg ListRejectedPlannedConsigmentsParams) ([]ListRejectedPlannedConsigmentsRow, error) {
	rows, err := q.db.QueryContext(ctx, listRejectedPlannedConsigments, arg.ExportcompanyID, arg.Status)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListRejectedPlannedConsigmentsRow{}
	for rows.Next() {
		var i ListRejectedPlannedConsigmentsRow
		if err := rows.Scan(
			&i.StartDate,
			&i.EndDate,
			&i.ConsignmentNo,
			&i.CreatedAt,
			&i.Status,
			&i.Expname,
			&i.Phname,
		); 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 listStoppedBoarderPlannedConsigments = `-- name: ListStoppedBoarderPlannedConsigments :many
SELECT plannedconsignments.start_date,plannedconsignments_tpdetails.exit_date,plannedconsignments.end_date,plannedconsignments.id consignment_no,
plannedconsignments.created_at,plannedconsignments.status,exportcompanies.expname,packhouses.phname FROM plannedconsignments
LEFT JOIN plannedconsignments_tpdetails on plannedconsignments_tpdetails.plannedconsignments_id = plannedconsignments.id
LEFT JOIN exportcompanies on exportcompanies.id = plannedconsignments.exportcompany_id
LEFT JOIN packhouse_exporter on packhouse_exporter.exportcompany_id = exportcompanies.id
LEFT JOIN packhouses on packhouses.id  = packhouse_exporter.packhouse_id
WHERE plannedconsignments.status IN ('Rejected', 'Retreatment', 'Destroyed')
ORDER BY plannedconsignments.created_at DESC
`

type ListStoppedBoarderPlannedConsigmentsRow struct {
	StartDate     string         `json:"start_date"`
	ExitDate      sql.NullTime   `json:"exit_date"`
	EndDate       string         `json:"end_date"`
	ConsignmentNo string         `json:"consignment_no"`
	CreatedAt     time.Time      `json:"created_at"`
	Status        string         `json:"status"`
	Expname       sql.NullString `json:"expname"`
	Phname        sql.NullString `json:"phname"`
}

func (q *Queries) ListStoppedBoarderPlannedConsigments(ctx context.Context) ([]ListStoppedBoarderPlannedConsigmentsRow, error) {
	rows, err := q.db.QueryContext(ctx, listStoppedBoarderPlannedConsigments)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListStoppedBoarderPlannedConsigmentsRow{}
	for rows.Next() {
		var i ListStoppedBoarderPlannedConsigmentsRow
		if err := rows.Scan(
			&i.StartDate,
			&i.ExitDate,
			&i.EndDate,
			&i.ConsignmentNo,
			&i.CreatedAt,
			&i.Status,
			&i.Expname,
			&i.Phname,
		); 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 listStoppedBoarderPlannedConsigmentsPaginated = `-- name: ListStoppedBoarderPlannedConsigmentsPaginated :many
SELECT plannedconsignments.start_date,plannedconsignments_tpdetails.exit_date,plannedconsignments.end_date,plannedconsignments.id consignment_no,
plannedconsignments.created_at,plannedconsignments.status,exportcompanies.expname,packhouses.phname FROM plannedconsignments
LEFT JOIN plannedconsignments_tpdetails on plannedconsignments_tpdetails.plannedconsignments_id = plannedconsignments.id
LEFT JOIN exportcompanies on exportcompanies.id = plannedconsignments.exportcompany_id
LEFT JOIN packhouse_exporter on packhouse_exporter.exportcompany_id = exportcompanies.id
LEFT JOIN packhouses on packhouses.id  = packhouse_exporter.packhouse_id
WHERE
    plannedconsignments.status IN ('Rejected', 'Retreatment', 'Destroyed')
ORDER BY
    plannedconsignments.created_at DESC
LIMIT
    $1 OFFSET $2
`

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

type ListStoppedBoarderPlannedConsigmentsPaginatedRow struct {
	StartDate     string         `json:"start_date"`
	ExitDate      sql.NullTime   `json:"exit_date"`
	EndDate       string         `json:"end_date"`
	ConsignmentNo string         `json:"consignment_no"`
	CreatedAt     time.Time      `json:"created_at"`
	Status        string         `json:"status"`
	Expname       sql.NullString `json:"expname"`
	Phname        sql.NullString `json:"phname"`
}

func (q *Queries) ListStoppedBoarderPlannedConsigmentsPaginated(ctx context.Context, arg ListStoppedBoarderPlannedConsigmentsPaginatedParams) ([]ListStoppedBoarderPlannedConsigmentsPaginatedRow, error) {
	rows, err := q.db.QueryContext(ctx, listStoppedBoarderPlannedConsigmentsPaginated, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListStoppedBoarderPlannedConsigmentsPaginatedRow{}
	for rows.Next() {
		var i ListStoppedBoarderPlannedConsigmentsPaginatedRow
		if err := rows.Scan(
			&i.StartDate,
			&i.ExitDate,
			&i.EndDate,
			&i.ConsignmentNo,
			&i.CreatedAt,
			&i.Status,
			&i.Expname,
			&i.Phname,
		); 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 pendingPlannedConsignmentsSum = `-- name: PendingPlannedConsignmentsSum :one
SELECT COUNT(id)
FROM  plannedconsignments
WHERE plannedconsignments.status= 'Pending'
AND exportcompany_id = $1
`

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

const queriedPlannedConsignmentsSum = `-- name: QueriedPlannedConsignmentsSum :one
SELECT COUNT(id)
FROM plannedconsignments
WHERE plannedconsignments.status= 'Queried'
AND exportcompany_id = $1
`

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

const reDocumentPlannedConsignmentsSum = `-- name: ReDocumentPlannedConsignmentsSum :one
SELECT COUNT(id)
FROM plannedconsignments
WHERE plannedconsignments.status= 'ReDocument'
AND exportcompany_id = $1
`

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

const rejectedPlannedConsignmentsSum = `-- name: RejectedPlannedConsignmentsSum :one
SELECT COUNT(id)
FROM  plannedconsignments
WHERE plannedconsignments.status= 'Intercepted'
AND exportcompany_id = $1
`

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

const resortingPlannedConsignmentsSum = `-- name: ResortingPlannedConsignmentsSum :one
SELECT COUNT(id)
FROM plannedconsignments
WHERE plannedconsignments.status= 'Resort'
AND exportcompany_id = $1
`

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

const stoppedPlannedConsignmentsSum = `-- name: StoppedPlannedConsignmentsSum :one
SELECT COUNT(id)
FROM plannedconsignments
WHERE plannedconsignments.status IN ('Rejected', 'Retreatment', 'Destroyed')
`

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

const submittedPlannedConsignmentsSum = `-- name: SubmittedPlannedConsignmentsSum :one
SELECT COUNT(id)
FROM plannedconsignments
WHERE plannedconsignments.status= 'Submitted'
AND exportcompany_id = $1
`

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

const updatePlannedConsigment = `-- name: UpdatePlannedConsigment :one
UPDATE plannedconsignments
  set
    start_date       = $2,
    end_date         = $3,
    user_id          = $4,
    exportcompany_id = $5
WHERE id = $1
RETURNING id, start_date, end_date, status, exportcompany_id, user_id, created_at
`

type UpdatePlannedConsigmentParams struct {
	ID              string `json:"id"`
	StartDate       string `json:"start_date"`
	EndDate         string `json:"end_date"`
	UserID          int32  `json:"user_id"`
	ExportcompanyID int32  `json:"exportcompany_id"`
}

func (q *Queries) UpdatePlannedConsigment(ctx context.Context, arg UpdatePlannedConsigmentParams) (Plannedconsignment, error) {
	row := q.db.QueryRowContext(ctx, updatePlannedConsigment,
		arg.ID,
		arg.StartDate,
		arg.EndDate,
		arg.UserID,
		arg.ExportcompanyID,
	)
	var i Plannedconsignment
	err := row.Scan(
		&i.ID,
		&i.StartDate,
		&i.EndDate,
		&i.Status,
		&i.ExportcompanyID,
		&i.UserID,
		&i.CreatedAt,
	)
	return i, err
}

const updatePlannedConsigmentStatus = `-- name: UpdatePlannedConsigmentStatus :one
UPDATE plannedconsignments
  set
    status = $2
WHERE id = $1
RETURNING id, start_date, end_date, status, exportcompany_id, user_id, created_at
`

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

func (q *Queries) UpdatePlannedConsigmentStatus(ctx context.Context, arg UpdatePlannedConsigmentStatusParams) (Plannedconsignment, error) {
	row := q.db.QueryRowContext(ctx, updatePlannedConsigmentStatus, arg.ID, arg.Status)
	var i Plannedconsignment
	err := row.Scan(
		&i.ID,
		&i.StartDate,
		&i.EndDate,
		&i.Status,
		&i.ExportcompanyID,
		&i.UserID,
		&i.CreatedAt,
	)
	return i, err
}
