<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "管坯入库">
<query id = "FrmStuffInputStore.doQuery" desc = "查询切割实绩">
<![CDATA[
SELECT 
       STOVE_NO,
       GRADENAME,
       CAST_NO,
       HEATCNT,
       LENGTH,
       sum(WEIGHT)WEIGHT,
       DIAMETER,
       DECODE(FLAG,'0','未收料','1','已收料')FLAG,
       PRODORDERNO,
       STANDARDSCODE,
       STANDARDREMAK,
       FLAG_STOVE_NO,
       PRO_ORDER_NO,
       LEN_MIN,
       LEN_MAX,
       FIX_NUM,
       FIX_LEN,
       JUDGE_STOVE_NO,
       BATCH_GROUD_NO,
       SUM(ACT_COUNT) ACT_COUNT,
       MATERIAL_NAME,
       PRODUCNAME
 FROM STL_INCISION
 WHERE STOVE_NO || '&' LIKE ('%' || ? || '%')
 AND JUDGE_STOVE_NO || '&' LIKE ('%' || ? || '%')
 GROUP BY STOVE_NO,
       GRADENAME,
       CAST_NO,
       HEATCNT,
       LENGTH,
       WEIGHT,
       DIAMETER,
       FLAG,
       PRODORDERNO,
       STANDARDSCODE,
       STANDARDREMAK,
       FLAG_STOVE_NO,
       PRO_ORDER_NO,
       LEN_MIN,
       LEN_MAX,
       FIX_NUM,
       FIX_LEN,
       JUDGE_STOVE_NO,
       BATCH_GROUD_NO,
       ACT_COUNT,
       MATERIAL_NAME,
       PRODUCNAME
       ]]>
</query>
<query id = "FrmStuffInputStore.doQueryMat" desc = "查询收料实绩">
<![CDATA[
 SELECT 
       max(TO_CHAR(T.INSTOCK_TIME, 'YYYY-MM-DD HH24:MI:SS')) INSTOCK_TIME,
       T.MEMO,
       T.PRODUCT_FLAG,
       T.MAT_STATUS,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.GROUD_NO,
       T.CAST_NO,
       T.CCMID,
       T.SAMPLE_FLAG,
       T.CUTTING_FLAG,
       T.CUTTING_NUM,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.JUDGE_GRADECODE,
       T.JUDGE_GRADENAME,
       T.JUDGE_STD_CODE,
       T.JUDGE_STD_NAME,
       T.PRO_ORDER_NO,
       T.PRO_ORDER_ID,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.ACT_DIMATER,
       sum(nvl(T.ACT_LEN,0))ACT_LEN,
       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       T.ACT_FIX_NUM,
       T.ACT_FIX_LEN,
       sum(T.ACT_COUNT)ACT_COUNT,
       sum(T.ACT_THEORY_WEIGHT)ACT_THEORY_WEIGHT,
       T.BELONG_CODE,
       T.BELONG_NAME 
 FROM MAT_GP_M T
 WHERE T.Stove_No || '&'LIKE ('%'||?||'%')
 AND T.JUDGE_STOVE_NO || '&' LIKE ('%' || ? || '%')
 group by 
 T.MEMO,
       T.PRODUCT_FLAG,
       T.MAT_STATUS,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.GROUD_NO,
       T.CAST_NO,
       T.CCMID,
       T.SAMPLE_FLAG,
       T.CUTTING_FLAG,
       T.CUTTING_NUM,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.JUDGE_GRADECODE,
       T.JUDGE_GRADENAME,
       T.JUDGE_STD_CODE,
       T.JUDGE_STD_NAME,
       T.PRO_ORDER_NO,
       T.PRO_ORDER_ID,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.ACT_DIMATER,
       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       T.ACT_FIX_NUM,
       T.ACT_FIX_LEN,
       T.BELONG_CODE,
       T.BELONG_NAME 
 ]]>
</query>
<query id = "FrmStuffInputStore.selectStlIn" desc = "查询收割实绩材料状态">
SELECT COUNT(T.ACT_COUNT) ACOUNT
             FROM STL_INCISION T
            WHERE NVL(T.STOVE_NO,'/') = NVL(?,'/')
              AND T.JUDGE_STOVE_NO = ?
              AND T.BATCH_GROUD_NO = ?
              AND NVL(T.LEN_MIN,0) = NVL(?,0)
              AND NVL(T.LEN_MAX,0) = NVL(?,0)
              AND NVL(T.FIX_NUM,0) = NVL(?,0)
              AND NVL(T.FIX_LEN,0) = NVL(?,0)
              AND T.FLAG = '1'
