Ok, well you owe me a big one of whatever your local delicacy is, next time I am in the neighbourhood
Please try this:
DECLARE @CardCode NVARCHAR(15) = SELECT CardCode FROM OCRD WHERE CardCode = '[%0]'
SELECT c.CardCode
,c.CardName
,i.ItemCode
,i.ItemName
,ISNULL(i.SalUnitMsr, 'pcs') AS UoM
,ISNULL(s.Quantity,0) AS SoldLast3Months
,(ISNULL(s.Quantity,0)/60) AS AvgPcsSoldPerDay
,i.OnHand
,ISNULL((SELECT SUM(ISNULL(x.Quantity, 0)) AS Quantity
FROM (SELECT r.OpenQty AS Quantity
FROM OPDN h
INNER JOIN PDN1 r ON h.DocEntry = r.DocEntry
WHERE h.DocDueDate > GETDATE()
AND r.ItemCode = i.ItemCode
AND r.LineStatus = 'O'
GROUP BY r.OpenQty) x), 0) AS QuantityIncoming
,ISNULL((SELECT x.DocDueDate
FROM (SELECT r.Quantity
,MIN(h.DocDueDate) AS DocDueDate
FROM OPDN h
INNER JOIN PDN1 r ON h.DocEntry = r.DocEntry
WHERE h.DocDueDate > GETDATE()
AND r.ItemCode = i.ItemCode
GROUP BY r.Quantity) x), DATEADD(MONTH, 3, GETDATE())) AS QuantityIncomingWhen
,DATEDIFF(DAY, GETDATE(), ISNULL((SELECT x.DocDueDate
FROM (SELECT r.Quantity
,MIN(h.DocDueDate) AS DocDueDate
FROM OPDN h
INNER JOIN PDN1 r ON h.DocEntry = r.DocEntry
WHERE h.DocDueDate > GETDATE()
AND r.ItemCode = i.ItemCode
GROUP BY r.Quantity) x), DATEADD(MONTH, 3, GETDATE()))) AS NrOfDaysToNextPurchaseDelivery
,(DATEDIFF(DAY, GETDATE(), ISNULL((SELECT x.DocDueDate
FROM (SELECT r.Quantity
,MIN(h.DocDueDate) AS DocDueDate
FROM OPDN h
INNER JOIN PDN1 r ON h.DocEntry = r.DocEntry
WHERE h.DocDueDate > GETDATE()
AND r.ItemCode = i.ItemCode
GROUP BY r.Quantity) x), DATEADD(MONTH, 3, GETDATE()))) * (ISNULL(s.Quantity,0)/60)) AS PotentialSales
,i.OnHand - (DATEDIFF(DAY, GETDATE(), ISNULL((SELECT x.DocDueDate
FROM (SELECT r.Quantity
,MIN(h.DocDueDate) AS DocDueDate
FROM OPDN h
INNER JOIN PDN1 r ON h.DocEntry = r.DocEntry
WHERE h.DocDueDate > GETDATE()
AND r.ItemCode = i.ItemCode
GROUP BY r.Quantity) x), DATEADD(MONTH, 3, GETDATE()))) * (ISNULL(s.Quantity,0)/60)) AS StockLevelAtNextPurchaseDelivery
,(i.OnHand / DATEDIFF(DAY, GETDATE(), ISNULL((SELECT x.DocDueDate
FROM (SELECT r.Quantity
,MIN(h.DocDueDate) AS DocDueDate
FROM OPDN h
INNER JOIN PDN1 r ON h.DocEntry = r.DocEntry
WHERE h.DocDueDate > GETDATE()
AND r.ItemCode = i.ItemCode
GROUP BY r.Quantity) x), DATEADD(MONTH, 3, GETDATE())))) AS CurrentStockWillLastThisLong
FROM OCRD c
INNER JOIN OITM i ON c.CardCode = i.CardCode
LEFT OUTER JOIN (SELECT r.ItemCode, SUM(r.Quantity) AS Quantity
FROM INV1 r
INNER JOIN OINV h ON r.DocEntry = h.DocEntry
WHERE h.DocDate > DATEADD(MONTH, -3, GETDATE())
GROUP BY r.ItemCode) s ON i.ItemCode = s.ItemCode
WHERE c.CardCode = @CardCode
AND NOT i.frozenFor = 'Y'