<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "判定时写入库表">
<query id = "FrmGpIqInList.getInListDoc" desc = "生成入库单号">
    SELECT 'IQ' || TO_CHAR(SYSDATE, 'YYMMDD') ||
    LPAD(NVL(MAX(SUBSTR(T.INSTOCK_DOC, 9)), 0) + 1, 5, 0) INSTOCK_DOC
    FROM YDM_GP_INLIST T
    WHERE T.INSTOCK_TYPE_CODE = ?
    AND T.INSTOCK_DOC LIKE 'IQ' || TO_CHAR(SYSDATE, 'YYMMDD') || '_____'
</query>
<query id = "FrmGpIqInList.getIdCodeItExists" desc = "查询是否存在">
    SELECT
        T.ID
    FROM
        COM_ID_CODE T
    WHERE
        T.ID = ?
</query>
<query id = "FrmGpIqInList.insertComIdCode" desc = "插入编号表">
    INSERT INTO COM_ID_CODE(
        ID,
        TYPE
    )
    VALUES(
        ?,
        ?
    )
</query>
<query id = "FrmGpIqInList.querySendSql" desc = "生成入库流水号">
SELECT ? ||
       LPAD(NVL(MAX(SUBSTR(T.INSTOCK_SQE, LENGTH(T.INSTOCK_SQE) - 4)), 0) + 1,
            5,
            0) INSTOCK_SQE
  FROM YDM_GP_INLIST T
 WHERE T.INSTOCK_DOC = ?
</query>
<query id = "FrmGpIqInList.QueryMatNoM" desc = "生成材料号">
SELECT ? ||
       LPAD(NVL(MAX(SUBSTR(T2.MAT_NO, LENGTH(T2.MAT_NO) - 2)), 0) + 1, 3, 0) MAT_NO
  FROM (SELECT MAX(T.MAT_NO)MAT_NO
          FROM MAT_GP_M T
         WHERE T.JUDGE_STOVE_NO = ?
        UNION ALL
        SELECT MAX(T1.MAT_NO)MAT_NO
          FROM YDM_GP_INLIST T1
         WHERE T1.JUDGE_STOVE_NO = ?
         UNION ALL
         SELECT MAX(T3.MAT_NO)MAT_NO
         FROM MAT_GP_TRACK T3
         WHERE T3.JUDGE_STOVE_NO = ?) T2
</query>
<query id = "FrmGpIqInList.insertGpInList" desc = "插入入库表">
 INSERT INTO YDM_GP_INLIST(
        INSTOCK_SQE,
        INSTOCK_DOC,
        INSTOCK_TYPE_CODE,
        INSTOCK_TYPE_NAME,
        MAT_NO,
        PRODUCT_FLAG,
        MAT_STATUS,
        STOVE_NO,
        JUDGE_STOVE_NO,
        PLINE_CODE,
        PLINE_NAME,
        PRO_ORDER_NO,
        MATERIAL_NO,
        MATERIAL_NAME,
        GRADECODE,
        GRADENAME,
        STD_CODE,
        STD_NAME,
        DIMATER,
        ACT_LEN,
        FIX_NUM,
        FIX_LEN,
        ACT_COUNT,
        ACT_WEIGHT,
        BELONG_CODE,
        BELONG_NAME,
        INSTOCK_TIME,
        IN_TIME_F,
        BAL_YEAR_MONTH,
        CREATE_NAME,
        CREATE_TIME,
        GROUD_NO,
        PRO_PLAN_ID,
        GX_PLAN_NO,
        JUDGE_STOVE_NO_LG,
        EF_PLINE_CODE,
        EF_PLINE_NAME,
        SOURE_CODE,
        SOURE_NAME,
        STORAGE_NO,
    SUPPLY_UNIT_CODE,
    SUPPLY_UNIT,
    IS_DEALER,
    JUGDE_APPLY_CODE_SQE)
 VALUES( 
        '#INSTOCK_SQE#',
        '#INSTOCK_DOC#',
        '#INSTOCK_TYPE_CODE#',
        '#INSTOCK_TYPE_NAME#',
        '#MAT_NO#',
        '#PRODUCT_FLAG#',
        '#MAT_STATUS#',
        '#STOVE_NO#',
        '#JUDGE_STOVE_NO#',
        '#PLINE_CODE#',
        '#PLINE_NAME#',
        '#PRO_ORDER_NO#',
        '#MATERIAL_NO#',
        '#MATERIAL_NAME#',
        '#GRADECODE#',
        '#GRADENAME#',
        '#STD_CODE#',
        '#STD_NAME#',
        '#DIMATER#',
        '#ACT_LEN#',
        '#FIX_NUM#',
        '#FIX_LEN#',
        '#ACT_COUNT#',
        '#ACT_WEIGHT#',
        '#BELONG_CODE#',
        '#BELONG_NAME#',
        TO_DATE('#INSTOCK_TIME#','YYYY-MM-DD HH24:MI:SS'),
        TO_DATE('#IN_TIME_F#','YYYY-MM-DD HH24:MI:SS'),
        '#BAL_YEAR_MONTH#',
        '#CREATE_NAME#',
        TO_DATE('#CREATE_TIME#','YYYY-MM-DD HH24:MI:SS'),
        '#GROUD_NO#',
        '#PRO_PLAN_ID#',
        '#GX_PLAN_NO#',
        '#JUDGE_STOVE_NO_LG#',
        '#EF_PLINE_CODE#',
        '#EF_PLINE_NAME#',
        '#SOURE_CODE#',
         '#SOURE_NAME#',
         '#STORAGE_NO#',
         '#SUPPLY_UNIT_CODE#',
        '#SUPPLY_UNIT#',
        '#IS_DEALER#',
        '#JUGDE_APPLY_CODE_SQE#')
