Select
p1.product_ident_number
FROM products p1
LEFT JOIN warehouse_products wp ON wp.`product_id`=p1.id
LEFT JOIN orders o ON wp.`order_id`=o.id
WHERE wp.deleted_at IS NULL AND wp.stock_out_dt IS NULL AND wp.id IS NOT NULL
GROUP BY p1.product_ident_number)
AS temp_warehouse_amount
->leftJoin('
Select
p1.product_ident_number
FROM products p1
LEFT JOIN warehouse_products wp ON wp.`product_id`=p1.id
LEFT JOIN orders o ON wp.`order_id`=o.id
WHERE wp.deleted_at IS NULL AND wp.stock_out_dt IS NULL AND wp.id IS NOT NULL
GROUP BY p1.product_ident_number)
AS temp_warehouse_amount'),
//AND (o.status != "' . Order::STATUS_SENDED . '" OR o.status IS NULL)
function ($query) {
/** @var JoinClause $query */
$query->on('products.product_ident_number', '=', 'temp_warehouse_amount.product_ident_number');
}
)