<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="发货信息统计">
	<query id="FrmrptProductSendOut.getSendOutData" desc="发货信息查询">
<![CDATA[
SELECT

 #columns# SUM(T.ACT_COUNT) AS ACT_COUNT,
	sum(
		CASE WHEN t.PONDER_NO IS NULL THEN nvl( t.ACT_WEIGHT, 0 )
			ELSE
-- 				nvl( t.PONDER_GROSS_WT, 0 )
                CASE
                    WHEN S.LOADVEHICLE_TYPE = 2 AND M.SUPPLY_UNIT = '120504' THEN
                        NVL( T.ACT_WEIGHT, 0 )
                    ELSE
                        NVL( T.PONDER_GROSS_WT, 0 )
                END
		 END
	) AS ACT_WEIGHT,
	sum(NVL( T.PONDER_GROSS_WT, 0 )) PONDER_GROSS_WT,
     SUM(T.ACT_LEN) ACT_LEN,
 SUM(T.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT

   FROM YDM_ZC_LOADVEHICLE_MAT T,
       (SELECT DISTINCT M.DELETE_TIME, M.DELVRY_ADDR, M.BILL_NO,O.SUPPLY_UNIT,M.ORD_PK ,O.CREATE_NAME ORDER_CREATE_NAME,M.Plan_Number,m.order_seq
          FROM YDM_ZC_BILL_M M
          LEFT JOIN SLM_ORDER_HEAD O ON M.ORD_PK = O. ORD_PK ) M,
       YDM_ZC_LOADVEHICLE S,
       YDM_BS_STORAGE D,
       --YDM_BS_LOCATION F,
       SLM_ORDER_HEAD G,
       (SELECT
            CUSTM_ORDER_NO HT,
            '成品' type,
            max( CUSTOMER_NM ) ZZ
        FROM
            SLM_ORDER_HEAD
            WHERE VALIDFLAG = '1'
        GROUP BY
            CUSTM_ORDER_NO) cp,
       (
        SELECT
            TH_ORDER_NO_SEQ HT,
            '半成品' type,
            '天津钢管制造有限公司' ZZ
        FROM
            PLN_ORDER_ZG_S
        GROUP BY
            TH_ORDER_NO_SEQ) bcp
 WHERE T.BILL_NO = S.BILL_NO
   AND T.BILL_NO = M.BILL_NO
   AND D.STORAGE_NO = T.STORAGE_NO
   --AND F.LOCATION_NO = T.LOCATION_NO
   AND T.ORD_PK = G.ORD_PK
   and t.order_seq = m.order_seq
   AND T.ORD_PK = M.ORD_PK
   AND T.LOADVEHICLE_NO = S.LOADVEHICLE_NO
    AND T.ORDER_NO = cp.HT (+)
    and  T.ORDER_NO || '/' || T.ORDER_SEQ = bcp.HT (+)
   AND T.VALIDFLAG <> '0'
   AND T.RETURN_FLAG='0'
    #conditions#

 
 ]]>
	</query>
	<query id = "FrmrptProductSendOut.getSendOutDataC" desc = "查询半成品出库实绩">
	SELECT

 #columns# SUM(T.ACT_COUNT) AS ACT_COUNT,
 sum(case
       when t.PONDER_NO is null then
        nvl(t.ACT_WEIGHT, 0)
       else
        nvl(t.PONDER_GROSS_WT, 0)
     end) AS ACT_WEIGHT,
     SUM(T.ACT_LEN) ACT_LEN,
 SUM(T.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
   FROM YDM_ZC_OUTLIST T LEFT JOIN YDM_BS_STORAGE D ON T.STORAGE_NO = D.STORAGE_NO
 WHERE (T.OUTSTOCK_TYPE_CODE = '800803' AND T.TAR_REC_FLAG = '#TAR_REC_FLAG#'
    #conditions1#
    #conditions#
	</query>
	
	<query id = "FrmrptProductSendOut.getSendOutDataB" desc = "查询半成品出库实绩（所属权）">
	SELECT

 #columns# SUM(T.ACT_COUNT) AS ACT_COUNT,
 sum(case
       when t.PONDER_NO is null then
        nvl(t.ACT_WEIGHT, 0)
       else
        nvl(t.PONDER_GROSS_WT, 0)
     end) AS ACT_WEIGHT,
     SUM(T.ACT_LEN) ACT_LEN,
 SUM(T.ACT_THEORY_WEIGHT) ACT_THEORY_WEIGHT
   FROM YDM_ZC_OUTLIST T LEFT JOIN YDM_BS_STORAGE D ON T.STORAGE_NO = D.STORAGE_NO
 WHERE 1=1
    AND T.OUTSTOCK_TYPE_CODE IN('800809','800810')
    #conditions1#
    #conditions#
	</query>
</queryMap>