<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "判定后自动确认管理">
<query id = "FrmBcIqInList.insertBcIqInList" desc = "产权转移写半成品入库表">
<![CDATA[
DECLARE
  V_INSTOCK_SQE YDM_BC_INLIST.INSTOCK_SQE%TYPE := NULL;
  V_COUNT       NUMBER := 1;
  V_INCOUNT     NUMBER := 0;
  V_ACT_WEIGHT YDM_BC_INLIST.ACT_WEIGHT%TYPE := NULL;
BEGIN
  SELECT LPAD(NVL(MAX(SUBSTR(T.INSTOCK_SQE, LENGTH(T.INSTOCK_SQE) - 3)), 0) + 1,
              4,
              0) INSTOCK_SQE
    INTO V_COUNT
    FROM YDM_BC_INLIST T
   WHERE T.INSTOCK_DOC = '#INSTOCK_DOC#';
  FOR MYROW IN (SELECT *
                  FROM (SELECT * FROM (SELECT *
                          FROM MAT_BC_M T1
                         WHERE T1.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
                           AND T1.JUGDE_APPLY_SEQUENO =
                               '#JUGDE_APPLY_SEQUENO#'
                           AND T1.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                           AND T1.BATCH_NO = '#BATCH_NO#'
                           AND T1.QCM_STAUS = '00')
                           WHERE ROWNUM <= #ACT_COUNT#
                        UNION ALL
                        SELECT * FROM (SELECT *
                          FROM MAT_BC_BACKUP T2
                         WHERE T2.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
                           AND T2.JUGDE_APPLY_SEQUENO =
                               '#JUGDE_APPLY_SEQUENO#'
                           AND T2.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                           AND T2.BATCH_NO = '#BATCH_NO#'
                           AND T2.QCM_STAUS = '00')WHERE ROWNUM <= #ACT_COUNT#) T
                 ORDER BY T.MAT_NO ASC) LOOP
    V_INSTOCK_SQE := '#INSTOCK_DOC#' || LPAD(V_COUNT, 4, 0);
    SELECT COUNT(1)INTO V_INCOUNT FROM YDM_BC_INLIST T WHERE T.MAT_NO = MYROW.MAT_NO AND T.PLINE_CODE = MYROW.PLINE_CODE AND T.BELONG_CODE=MYROW.BELONG_CODE
    AND T.INSTOCK_TYPE_CODE = '800709';
    IF(NVL(MYROW.PONDER_GROSS_WT,0) = 0)THEN
    V_ACT_WEIGHT := MYROW.ACT_WEIGHT;
    ELSE
    V_ACT_WEIGHT := MYROW.PONDER_GROSS_WT;
    END IF;
    IF(V_INCOUNT = 0)THEN
    INSERT INTO YDM_BC_INLIST
      (INSTOCK_SQE,
       INSTOCK_DOC,
       INSTOCK_TYPE_CODE,
       INSTOCK_TYPE_NAME,
       MAT_NO,
       LOT_NO,
       STOVE_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,
       PRO_ORDER_NO,
       PLINE_CODE,
       PLINE_NAME,
       ACT_DIMATER,
       ACT_HEIGHT,
       ACT_LEN,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_COUNT,
       ACT_WEIGHT,
       ACT_THEORY_WEIGHT,
       BELONG_CODE,
       BELONG_NAME,
       INSTOCK_TIME,
       CREATE_NAME,
       CREATE_TIME,
       ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK,
       ORDER_NO,
       ORDER_SEQ,
       DELIVERY_NO,
       PRODUCT_FLAG,
       MAT_STATUS,
       JUDGE_STD_NAME,
       IN_TIME_F,
       BAL_YEAR_MONTH,
       QCM_STAUS,
       PROCESS_CDOE,
       PROCESS_DESC,
       SOURE_CODE,
       SOURE_NAME)
    VALUES
      (V_INSTOCK_SQE,
       '#INSTOCK_DOC#',
       '800709',
       '产权入库',
       MYROW.MAT_NO,
       MYROW.LOT_NO,
       MYROW.STOVE_NO,
       MYROW.JUDGE_STOVE_NO,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_NAME,
       MYROW.PRODUCCODE,
       MYROW.PRODUCNAME,
       MYROW.STD_CODE,
       MYROW.STD_NAME,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       MYROW.STEELCODE,
       MYROW.STEELNAME,
       MYROW.STD_STYLE,
       MYROW.STD_STYLE_DESC,
       MYROW.SPEC_CODE,
       MYROW.SPEC_NAME,
       MYROW.MODEL_CODE,
       MYROW.MODEL_DESC,
       MYROW.PRO_ORDER_NO,
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.ACT_DIMATER,
       MYROW.ACT_HEIGHT,
       MYROW.ACT_LEN,
       MYROW.ACT_LEN_MIN,
       MYROW.ACT_LEN_MAX,
       MYROW.ACT_COUNT,
       V_ACT_WEIGHT,
       MYROW.ACT_THEORY_WEIGHT,
       '#BELONG_CODE_JUGDE#',
       '#BELONG_NAME_JUGDE#',
       TO_DATE('#APPLY_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       '#APPLY_NAME#',
       TO_DATE('#APPLY_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       MYROW.ORD_PK,
       MYROW.ORD_LN_PK,
       MYROW.ORD_LN_DLY_PK,
       MYROW.ORDER_NO,
       MYROW.ORDER_SEQ,
       MYROW.ORDER_SEQ_NO,
       MYROW.PRODUCT_FLAG,
       MYROW.MAT_STATUS,
       MYROW.JUDGE_STD_DES,
       TO_DATE('#APPLY_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       '#BAL_YEAR_MONTH#',
       MYROW.QCM_STAUS,
       MYROW.PROCESS_CDOE,
       MYROW.PROCESS_DESC,
       MYROW.SOURE_CODE,
       MYROW.SOURE_NAME);
    V_COUNT := V_COUNT + 1;
    END IF;
    
  END LOOP;
  UPDATE QCM_ZG_JUGDE_APPLY T
     SET T.INSTOCK_FLAG = '1'
   WHERE T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
     AND T.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#'
     AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     AND T.BATCH_NO = '#BATCH_NO#';
END;
]]>
</query>
<query id = "FrmBcIqInList.cancelInsertBcInList" desc = "删除产权转移入库记录">
DECLARE
BEGIN
  FOR MYROW IN (SELECT T.MAT_NO,T.PLINE_CODE
                  FROM MAT_BC_M T
                 WHERE T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
                   AND T.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#'
                   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                   AND T.BATCH_NO = '#BATCH_NO#'
                 ORDER BY T.MAT_NO ASC) LOOP
    DELETE FROM YDM_BC_INLIST T
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.INSTOCK_TYPE_CODE = '800709'
       AND T.PLINE_CODE = MYROW.PLINE_CODE
       AND T.BELONG_CODE ='#BELONG_CODE_JUGDE#';
  END LOOP;
  UPDATE QCM_ZG_JUGDE_APPLY T
     SET T.INSTOCK_FLAG = '0'
   WHERE T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
     AND T.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#'
     AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     AND T.BATCH_NO = '#BATCH_NO#';
END;
</query>
<query id = "FrmBcIqInList.getInListDoc" desc = "获取入库单号">
SELECT 'IQ' || TO_CHAR(SYSDATE, 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.INSTOCK_DOC, 9)), 0) + 1, 5, 0) INSTOCK_DOC
    FROM YDM_BC_INLIST T
   WHERE T.INSTOCK_TYPE_CODE = ?
     AND TRUNC(T.CREATE_TIME) = TRUNC(TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'))
</query>
<query id = "FrmBcIqInList.deleteMatBcM" desc = "产销判定2自动转移历史表">
<![CDATA[
DECLARE
BEGIN
  FOR MYROW IN (SELECT *
                  FROM (SELECT *
                          FROM (SELECT *
                                  FROM MAT_BC_M T1
                                 WHERE T1.JUGDE_APPLY_CODE =
                                       '#JUGDE_APPLY_CODE#'
                                   AND T1.JUGDE_APPLY_SEQUENO =
                                       '#JUGDE_APPLY_SEQUENO#'
                                   AND T1.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                                   AND T1.BATCH_NO = '#BATCH_NO#'
                                   AND T1.QCM_STAUS = '00')
                         WHERE ROWNUM <= #ACT_COUNT#)
                 ORDER BY MAT_NO ASC) LOOP
  INSERT INTO MAT_BC_BACKUP
      SELECT *
        FROM MAT_BC_M T
       WHERE T.MAT_NO = MYROW.MAT_NO
         AND T.PLINE_CODE = MYROW.PLINE_CODE;
  DELETE FROM MAT_BC_M T WHERE T.MAT_NO = MYROW.MAT_NO AND T.PLINE_CODE = MYROW.PLINE_CODE;
  DELETE FROM YDM_BC_BUTTRESS T WHERE T.MAT_NO = MYROW.MAT_NO; 
  END LOOP;
  UPDATE QCM_ZG_JUGDE_APPLY T
     SET T.INSTOCK_FLAG = '0'
   WHERE T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
     AND T.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#'
     AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     AND T.BATCH_NO = '#BATCH_NO#';
END;
]]>
</query>
<query id = "FrmBcIqInList.insertMatBcM" desc = "撤销成品判定时恢复半成品表">
<![CDATA[
DECLARE
BEGIN
  FOR MYROW IN (SELECT *
                  FROM (SELECT *
                          FROM (SELECT *
                                  FROM MAT_BC_BACKUP T1
                                 WHERE T1.JUGDE_APPLY_CODE =
                                       '#JUGDE_APPLY_CODE#'
                                   AND T1.JUGDE_APPLY_SEQUENO =
                                       '#JUGDE_APPLY_SEQUENO#'
                                   AND T1.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                                   AND T1.BATCH_NO = '#BATCH_NO#'
                                   AND T1.QCM_STAUS = '00')
                         WHERE ROWNUM <= #ACT_COUNT#)
                 ORDER BY MAT_NO ASC) LOOP
    INSERT INTO YDM_BC_BUTTRESS
      (MAT_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       STORAGE_NO,
       LOCATION_NO,
       LARY_NO,
       CREATE_NAME,
       CREATE_TIME)
    VALUES
      (MYROW.MAT_NO,
       MYROW.JUDGE_STOVE_NO,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       (SELECT S.STORAGE_NO
          FROM COM_BASE_PLINE T, YDM_BS_STORAGE S
         WHERE T.DEPARTMENT_CODE = S.MANAGEMENT_NO
           AND T.PLINE_CODE = MYROW.PLINE_CODE
           AND ROWNUM = 1),
       (SELECT S.STORAGE_NO
          FROM COM_BASE_PLINE T, YDM_BS_STORAGE S
         WHERE T.DEPARTMENT_CODE = S.MANAGEMENT_NO
           AND T.PLINE_CODE = MYROW.PLINE_CODE
           AND ROWNUM = 1) || '00001',
       '1',
       MYROW.CREATE_NAME,
       MYROW.CREATE_TIME);
    INSERT INTO MAT_BC_M
      SELECT *
        FROM MAT_BC_BACKUP T
       WHERE T.MAT_NO = MYROW.MAT_NO
         AND T.PLINE_CODE = MYROW.PLINE_CODE;
    DELETE FROM MAT_BC_BACKUP T
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.PLINE_CODE = MYROW.PLINE_CODE;
  END LOOP;
  UPDATE QCM_ZG_JUGDE_APPLY T
     SET T.INSTOCK_FLAG = '0'
   WHERE T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
     AND T.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#'
     AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     AND T.BATCH_NO = '#BATCH_NO#';
END;
]]>
</query>

    <query id = "FrmBcIqInList.getFmisBcInlist" desc = "查询是否被财务系统接收">
        <![CDATA[
            SELECT
                Y.INSTOCK_DOC,
                Y.JUDGE_STOVE_NO,
                Y.BATCH_NO,
                Y.BATCH_GROUD_NO
            FROM
                MAT_BC_M T
                INNER JOIN YDM_BC_INLIST Y ON T.MAT_NO = Y.MAT_NO
                INNER JOIN FMIS_BC_INLIST F ON Y.INSTOCK_DOC = F.INSTOCK_DOC
                    AND Y.JUDGE_STOVE_NO = F.JUDGE_STOVE_NO
                    AND Y.BATCH_NO = F.BATCH_NO
                    AND Y.BATCH_GROUD_NO = F.BATCH_GROUD_NO
            WHERE
                T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
                AND T.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#'
                AND Y.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                AND Y.BATCH_NO = '#BATCH_NO#'
                AND Y.BELONG_CODE = '#BELONG_CODE_JUGDE#'
                AND F.SYNC_FLAG = '1'
            GROUP BY
                Y.INSTOCK_DOC,
                Y.JUDGE_STOVE_NO,
                Y.BATCH_NO,
                Y.BATCH_GROUD_NO
        ]]>
    </query>

    <query id = "FrmBcIqInList.delFmisBcInlist" desc = "删除财务系统中间表">
        <![CDATA[
          DECLARE
		    BEGIN
				FOR MYROW IN
                    (SELECT
                        Y.INSTOCK_DOC,
                        Y.JUDGE_STOVE_NO,
                        Y.BATCH_NO,
                        Y.BATCH_GROUD_NO
                    FROM
                        MAT_BC_M T
                        INNER JOIN YDM_BC_INLIST Y ON T.MAT_NO = Y.MAT_NO
                        INNER JOIN FMIS_BC_INLIST F ON Y.INSTOCK_DOC = F.INSTOCK_DOC
                            AND Y.JUDGE_STOVE_NO = F.JUDGE_STOVE_NO
                            AND Y.BATCH_NO = F.BATCH_NO
                            AND Y.BATCH_GROUD_NO = F.BATCH_GROUD_NO
                    WHERE
                        T.JUGDE_APPLY_CODE = '#JUGDE_APPLY_CODE#'
                        AND T.JUGDE_APPLY_SEQUENO = '#JUGDE_APPLY_SEQUENO#'
                        AND Y.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                        AND Y.BATCH_NO = '#BATCH_NO#'
                        AND Y.BELONG_CODE = '#BELONG_CODE_JUGDE#'
                        AND F.SYNC_FLAG = '0'
                    GROUP BY
                        Y.INSTOCK_DOC,
                        Y.JUDGE_STOVE_NO,
                        Y.BATCH_NO,
                        Y.BATCH_GROUD_NO) LOOP
                 DELETE FROM FMIS_BC_INLIST D
                 WHERE D.INSTOCK_DOC = MYROW.INSTOCK_DOC
                    AND D.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
                    AND D.BATCH_NO = MYROW.BATCH_NO
                    AND D.BATCH_GROUD_NO = MYROW.BATCH_GROUD_NO;
            END LOOP;
          END;
        ]]>
    </query>
</queryMap>