</query>
<query id = "FrmStuffInputStore.doQueryInList" desc = "查询入库实绩">
<![CDATA[
 SELECT 
       GROUD_NO,
       MATERIAL_NAME,
       PRODUCNAME,
       JUDGE_GRADENAME,
       JUDGE_STD_NAME,
       ACT_DIMATER,
       sum(nvl(ACT_LEN,0))ACT_LEN,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_FIX_NUM,
       ACT_FIX_LEN,
       SUM(ACT_COUNT)ACT_COUNT,
       SUM(ACT_THEORY_WEIGHT)ACT_THEORY_WEIGHT,
       BELONG_NAME,
       STORAGE_NO,
       DEPARTMENT_CODE,
       DEPARTMENT_DESC,
       MANAGEMENT_NO,
       MANAGEMENT_NAME,
       MAX(TO_CHAR(INSTOCK_TIME, 'YYYY-MM-DD HH24:MI:SS')) INSTOCK_TIME,
       MAX(TO_CHAR(IN_TIME_F, 'YYYY-MM-DD HH24:MI:SS')) IN_TIME_F,
       BAL_YEAR_MONTH,
       MEMO,
       CREATE_NAME,
       INSTOCK_DOC,
       INSTOCK_TYPE_NAME,
       STOVE_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       CAST_NO,
       CCMID,
       SAMPLE_FLAG,
       CUTTING_FLAG,
       CUTTING_NUM,
       PLINE_NAME,
       PRO_ORDER_NO,
       PRO_ORDER_ID,
       ORDER_NO,
       ORDER_SEQ,
       ORDER_SEQ_NO
 FROM YMD_GP_INLIST
 WHERE STOVE_NO || '&'LIKE ('%'||?||'%')
 AND JUDGE_STOVE_NO || '&' LIKE ('%' || ? || '%')
 GROUP BY GROUD_NO,
       MATERIAL_NAME,
       PRODUCNAME,
       JUDGE_GRADENAME,
       JUDGE_STD_NAME,
       ACT_DIMATER,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_FIX_NUM,
       ACT_FIX_LEN,
       BELONG_NAME,
       STORAGE_NO,
       DEPARTMENT_CODE,
       DEPARTMENT_DESC,
       MANAGEMENT_NO,
       MANAGEMENT_NAME,
       BAL_YEAR_MONTH,
       MEMO,
       CREATE_NAME,
       INSTOCK_DOC,
       INSTOCK_TYPE_NAME,
       STOVE_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       CAST_NO,
       CCMID,
       SAMPLE_FLAG,
       CUTTING_FLAG,
       CUTTING_NUM,
       PLINE_NAME,
       PRO_ORDER_NO,
       PRO_ORDER_ID,
       ORDER_NO,
       ORDER_SEQ,
       ORDER_SEQ_NO
       ]]>