</query>

    <query id = "FrmGpIqInList.SelectGpInlist" desc = "查询是否存在">
        <![CDATA[
            SELECT
                T.JUGDE_APPLY_CODE_SQE
            FROM
                YDM_GP_INLIST T
            WHERE
                T.INSTOCK_TYPE_CODE = '800709'
                AND T.JUGDE_APPLY_CODE_SQE = {0}
                AND T.JUDGE_STOVE_NO = {1}
            ]]>
    </query>

<query id = "FrmGpIqInList.cancelInsertGpInList" desc = "撤销判定删除产权入库记录">
<![CDATA[
DECLARE
BEGIN
  FOR MYROW IN (SELECT * FROM (
                    SELECT T.MAT_NO
                          FROM YDM_GP_INLIST T
                         WHERE T.STOVE_NO = '#STOVE_NO#'
                           AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                           AND T.FIX_NUM = '#MULTIPLE_NUM#'
                           AND T.INSTOCK_TYPE_CODE = '800709'
                           and decode(T.JUGDE_APPLY_CODE_SQE,'','/',T.JUGDE_APPLY_CODE_SQE) = decode(T.JUGDE_APPLY_CODE_SQE,'','/','#JUGDE_APPLY_CODE_SQE#')
                         ORDER BY T.MAT_NO DESC)
                WHERE ROWNUM <= #ACT_COUNT#)LOOP
    DELETE FROM YDM_GP_INLIST T
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.INSTOCK_TYPE_CODE = '800709';
  END LOOP;
END;
]]>
</query>

    <query id = "FrmGpIqInList.getGpInList" desc = "查询是否已被财务系统接收">
        <![CDATA[
            SELECT
                F.INSTOCK_DOC,
                F.JUDGE_STOVE_NO
            FROM
                YDM_GP_INLIST T
                INNER JOIN FMIS_GP_INLIST F ON t.INSTOCK_DOC = F.INSTOCK_DOC
                AND t.JUDGE_STOVE_NO = F.JUDGE_STOVE_NO
            WHERE
                T.STOVE_NO = '#STOVE_NO#'
                AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                AND T.FIX_NUM = '#MULTIPLE_NUM#'
                AND T.INSTOCK_TYPE_CODE = '800709'
                AND decode( T.JUGDE_APPLY_CODE_SQE, '', '/', T.JUGDE_APPLY_CODE_SQE ) = decode( T.JUGDE_APPLY_CODE_SQE, '', '/', '#JUGDE_APPLY_CODE_SQE#' )
                AND F.SYNC_FLAG = '1'
            GROUP BY
                F.INSTOCK_DOC,
                F.JUDGE_STOVE_NO
            ]]>
    </query>

    <query id = "FrmGpIqInList.delGpInList" desc = "删除财务系统中间表">
        <![CDATA[
          DECLARE
		    BEGIN
				FOR MYROW IN
                    (SELECT
                        F.INSTOCK_DOC,
                        F.JUDGE_STOVE_NO
                    FROM
                        YDM_GP_INLIST T
                        INNER JOIN FMIS_GP_INLIST F ON t.INSTOCK_DOC = F.INSTOCK_DOC
                        AND t.JUDGE_STOVE_NO = F.JUDGE_STOVE_NO
                    WHERE
                        T.STOVE_NO = '#STOVE_NO#'
                        AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                        AND T.FIX_NUM = '#MULTIPLE_NUM#'
                        AND T.INSTOCK_TYPE_CODE = '800709'
                        AND decode( T.JUGDE_APPLY_CODE_SQE, '', '/', T.JUGDE_APPLY_CODE_SQE ) = decode( T.JUGDE_APPLY_CODE_SQE, '', '/', '#JUGDE_APPLY_CODE_SQE#' )
                        AND F.SYNC_FLAG = '0'
                    GROUP BY
                        F.INSTOCK_DOC,
                        F.JUDGE_STOVE_NO) LOOP
                 DELETE FROM FMIS_GP_INLIST D
                 WHERE D.INSTOCK_DOC = MYROW.INSTOCK_DOC
                    AND D.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO;
            END LOOP;
          END;
            ]]>
    </query>
    <query id = "FrmGpIqInList.SelectMatGp" desc = "查询外购坯供应商">
        SELECT *
        FROM (SELECT T.SOURE_CODE, T.SOURE_NAME, S.STORAGE_NO, T.IS_DEALER
        FROM MAT_GP_M T
        LEFT JOIN YDM_GP_BUTTRESS S
        ON T.MAT_NO = S.MAT_NO
        WHERE T.JUGDE_APPLY_CODE = ?
        UNION ALL
        SELECT T.SOURE_CODE, T.SOURE_NAME, '' AS STORAGE_NO, T.IS_DEALER
        FROM MAT_GP_M_HISTORY T
        WHERE T.JUGDE_APPLY_CODE = ?)
        WHERE ROWNUM = 1
    </query>
</queryMap>