WITH RECURSIVE numbers AS (
	SELECT 1 n
	UNION ALL
	SELECT n + 1
		FROM numbers
		WHERE n < ?
)
SELECT ROW_NUMBER() OVER() labelNum,
		b.itemFk,
		i.name item,
		b.id buyFk,
		b.quantity,
		b.packing,
		b.entryFk,
		o.code origin,
		p.`name` producerName,
		p.id producerFk,
		i.`size`,
		i.category,
		i.stems,
		i.inkFk,
		ig.longName,
		ig.subName,
		i.comment,
		w.code buyerName,
		i.isLaid
	FROM vn.buy b
		JOIN vn.item i ON i.id = b.itemFk
		LEFT JOIN vn.item ig ON ig.id = b.itemOriginalFk
		JOIN vn.origin o ON o.id = i.originFk
		LEFT JOIN vn.producer p ON p.id = i.producerFk
		JOIN vn.itemType it ON it.id = i.typeFk
		JOIN vn.worker w ON w.id = it.workerFk
		JOIN numbers num
	WHERE b.id = ?