</query>
<query id = "FrmStuffInputStore.receiveData" desc = "插入收料数据">
<![CDATA[
DECLARE
  V_TIME MAT_GP_M.INSTOCK_TIME%TYPE := SYSDATE;
  V_BATHYEAR MAT_GP_M.BAL_YEAR_MONTH%TYPE := TO_CHAR(SYSDATE,'YYYYMM');
BEGIN
  FOR MYROW IN (SELECT T.*
                  FROM STL_INCISION T
                 WHERE T.STOVE_NO = ?
                   AND T.JUDGE_STOVE_NO = ?
                   AND T.BATCH_GROUD_NO = ?
                   AND NVL(T.LEN_MIN,0) = NVL(?,0)
                   AND NVL(T.LEN_MAX,0) = NVL(?,0)
                   AND NVL(T.FIX_NUM,0) = NVL(?,0)
                   AND NVL(T.FIX_LEN,0) = NVL(?,0)
                   ORDER BY T.MAT_NO DESC) LOOP
         INSERT INTO MAT_GP_M(
        INSTOCK_TIME,
        BAL_YEAR_MONTH,
        MEMO,
        CREATE_NAME,
        CREATE_TIME,
        GROUD_NO,
        MAT_NO,
        PRODUCT_FLAG,
        MAT_STATUS,
        STOVE_NO,
        FLAG_STOVE_NO,
        JUDGE_STOVE_NO,
        CAST_NO,
        CCMID,
        SAMPLE_FLAG,
        CUTTING_FLAG,
        
        MAT_ORIGIN_CODE,
        MAT_ORIGIN_NAME,
        SOURE_CODE,
        SOURE_NAME,
        MATERIAL_NO,
        MATERIAL_NAME,
        PRODUCCODE,
        PRODUCNAME,
        JUDGE_GRADECODE,
        JUDGE_GRADENAME,
        JUDGE_STD_CODE,
        JUDGE_STD_NAME,
        PRO_ORDER_NO,
        PRO_ORDER_ID,
        ORDER_NO,
        ORDER_SEQ,
        ORDER_SEQ_NO,
        ORD_PK,
        ORD_LN_PK,
        ORD_LN_DLY_PK,
        PLINE_CODE,
        PLINE_NAME,
        ACT_DIMATER,
        ACT_HEIGHT,
        ACT_LEN,
        ACT_LEN_MIN,
        ACT_LEN_MAX,
        ACT_FIX_NUM,
        ACT_FIX_LEN,
        ACT_COUNT,
        ACT_WEIGHT,
        ACT_THEORY_WEIGHT,
        BELONG_CODE,
        BELONG_NAME)
 VALUES( 
        V_TIME,
        V_BATHYEAR,
        '',
        ?,
        V_TIME,
        MYROW.BATCH_GROUD_NO,
        MYROW.MAT_NO,
        '801501',
        '80150101',
        MYROW.STOVE_NO,
        MYROW.FLAG_STOVE_NO,
        MYROW.JUDGE_STOVE_NO,
        MYROW.CAST_NO,
        MYROW.CCMID,
        '0',
        '0',
        '',
        '',
        '',
        '',
        MYROW.MATERIAL_NO,
        MYROW.MATERIAL_NAME,
        MYROW.PRODUCCODE,
        MYROW.PRODUCNAME,
        MYROW.GRADECODE,
        MYROW.GRADENAME,
        MYROW.STANDARDSCODE,
        MYROW.STANDARDREMAK,
        MYROW.PRO_ORDER_NO,
        MYROW.PRODORDERNO,
        MYROW.ORDER_NO,
        MYROW.ORDER_SEQ,
        MYROW.DELIVERY_NO,
        MYROW.ORD_PK,
        MYROW.ORD_LN_PK,
        MYROW.ORD_LN_DLY_PK,
        '',
        '',
        MYROW.DIAMETER,
        '',
        '',
        MYROW.LEN_MIN,
        MYROW.LEN_MAX,
        MYROW.FIX_NUM,
        MYROW.FIX_LEN,
        MYROW.ACT_COUNT,
        '',
        MYROW.WEIGHT,
        '',
        ''
        );
        UPDATE STL_INCISION T SET T.FLAG = '1' WHERE T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
END;
]]>
</query>
<query id = "FrmStuffInputStore.cancelReceive" desc = "撤销收料">
<![CDATA[
DECLARE
BEGIN
  FOR MYROW IN (SELECT T.Mat_No
                  FROM Mat_Gp_m T
                 WHERE T.STOVE_NO = ?
                   AND T.JUDGE_STOVE_NO = ?
                   AND T.Groud_No = ?
                   AND NVL(T.Act_Len_Min,0) = NVL(?,0)
                   AND NVL(T.Act_Len_Max,0) = NVL(?,0)
                   AND NVL(T.Act_Fix_Num,0) = NVL(?,0)
                   AND NVL(T.Act_Fix_Len,0) = NVL(?,0)
                   ORDER BY T.MAT_NO DESC) LOOP
        Delete mat_gp_m t where t.mat_no = myrow.mat_no;
        UPDATE STL_INCISION T SET T.FLAG = '0' WHERE T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
END;
]]>
</query>
<query id = "FrmStuffInputStore.getStoreType" desc = "查询仓库类型">
SELECT T.STORAGE_ATTR,
       T.STORAGE_ATTR_NAME,
       T.STORAGE_TYPE_NO,
       T.STORAGE_TYPE_NAME
  FROM YDM_BS_STORAGE T
 WHERE T.STORAGE_NO = ?
