<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "入库明细汇总">
<query id = "FrmInList.doQuery" desc = "查询">
SELECT 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,
       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.ORDER_NO,
       T.ORDER_SEQ,
       T.DELIVERY_NO,
       T.BAL_YEAR_MONTH,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       T.INSTOCK_TYPE_NAME,
       SUM(NVL(T.ACT_COUNT, 0)) ACT_COUNT,
       SUM(NVL(T.ACT_WEIGHT, 0)) ACT_WEIGHT,
       CASE
         WHEN (T.INSTOCK_TYPE_CODE = '800712' OR (T.INSTOCK_TYPE_CODE = '800701' AND T.HAND_FLAG = '0')) THEN
          SUM(NVL(T.ACT_COUNT, 0))
         ELSE
          0
       END OUT_COUNT,
       CASE
         WHEN (T.INSTOCK_TYPE_CODE = '800712' OR (T.INSTOCK_TYPE_CODE = '800701' AND T.HAND_FLAG = '0')) THEN
         
          SUM(NVL(T.ACT_WEIGHT, 0))
         ELSE
          0
       END OUT_WEIGHT,
       CASE
         WHEN T.INSTOCK_TYPE_CODE = '800701' AND T.HAND_FLAG = '1' THEN
          SUM(NVL(T.ACT_COUNT, 0))
         ELSE
          0
       END HANDLE_COUNT,
       CASE
         WHEN T.INSTOCK_TYPE_CODE = '800701' AND T.HAND_FLAG = '1' THEN
          SUM(NVL(T.ACT_WEIGHT, 0))
         ELSE
          0
       END HANDLE_WEIGHT,
       CASE
         WHEN T.INSTOCK_TYPE_CODE = '800704' THEN
          SUM(NVL(T.ACT_COUNT, 0))
         ELSE
          0
       END RED_COUNT,
       CASE
         WHEN T.INSTOCK_TYPE_CODE = '800704' THEN
          SUM(NVL(T.ACT_WEIGHT, 0))
         ELSE
          0
       END RED_WEIGHT,
       CASE
         WHEN T.INSTOCK_TYPE_CODE = '800706' THEN
          SUM(NVL(T.ACT_COUNT, 0))
         ELSE
          0
       END GP_COUNT,
       CASE
         WHEN T.INSTOCK_TYPE_CODE = '800706' THEN
          SUM(NVL(T.ACT_WEIGHT, 0))
         ELSE
          0
       END GP_WEIGHT,
       CASE
         WHEN T.INSTOCK_TYPE_CODE = '800702' THEN
          SUM(NVL(T.ACT_COUNT, 0))
         ELSE
          0
       END PY_COUNT,
       CASE
         WHEN T.INSTOCK_TYPE_CODE = '800702' THEN
          SUM(NVL(T.ACT_WEIGHT, 0))
         ELSE
          0
       END PY_WEIGHT,
       MAX(TO_CHAR(T.IN_TIME_F,'YYYY-MM-DD HH:MM:SS'))INSTOCK_TIME,
       S.RECEIV_NM,
       NVL(SUM(T.PACK_NO),0) PACK_NO,
       (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
  FROM YDM_ZC_INLIST T
  LEFT JOIN SLM_ORDER_LINE_DELIVERY S
  ON T.ORD_PK = S.ORD_PK
  AND T.ORD_LN_PK = S.ORD_LN_PK
  AND T.ORD_LN_DLY_PK = S.ORD_LN_DLY_PK
 WHERE 1 = 1
   AND T.INSTOCK_TYPE_CODE IN ('800701', '800702', '800704', '800706','800712')
   AND T.VALIDFLAG = '1'
</query>
</queryMap>