<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "出库明细">
<query id = "FrmOutBoundSum.getGpDataB" desc = "出库明细">
<![CDATA[
SELECT T.OUTSTOCK_TYPE_NAME,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T.MATERIAL_NAME,
       T.PRODUCNAME,
       T.STD_NAME,
       T.GRADENAME,
       T.STEELNAME,
       T.STD_STYLE_DESC,
       T.SPEC_NAME,
       T.MODEL_DESC,
       T.PLINE_NAME,
       T.ACT_LEN_MIN || '-' || T.ACT_LEN_MAX ACTLENMA,
       T.BELONG_NAME,
       (SELECT S.SALE_AREA_DESC
          FROM SLM_ORDER_HEAD S
         WHERE S.ORD_PK = T.ORD_PK) SALE_AREA_DESC,
       (SELECT B.STORAGE_NAME
          FROM YDM_BS_STORAGE B
         WHERE B.STORAGE_NO = T.STORAGE_NO) STORAGE_NO,
       T.MANAGEMENT_NAME,
       T.CREATE_NAME,
       TO_CHAR(MAX(T.CREATE_TIME),'YYYY-MM-DD') CREATE_TIME,
       TO_CHAR(MIN(T.OUTSTOCK_TIME),'YYYY-MM-DD HH24:MI:SS') OUTSTOCK_TIME,
       T.ORD_LN_DLY_PK,
       T.DEPARTMENT_DESC,
       T.ORDER_NO,
       T.ORDER_SEQ,
       T.DELIVERY_NO,
       DECODE(T.PRODUCT_FLAG,'801402','成品','801401','在制品','商品') PRODUCT_FLAG,
       T.PONDER_NO,
       T.BAL_YEAR_MONTH,
       SUM(NVL(T.ACT_COUNT, 0)) ACT_COUNT,
        CASE
            WHEN T.PONDER_NO IS NOT NULL THEN
                CASE
                    WHEN (SELECT DISTINCT LOADVEHICLE_TYPE from YDM_ZC_BILL_M WHERE BILL_NO = T.BILL_NO) = 2 AND MAX(T.SUPPLY_UNIT_CODE) = '120504' THEN
                        SUM( NVL( T.ACT_WEIGHT, 0 ) )
                    ELSE
                        SUM( NVL( T.PONDER_GROSS_WT, 0 ) )
                END
    -- 			SUM( NVL( T.PONDER_GROSS_WT, 0 ) )
            ELSE SUM( NVL( T.ACT_WEIGHT, 0 ) )
        END ACT_WEIGHT,
       CASE
         WHEN T.OUTSTOCK_TYPE_CODE = '800804' THEN
          SUM(NVL(T.ACT_COUNT, 0))
         ELSE
          0
       END HKACT_COUNT,
       CASE
         WHEN T.OUTSTOCK_TYPE_CODE = '800804' THEN
         (CASE
            WHEN T.PONDER_NO IS NOT NULL THEN
             SUM(NVL(T.PONDER_GROSS_WT, 0))
            ELSE
             SUM(NVL(T.ACT_WEIGHT, 0))
          END)
         ELSE
          0
       END HKACT_WEIGHT,
       CASE
         WHEN T.OUTSTOCK_TYPE_CODE = '800805' OR T.OUTSTOCK_TYPE_CODE = '800812' THEN
          SUM(NVL(T.ACT_COUNT, 0))
         ELSE
          0
       END XSACT_COUNT,
       CASE
         WHEN T.OUTSTOCK_TYPE_CODE = '800805' OR T.OUTSTOCK_TYPE_CODE = '800812' THEN
          (CASE
            WHEN T.PONDER_NO IS NOT NULL THEN
             SUM(NVL(T.PONDER_GROSS_WT, 0))
            ELSE
             SUM(NVL(T.ACT_WEIGHT, 0))
          END)
         ELSE
          0
       END XSACT_WEIGHT,
        CASE
         WHEN T.OUTSTOCK_TYPE_CODE = '800806' THEN
          SUM(NVL(T.ACT_COUNT, 0))
         ELSE
          0
       END THACT_COUNT,
       CASE
         WHEN T.OUTSTOCK_TYPE_CODE = '800806' THEN
          (CASE
            WHEN T.PONDER_NO IS NOT NULL THEN
             SUM(NVL(T.PONDER_GROSS_WT, 0))
            ELSE
             SUM(NVL(T.ACT_WEIGHT, 0))
          END)
         ELSE
          0
       END THACT_WEIGHT,
        CASE
         WHEN T.OUTSTOCK_TYPE_CODE = '800808' THEN
          SUM(NVL(T.ACT_COUNT, 0))
         ELSE
          0
       END GPACT_COUNT,
       CASE
         WHEN T.OUTSTOCK_TYPE_CODE = '800808' THEN
          (CASE
            WHEN T.PONDER_NO IS NOT NULL THEN
             SUM(NVL(T.PONDER_GROSS_WT, 0))
            ELSE
             SUM(NVL(T.ACT_WEIGHT, 0))
          END)
         ELSE
          0
       END GPACT_WEIGHT,
        CASE
         WHEN T.OUTSTOCK_TYPE_CODE = '800802' THEN
          SUM(NVL(T.ACT_COUNT, 0))
         ELSE
          0
       END PKACT_COUNT,
       CASE
         WHEN T.OUTSTOCK_TYPE_CODE = '800802' THEN
          (CASE
            WHEN T.PONDER_NO IS NOT NULL THEN
             SUM(NVL(T.PONDER_GROSS_WT, 0))
            ELSE
             SUM(NVL(T.ACT_WEIGHT, 0))
          END)
         ELSE
          0
       END PKACT_WEIGHT,CASE
         WHEN T.OUTSTOCK_TYPE_CODE = '800806' THEN
          T.RECEIV_NM
         ELSE
          T1.RECEIV_NM
       END RECEIV_NM,
           (SELECT TO_CHAR(MIN(T2.INSTOCK_TIME),'YYYY-MM-DD HH24:MI:SS')
          FROM YDM_ZC_INLIST T2
         WHERE T2.JUDGE_STOVE_NO = T.JUDGE_STOVE_NO
           AND T2.BATCH_NO = T.BATCH_NO
           AND T2.BATCH_GROUD_NO = T.BATCH_GROUD_NO
           AND T2.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK) INSTOCK_TIME,
           (SELECT TO_CHAR(MIN(T2.IN_TIME_F), 'YYYY-MM-DD HH24:MI:SS')
          FROM YDM_ZC_INLIST T2
         WHERE T2.JUDGE_STOVE_NO = T.JUDGE_STOVE_NO
           AND T2.BATCH_NO = T.BATCH_NO
           AND T2.BATCH_GROUD_NO = T.BATCH_GROUD_NO
           AND T2.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK) IN_TIME_F,
           (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = T.IN_MOLD AND ROWNUM = 1) IN_MOLD,
           DECODE(T.FINISHPRO_MOLD,'801801','合同变更','801802','超交货期','801803','超载甩量',
           '801804','成品备库','801805','质量异议待处理') FINISHPRO_MOLD,
           T.PRO_ORDER_NO
            FROM YDM_ZC_OUTLIST T, 
       SLM_ORDER_LINE_DELIVERY T1,
       SLM_ORDER_HEAD T2
       WHERE T.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK(+)
       AND T.ORD_PK = T2.ORD_PK(+)
       AND T.VALIDFLAG='1' 
 AND T.OUTSTOCK_TYPE_CODE IN ('800805','800806','800808','800802','800804','800812')
 ]]>
</query>
</queryMap>