</query>
<query id = "FrmStuffInputStore.ensureInPutData" desc= "确认入库">
<![CDATA[
DECLARE
  v_Instock_doc ymd_gp_inlist.instock_doc%type := null; --入库单号
  v_instock_sqe ymd_gp_inlist.instock_sqe%type := null; --入库流水
  v_Imemo       com_base_info.memo%type := null;
  v_baseName    com_base_info.basename%type := null;
  v_Icount      NUMBER := 1;
  v_time        ymd_gp_inlist.create_time%type := sysdate;
  v_bathYear    ymd_gp_inlist.bal_year_month%type := to_char(sysdate,
                                                             'yyyyMM');
BEGIN
  --生成入库单号
  select memo, BASENAME
    into v_Imemo, v_baseName
    from com_base_info
   where basecode = ?;
  select v_Imemo || to_char(sysdate, 'yymmdd') ||
         Lpad(NVL(MAX(substr(t.instock_doc, 9)), 0) + 1, 5, 0) instock_doc
    into v_Instock_doc
    from ymd_gp_inlist t
   where t.instock_type_code = ?
     AND to_char(t.CREATE_TIME, 'YYYY-MM-DD') =
         to_char(sysdate, 'YYYY-MM-DD');
  FOR MYROW IN (SELECT T.*
                  FROM Mat_Gp_m T
                 WHERE T.STOVE_NO = ?
                   AND T.JUDGE_STOVE_NO = ?
                   AND T.Groud_No = ?
                   AND NVL(T.Act_Len_Min, 0) = NVL(?, 0)
                   AND NVL(T.Act_Len_Max, 0) = NVL(?, 0)
                   AND NVL(T.Act_Fix_Num, 0) = NVL(?, 0)
                   AND NVL(T.Act_Fix_Len, 0) = NVL(?, 0)
                 ORDER BY T.MAT_NO DESC) LOOP
    INSERT INTO YDM_GP_BUTTRESS
      (GROUD_NO,
       MAT_NO,
       STOVE_NO,
       FLAG_STOVE_NO,
       LOT_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       STORAGE_NO,
       LOCATION_NO,
       STORAGE_ATTR,
       STORAGE_ATTR_NAME,
       STORAGE_TYPE_NO,
       STORAGE_TYPE_NAME,
       DEPARTMENT_CODE,
       DEPARTMENT_DESC,
       MANAGEMENT_NO,
       MANAGEMENT_NAME,
       MEMO,
       CREATE_NAME,
       CREATE_TIME)
    VALUES
      (myrow.groud_no,
       myrow.mat_no,
       myrow.STOVE_NO,
       myrow.FLAG_STOVE_NO,
       myrow.LOT_NO,
       myrow.JUDGE_STOVE_NO,
       myrow.BATCH_NO,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       myrow.memo,
       ?,
       v_time);
    v_instock_sqe := v_Instock_doc || Lpad(v_Icount, 4, 0);
    INSERT INTO YMD_GP_INLIST
      (GROUD_NO,
       MAT_ORIGIN_CODE,
       MAT_ORIGIN_NAME,
       SOURE_CODE,
       SOURE_NAME,
       MATERIAL_NO,
       MATERIAL_NAME,
       PRODUCCODE,
       PRODUCNAME,
       JUDGE_GRADECODE,
       JUDGE_GRADENAME,
       JUDGE_STD_CODE,
       JUDGE_STD_NAME,
       ACT_DIMATER,
       ACT_HEIGHT,
       ACT_LEN,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_FIX_NUM,
       ACT_FIX_LEN,
       ACT_COUNT,
       ACT_WEIGHT,
       ACT_THEORY_WEIGHT,
       BELONG_CODE,
       BELONG_NAME,
       STORAGE_NO,
       LOCATION_NO,
       DEPARTMENT_CODE,
       DEPARTMENT_DESC,
       MANAGEMENT_NO,
       MANAGEMENT_NAME,
       INSTOCK_TIME,
       IN_TIME_F,
       BAL_YEAR_MONTH,
       STORAGE_ATTR,
       STORAGE_ATTR_NAME,
       STORAGE_TYPE_NO,
       STORAGE_TYPE_NAME,
       MEMO,
       CREATE_NAME,
       CREATE_TIME,
       INSTOCK_SQE,
       INSTOCK_DOC,
       INSTOCK_TYPE_CODE,
       INSTOCK_TYPE_NAME,
       MAT_NO,
       PRODUCT_FLAG,
       MAT_STATUS,
       STOVE_NO,
       FLAG_STOVE_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       CAST_NO,
       CCMID,
       SAMPLE_FLAG,
       CUTTING_FLAG,
       CUTTING_NUM,
       PLINE_CODE,
       PLINE_NAME,
       PRO_ORDER_NO,
       PRO_ORDER_ID,
       ORDER_NO,
       ORDER_SEQ,
       ORDER_SEQ_NO,
       ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK)
    VALUES
      (myrow.GROUD_NO,
       myrow.MAT_ORIGIN_CODE,
       myrow.MAT_ORIGIN_NAME,
       myrow.SOURE_CODE,
       myrow.SOURE_NAME,
       myrow.MATERIAL_NO,
       myrow.MATERIAL_NAME,
       myrow.PRODUCCODE,
       myrow.PRODUCNAME,
       myrow.judge_gradecode,
       myrow.JUDGE_GRADENAME,
       myrow.JUDGE_STD_CODE,
       myrow.JUDGE_STD_NAME,
       myrow.ACT_DIMATER,
       myrow.ACT_HEIGHT,
       myrow.ACT_LEN,
       myrow.ACT_LEN_MIN,
       myrow.ACT_LEN_MAX,
       myrow.ACT_FIX_NUM,
       myrow.ACT_FIX_LEN,
       myrow.ACT_COUNT,
       myrow.ACT_WEIGHT,
       myrow.ACT_THEORY_WEIGHT,
       myrow.BELONG_CODE,
       myrow.BELONG_NAME,
       ?,
       ?,
       ?,
       ?,
       ?,
       ?,
       v_time,
       v_time,
       v_bathYear,
       ?,
       ?,
       ?,
       ?,
       myrow.memo,
       ?,
       v_time,
       v_instock_sqe,
       v_Instock_doc,
       ?,
       v_baseName,
       myrow.mat_no,
       myrow.PRODUCT_FLAG,
       myrow.MAT_STATUS,
       myrow.STOVE_NO,
       myrow.FLAG_STOVE_NO,
       myrow.JUDGE_STOVE_NO,
       myrow.BATCH_NO,
       myrow.CAST_NO,
       myrow.CCMID,
       myrow.SAMPLE_FLAG,
       myrow.CUTTING_FLAG,
       myrow.CUTTING_NUM,
       myrow.PLINE_CODE,
       myrow.PLINE_NAME,
       myrow.PRO_ORDER_NO,
       myrow.PRO_ORDER_ID,
       myrow.ORDER_NO,
       myrow.ORDER_SEQ,
       myrow.ORDER_SEQ_NO,
       myrow.ORD_PK,
       myrow.ORD_LN_PK,
       myrow.ORD_LN_DLY_PK);
    UPDATE mat_gp_m T SET T.JUGDE_APPLY_FLAG = '1',T.INSTOCK_FLAG = '1',T.Product_Flag = '801402',T.mat_status = '80150201' WHERE T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
END;
]]>
</query>
<query id = "FrmStuffInputStore.cancelInPutData" desc = "撤销入库">
<![CDATA[
DECLARE
BEGIN
  FOR MYROW IN (SELECT T.MAT_NO
                  FROM YMD_GP_INLIST T
                 WHERE T.INSTOCK_DOC = ?
                 ORDER BY T.MAT_NO DESC) LOOP
    DELETE YDM_GP_BUTTRESS S WHERE S.MAT_NO = MYROW.MAT_NO;
    UPDATE MAT_GP_M T SET T.JUGDE_APPLY_FLAG = '0',T.INSTOCK_FLAG = '0',T.PRODUCT_FLAG = '801401',T.MAT_STATUS = '80150101' WHERE T.MAT_NO = MYROW.MAT_NO;
    DELETE YMD_GP_INLIST T WHERE T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
END;
]]>
</query>
</queryMap>