----------------------------------採購收貨數量不能超出採購訂單數量------------------------------------------------------ide
SELECT TOP 1 @ERROR = 1, spa
@ERROR_MESSAGE = N'物料:' + t1.ItemCode + N' 收貨數量已超出訂單數量!it
訂單未清數量爲:' + CAST (t3.OpenCreQty AS NVARCHAR) class
+ N', 本次總計收貨數量爲:' error
+ CAST (t1.Quantity AS NVARCHAR) tab
FROM di
(SELECT ItemCode, BaseEntry, BaseLine, SUM (Quantity) AS Quantity view
FROM PDN1 AS t0 vi
WHERE (DocEntry = @list_of_cols_val_tab_del) GROUP BY ItemCode, BaseEntry, BaseLine) ant
AS t1
LEFT OUTER JOIN
(SELECT t2.LineNum, t2.OpenCreQty, t2.DocEntry
FROM
(SELECT ROW_NUMBER () OVER (PARTITION BY T.DOCENTRY ORDER BY t.LogInstanc DESC) indx,
t.LogInstanc, t.LineNum, t.OpenCreQty,t.DocEntry
FROM ADO1 t WHERE ObjType = 22 ) t2
WHERE t2.indx = 1) t3
ON t1.BaseLine = t3.LineNum and t1.BaseEntry =t3.DocEntry
WHERE t3.OpenCreQty < t1.Quantity
--------------------------------------------------------------------------------------------------------------------------
SELECT TOP 1 @error = 1,
@message = N'子物料:' + CAST (t1.ItemCode AS VARCHAR) + N' 未發過貨,訂單不能關閉!若是確實不須要,請從工單中刪除該物料!'
FROM OWOR T0 INNER JOIN WOR1 T1 ON T0.DocEntry = T1.DocEntry
WHERE T0.DocEntry = #1 AND T1.IssuedQty = 0 AND T0.RjctQty +T0.CmpltQty >0
---------------------------------------------------------------------------------------------
採購訂單數量不能超出採購申請
SELECT TOP 1 @error = 1,
@message = N'第' + CAST (t.VisOrder + 1 AS VARCHAR) + N'行'
+ CASE WHEN t.BaseType <> 1470000113 THEN N'沒有基於採購申請單!'
WHEN t.Quantity < t.PoQty THEN N'累計下達訂單已超出了申請單數量!' END
FROM
(SELECT T0.VisOrder + 1 VisOrder, t0.BaseType, T1.Quantity,
SUM (T2.Quantity) OVER (PARTITION BY T2.BASEENTRY, T2.BASELINE) PoQty
FROM POR1 T0
LEFT OUTER JOIN PRQ1 T1 ON T0.BaseType = T1.ObjType AND T0.BaseEntry = T1.DocEntry AND T0.BaseLine = T1.LineNum
LEFT OUTER JOIN (POR1 T2 INNER JOIN OPOR T3 ON T2.DocEntry = T3.DocEntry AND T3.CANCELED = 'N')
ON T2.BaseType = T1.ObjType AND T2.BaseEntry = T1.DocEntry AND T2.BaseLine = T1.LineNum
WHERE T0.DocEntry = #1) T
WHERE (t.BaseType <> 1470000113 OR t.Quantity < t.PoQty)
---------------------------------------------------------------------------------------------