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K WHERE SUBSTR(ITMREF_0,1,1) = '2' GROUP BY ITMREF_0 UNION ALL SELECT MFGMAT.ITMREF_0 AS CPDM,0 AS KCSL,SUM(MFGMAT.RETQTY_0-MFGMAT.USEQTY_0) AS XQSL FROM MFGOPE INNER JOIN MFGMAT ON MFGOPE.MFGNUM_0=MFGMAT.MFGNUM_0 AND MFGOPE.OPENUM_0=MFGMAT.BOMOPE_0 AND MFGOPE.OPESPLNUM_0=0 WHERE MFGMAT.MATSTA_0<=2 AND MFGOPE.XMMSTA_0=1 AND SUBSTR(MFGMAT.ITMREF_0,1,1) = '2' GROUP BY MFGMAT.ITMREF_0)AAA GROUP BY CPDM )BBB left JOIN ITMBPS ON BBB.CPDM=ITMBPS.ITMREF_0 WHERE (BBB.KYSL<=0 OR BBB.KYSL IS NULL) AND (ITMBPS.BPSNUM_0<>'S14017' AND ITMBPS.BPSNUM_0<>'S10125' AND ITMBPS.BPSNUM_0<>'S10118' or ITMBPS.BPSNUM_0 is null) )EEE left JOIN ITMMASTER ON EEE.CPDM=ITMMASTER.ITMREF_0 )CCC ON DDD.CLDM=CCC.CPDM )FFF left JOIN MFGHEAD ON FFF.GDH=MFGHEAD.MFGNUM_0 WHERE MFGHEAD.ZMFGSTA_0<=2 )PPP RIGHT JOIN (SELECT HHH.GDH,HHH.KHDM,BPCUSTOMER.BPCNAM_0 AS KHMC,HHH.CPDM,HHH.CPMC,HHH.GG,HHH.WLQD,HHH.JHSL,HHH.DMBZ,HHH.JHXS FROM (SELECT GGG.DDH,GGG.KHDM,GGG.GDH,GGG.CPDM,ITMMASTER.ITMDES1_0 AS CPMC,ITMMASTER.ITMSTD_0 AS GG,GGG.WLQD,GGG.JHSL,GGG.DMBZ, (GGG.JHSL/ITMMASTER.PUUSTUCOE_0) AS JHXS FROM (SELECT SORDER.SOHNUM_0 AS DDH,SORDER.ZBPCORD_0 AS KHDM,MFGITM.ITMREF_0 AS CPDM,MFGITM.BOMALT_0 AS WLQD,MFGITM.XCODREM_0 AS DMBZ, MFGITM.UOMEXTQTY_0 AS JHSL,MFGITM.MFGNUM_0 AS GDH FROM MFGITM LEFT JOIN SORDER ON MFGITM.VCRNUMORI_0=SORDER.SOHNUM_0 WHERE SUBSTR(MFGITM.ITMREF_0,1,1)='1') GGG INNER JOIN ITMMASTER ON GGG.CPDM=ITMMASTER.ITMREF_0 )HHH LEFT JOIN BPCUSTOMER ON HHH.KHDM=BPCUSTOMER.BPCNUM_0 )QQQ ON PPP.GDH=QQQ.GDH WHERE PPP.GDZT<3 AND PPP.KYSL<0 AND SUBSTR(PPP.CLDM,1,1)='2' ORDER BY PPP.GDRQ DESC
|