<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="权限功能表查询">

    <query id="CrmOutList.insertCrmOutList" desc="新增">
        INSERT INTO CRM_ZC_OUTLIST(
        LOADVEHICLE_SQE,
        BILL_NO,
        LOADVEHICLE_NO,
        JUDGE_STOVE_NO,
        BATCH_NO,
        BATCH_GROUD_NO,
        MATERIAL_NO,
        MATERIAL_NAME,
        PRODUCCODE,
        PRODUCNAME,
        STD_CODE,
        STD_NAME,
        GRADECODE,
        GRADENAME,
        STEELCODE,
        STEELNAME,
        STD_STYLE,
        STD_STYLE_DESC,
        SPEC_CODE,
        SPEC_NAME,
        MODEL_CODE,
        MODEL_DESC,
        ACT_LEN_MIN,
        ACT_LEN_MAX,
        ACT_COUNT,
        ACT_WEIGHT,
        ACT_LEN,
        STORAGE_NO,
        STORAGE_NAME,
        SEN_TIME,
        VALIDFLAG,
        ORDER_NO,
        ORDER_SEQ,
        DELIVERY_NO,
        ORD_PK,
        ORD_LN_PK,
        ORD_LN_DLY_PK,
        DATA_STATUS,
        CREATE_TIME,
        DELVRY_WHEREABOUTS,
        SUPPLY_UNIT_CODE,
        SUPPLY_UNIT,
        BAL_YEAR_MONTH,
        ACT_DIMATER,
        ACT_HEIGHT,
        BELONG_CODE,
        BELONG_NAME,
        OUTSTOCK_TYPE_CODE,
        OUTSTOCK_TYPE_NAME
        )
        VALUES(
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        (SELECT STORAGE_NAME FROM YDM_BS_STORAGE WHERE STORAGE_NO = ?),
        to_date(?,'YYYY-MM-DD HH24:MI:SS'),
        DECODE(?,'0','发运无效','1','发运有效','2','确认有效','3','传送发运明细到销售和质检'),
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        to_date(?,'YYYY-MM-DD HH24:MI:SS'),
        (SELECT DELVRY_WHEREABOUTS FROM YDM_ZC_BILL_M WHERE BILL_NO = ? AND VALIDFLAG = '1' AND ROWNUM = 1),
        (SELECT SUPPLY_UNIT FROM YDM_ZC_BILL_M WHERE BILL_NO = ? AND VALIDFLAG = '1' AND ROWNUM = 1),
        (SELECT SUPPLY_UNIT_DESC FROM YDM_ZC_BILL_M WHERE BILL_NO = ? AND VALIDFLAG = '1' AND ROWNUM = 1),
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?
        )
    </query>

    <query id="CrmOutList.insertCrmOutList_Time" desc="新增(已废)">
        INSERT INTO CRM_ZC_OUTLIST(
        LOADVEHICLE_SQE,
        BILL_NO,
        LOADVEHICLE_NO,
        JUDGE_STOVE_NO,
        BATCH_NO,
        BATCH_GROUD_NO,
        MATERIAL_NO,
        MATERIAL_NAME,
        PRODUCCODE,
        PRODUCNAME,
        STD_CODE,
        STD_NAME,
        GRADECODE,
        GRADENAME,
        STEELCODE,
        STEELNAME,
        STD_STYLE,
        STD_STYLE_DESC,
        SPEC_CODE,
        SPEC_NAME,
        MODEL_CODE,
        MODEL_DESC,
        ACT_LEN_MIN,
        ACT_LEN_MAX,
        ACT_COUNT,
        ACT_WEIGHT,
        ACT_LEN,
        STORAGE_NO,
        STORAGE_NAME,
        SEN_TIME,
        VALIDFLAG,
        ORDER_NO,
        ORDER_SEQ,
        DELIVERY_NO,
        ORD_PK,
        ORD_LN_PK,
        ORD_LN_DLY_PK,
        DATA_STATUS,
        CREATE_TIME,
        DELETE_TIME,DELVRY_WHEREABOUTS,
        OUTSTOCK_TYPE_CODE,
        OUTSTOCK_TYPE_NAME)
        VALUES(
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        (SELECT STORAGE_NAME FROM YDM_BS_STORAGE WHERE STORAGE_NO = ?),
        to_date(?,'YYYY-MM-DD HH24:MI:SS'),
        DECODE(?,'0','发运无效','1','发运有效','2','确认有效','3','传送发运明细到销售和质检'),
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        SYSDATE,
        SYSDATE,
        (SELECT DELVRY_WHEREABOUTS FROM YDM_ZC_BILL_M WHERE BILL_NO = ? AND VALIDFLAG = '1' AND ROWNUM = 1),
        ?,
        ?
        )
    </query>

    <query id="CrmOutList.insertQueryInfo" desc="查询发货实绩表信息">
        INSERT INTO CRM_ZC_OUTLIST(
        LOADVEHICLE_SQE,
        BILL_NO,
        LOADVEHICLE_NO,
        JUDGE_STOVE_NO,
        BATCH_NO,
        BATCH_GROUD_NO,
        MATERIAL_NO,
        MATERIAL_NAME,
        PRODUCCODE,
        PRODUCNAME,
        STD_CODE,
        STD_NAME,
        GRADECODE,
        GRADENAME,
        STEELCODE,
        STEELNAME,
        STD_STYLE,
        STD_STYLE_DESC,
        SPEC_CODE,
        SPEC_NAME,
        MODEL_CODE,
        MODEL_DESC,
        ACT_LEN_MIN,
        ACT_LEN_MAX,
        ACT_COUNT,
        ACT_WEIGHT,
        ACT_LEN,
        STORAGE_NO,
        STORAGE_NAME,
        SEN_TIME,
        VALIDFLAG,
        ORDER_NO,
        ORDER_SEQ,
        DELIVERY_NO,
        ORD_PK,
        ORD_LN_PK,
        ORD_LN_DLY_PK,
        DATA_STATUS,
        CREATE_TIME,
        DELVRY_WHEREABOUTS,
        SUPPLY_UNIT_CODE,
        SUPPLY_UNIT,
        BAL_YEAR_MONTH,
        ACT_DIMATER,
        ACT_HEIGHT,
        BELONG_CODE,
        BELONG_NAME,
        OUTSTOCK_TYPE_CODE,
        OUTSTOCK_TYPE_NAME
        )

        SELECT
        M.LOADVEHICLE_SQE,
        T.M_BILL_NO,
        M.LOADVEHICLE_NO,
        T.JUDGE_STOVE_NO,
        T.BATCH_NO,
        T.BATCH_GROUD_NO,
        T.MATERIAL_NO,
        T.MATERIAL_NAME,
        T.PRODUCCODE,
        T.PRODUCNAME,
        T.STD_CODE,
        T.STD_NAME,
        T.GRADECODE,
        T.GRADENAME,
        T.STEELCODE,
        T.STEELNAME,
        T.STD_STYLE,
        T.STD_STYLE_DESC,
        T.SPEC_CODE,
        T.SPEC_NAME,
        T.MODEL_CODE,
        T.MODEL_DESC,
        T.ACT_LEN_MIN,
        T.ACT_LEN_MAX,
        T.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 T.SUPPLY_UNIT_CODE = '120504' THEN
         NVL( T.ACT_WEIGHT, 0 )
        ELSE
         NVL( T.PONDER_GROSS_WT, 0 )
        END
        ELSE NVL( T.ACT_WEIGHT, 0 )
        END ACT_WEIGHT,
        T.ACT_LEN,
        T.STORAGE_NO,
        (SELECT STORAGE_NAME FROM YDM_BS_STORAGE WHERE STORAGE_NO = T.STORAGE_NO),
        M.SEN_TIME,
        DECODE(T.VALIDFLAG,'0','发运无效','1','发运有效','2','确认有效','3','传送发运明细到销售和质检'),
        T.ORDER_NO,
        T.ORDER_SEQ,
        T.DELIVERY_NO,
        T.ORD_PK,
        T.ORD_LN_PK,
        T.ORD_LN_DLY_PK,
        ?,
        to_date(?,'YYYY-MM-DD HH24:MI:SS'),
        (SELECT DELVRY_WHEREABOUTS FROM YDM_ZC_BILL_M WHERE BILL_NO = T.M_BILL_NO AND VALIDFLAG = '1' AND ROWNUM = 1),
        T.SUPPLY_UNIT_CODE,
        T.SUPPLY_UNIT,
        T.BAL_YEAR_MONTH,
        T.ACT_DIMATER,
        T.ACT_HEIGHT,
        T.BELONG_CODE,
        T.BELONG_NAME,
        T.OUTSTOCK_TYPE_CODE,
        T.OUTSTOCK_TYPE_NAME
        FROM YDM_ZC_OUTLIST T
        LEFT JOIN YDM_ZC_LOADVEHICLE_MAT M ON T.M_BILL_NO = M.BILL_NO  and t.MAT_NO = m.MAT_NO
        WHERE
         T.M_BILL_NO = ?
        AND T.JUDGE_STOVE_NO = ?
        AND T.BATCH_NO = ?
        AND T.BATCH_GROUD_NO = ?
        AND NVL(T.ORD_LN_DLY_PK,'/')=NVL(?,'/')
        AND T.OUTSTOCK_TYPE_CODE = '800806'
    </query>
</queryMap>