跳至主要內容

生产订单收货汇总查询

五六零网校小于 1 分钟

提示

逻辑:以生产订单为核心,汇总相关生产发料总数和生产收货总数 条件:日期范围必选;其他3个条件可不填,不填默认显示所有;物料描述可为关键词搜索,

代码示例

SELECT T0.[PostDate], T0.[DocNum] AS 生产订单编号
	, CASE 
		WHEN T0.[Type] = 'S' THEN N'标准'
		WHEN T0.[Type] = 'P' THEN N'特殊'
		WHEN T0.[Type] = 'D' THEN N'分拆'
	END AS '生产订单类型'
	, CASE 
		WHEN T0.[Status] = 'P' THEN N'已计划'
		WHEN T0.[Status] = 'R' THEN N'已下达'
		WHEN T0.[Status] = 'L' THEN N'已结算'
		WHEN T0.[Status] = 'C' THEN N'已取消'
	END AS '生产订单状态', T0.[ItemCode], T2.[ItemName] AS 成品描述, T0.[PlannedQty] AS '计划数量', TA.QTY AS '生产收货总数', T0.[Warehouse]
	
FROM OWOR T0
	INNER JOIN OITM T2 ON T2.ITEMCODE = T0.ITEMCODE
	LEFT JOIN (
		SELECT T0.[BaseEntry], T0.[ItemCode], SUM(T0.[Quantity]) AS 'QTY'
		FROM IGN1 T0
		WHERE T0.[BaseType] = '202'
		GROUP BY T0.[BaseEntry], T0.[ItemCode]
	) TA
	ON TA.baseentry = T0.docentry

WHERE T0.[PostDate] >= [%0]
	AND T0.[PostDate] <= [%1]
	AND (T0.[ItemCode] = '[%2]'
		OR '[%2]' = '')
	AND (T2.[ItemName] LIKE '%%[%3]%%'
		OR '[%3]' = '')
	AND (T0.[Warehouse] = '[%4]'
		OR '[%4]' = '')
ORDER BY T0.[DocNum] DESC