<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "倒库出库">
<query id = "FrmStuffMoveOut.doQuery" desc = "查询库存实绩">
<![CDATA[
 SELECT 
       max(TO_CHAR(T.INSTOCK_TIME, 'YYYY-MM-DD HH24:MI:SS')) INSTOCK_TIME,
       T.MEMO,
       --(SELECT C.BASENAME FROM COM_BASE_INFO C WHERE C.BASECODE =  T.PRODUCT_FLAG) PRODUCT_FLAG,
       --(SELECT D.BASENAME FROM COM_BASE_INFO D WHERE D.BASECODE =  T.MAT_STATUS)MAT_STATUS,
       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,
       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_WEIGHT)ACT_WEIGHT,
       T.BELONG_CODE,
       T.BELONG_NAME,
       (SELECT C.STORAGE_NAME FROM YDM_BS_STORAGE C WHERE C.STORAGE_NO = S.STORAGE_NO)STORAGE_NAME,
       S.STORAGE_NO
 FROM MAT_GP_M T,YDM_GP_BUTTRESS S
 --LEFT JOIN ydm_bs_storage T1 ON S.STORAGE_NO=T1.STORAGE_NO
 WHERE T.MAT_NO = S.MAT_NO 
 AND T.MAT_STATUS<>'80150302'
 AND T.JUDGE_STOVE_NO || '&' LIKE ('%' || ? || '%')
 ]]>
</query>
<query id = "FrmStuffMoveOut.doQueryOutList" desc = " 查询出库实绩">
<![CDATA[
 SELECT 
       OUTSTOCK_PLAN_NO,
       OUTSTOCK_DOC,
       OUTSTOCK_TYPE_CODE,
       OUTSTOCK_TYPE_NAME,
       VEHICLE_NO,
       (SELECT C.BASENAME FROM COM_BASE_INFO C WHERE C.BASECODE =  PRODUCT_FLAG) PRODUCT_FLAG,
       (SELECT D.BASENAME FROM COM_BASE_INFO D WHERE D.BASECODE =  MAT_STATUS)MAT_STATUS,
       STOVE_NO,
       FLAG_STOVE_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       CAST_NO,
       CCMID,
       SAMPLE_FLAG,
       CUTTING_FLAG,
       CUTTING_NUM,
       MATERIAL_NO,
       MATERIAL_NAME,
       PRODUCCODE,
       PRODUCNAME,
       JUDGE_GRADECODE,
       JUDGE_GRADENAME,
       JUDGE_STD_CODE,
       JUDGE_STD_NAME,
       ACT_DIMATER,
       ACT_LEN,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_FIX_NUM,
       ACT_FIX_LEN,
       ACT_COUNT,
       ACT_WEIGHT,
       PLINE_CODE,
       PLINE_NAME,
       PRO_ORDER_NO,
       PRO_ORDER_ID,
       BELONG_CODE,
       BELONG_NAME,
       (SELECT C.STORAGE_NAME FROM YDM_BS_STORAGE C WHERE C.STORAGE_NO = STORAGE_NO)STORAGE_NO,
       (SELECT C.STORAGE_NAME FROM YDM_BS_STORAGE C WHERE C.STORAGE_NO = TAR_STORAGE_NO)TAR_STORAGE_NO,
       DECODE(TAR_REC_FLAG,'0','未接收','1','已接收')TAR_REC_FLAG,
       max(TO_CHAR(OUTSTOCK_TIME, 'YYYY-MM-DD HH24:MI:SS')) OUTSTOCK_TIME,
       MEMO,
       CREATE_NAME
 FROM YMD_GP_OUTLIST
 WHERE JUDGE_STOVE_NO || '&' LIKE ('%' || ? || '%')
 AND OUTSTOCK_TYPE_CODE = '800803'
 ]]>
</query>
<query id = "FrmStuffMoveOut.doAddData" desc = "插入出库表">
<![CDATA[
DECLARE
  V_OUTSTOCK_DOC YMD_GP_OUTLIST.OUTSTOCK_DOC%TYPE := NULL; --出库单号
  V_OUTSTOCK_SQE YMD_GP_OUTLIST.OUTSTOCK_SQE%TYPE := NULL; --出库流水

  V_MEMO     COM_BASE_INFO.MEMO%TYPE := NULL;
  V_BASENAME COM_BASE_INFO.BASENAME%TYPE :=NULL;
  V_OCOUNT   NUMBER := 1;
  V_TIME     YMD_GP_OUTLIST.CREATE_TIME%TYPE := SYSDATE;
  V_BATHYEAR MAT_ZC_M.BAL_YEAR_MONTH%TYPE := TO_CHAR(SYSDATE, 'YYYYMM');
BEGIN
  --生成出库单号
  SELECT MEMO,BASENAME INTO V_MEMO,V_BASENAME FROM COM_BASE_INFO WHERE BASECODE = ?;
  SELECT V_MEMO || TO_CHAR(SYSDATE, 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(OUTSTOCK_DOC, 9)), 0) + 1, 5, 0) OUTSTOCK_DOC
    INTO V_OUTSTOCK_DOC
    FROM YMD_GP_OUTLIST T
   WHERE T.OUTSTOCK_TYPE_CODE = ?
     AND TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD') =
         TO_CHAR(SYSDATE, 'YYYY-MM-DD');
  FOR MYROW IN (SELECT T.*,
                       S.STORAGE_NO,
                       S.LOCATION_NO,
                       S.STORAGE_ATTR,
                       S.STORAGE_ATTR_NAME,
                       S.STORAGE_TYPE_NO,
                       S.STORAGE_TYPE_NAME
                  FROM MAT_GP_M T, YDM_GP_BUTTRESS S
                 WHERE T.MAT_NO = S.MAT_NO
                   AND NVL(T.STOVE_NO,'/') = NVL(?,'/')
                   AND T.JUDGE_STOVE_NO = ?
                   AND T.BATCH_NO = ?
                   AND T.GROUD_NO = ?
                   AND T.PRODUCT_FLAG = ?
                   AND T.MAT_STATUS = ?
                   AND NVL(S.STORAGE_NO,'/') = NVL(?,'/')
                   AND ROWNUM < ?
                   ORDER BY T.MAT_NO DESC) LOOP
    V_OUTSTOCK_SQE := V_OUTSTOCK_DOC || LPAD(V_OCOUNT, 4, 0);
    INSERT INTO YMD_GP_OUTLIST(
        OUTSTOCK_SQE,
        OUTSTOCK_PLAN_NO,
        OUTSTOCK_DOC,
        OUTSTOCK_TYPE_CODE,
        OUTSTOCK_TYPE_NAME,
        VEHICLE_NO,
        MAT_NO,
        MAT_SQE_NO,
        PRODUCT_FLAG,
        MAT_STATUS,
        STOVE_NO,
        FLAG_STOVE_NO,
        LOT_NO,
        JUDGE_STOVE_NO,
        BATCH_NO,
        CAST_NO,
        CCMID,
        SAMPLE_FLAG,
        CUTTING_FLAG,
        CUTTING_NUM,
        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,
        PLINE_CODE,
        PLINE_NAME,
        PRO_ORDER_NO,
        PRO_ORDER_ID,
        BELONG_CODE,
        BELONG_NAME,
        STORAGE_NO,
        LOCATION_NO,
        DEPARTMENT_CODE,
        DEPARTMENT_DESC,
        MANAGEMENT_NO,
        MANAGEMENT_NAME,
        TAR_STORAGE_NO,
        TAR_LOCATION_NO,
        TAR_DEPARTMENT_CODE,
        TAR_DEPARTMENT_DESC,
        TAR_MANAGEMENT_NO,
        TAR_MANAGEMENT_NAME,
        TAR_REC_FLAG,
        BAL_YEAR_MONTH,
        OUTSTOCK_TIME,
        OUT_BC,
        OUT_BZ,
        STORAGE_ATTR,
        STORAGE_ATTR_NAME,
        STORAGE_TYPE_NO,
        STORAGE_TYPE_NAME,
        MEMO,
        CREATE_NAME,
        CREATE_TIME,
        GROUD_NO,
        ICCAR_NO)
 VALUES( 
        V_OUTSTOCK_SQE,
        '',
        V_OUTSTOCK_DOC,
        ?,
        V_BASENAME,
        ?,
        MYROW.MAT_NO,
        MYROW.MAT_SQE_NO,
        MYROW.PRODUCT_FLAG,
        MYROW.MAT_STATUS,
        MYROW.STOVE_NO,
        MYROW.FLAG_STOVE_NO,
        MYROW.LOT_NO,
        MYROW.JUDGE_STOVE_NO,
        MYROW.BATCH_NO,
        MYROW.CAST_NO,
        MYROW.CCMID,
        MYROW.SAMPLE_FLAG,
        MYROW.CUTTING_FLAG,
        MYROW.CUTTING_NUM,
        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.PLINE_CODE,
        MYROW.PLINE_NAME,
        MYROW.PRO_ORDER_NO,
        MYROW.PRO_ORDER_ID,
        MYROW.BELONG_CODE,
        MYROW.BELONG_NAME,
        MYROW.STORAGE_NO,
        MYROW.LOCATION_NO,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        '',
        '',
        '',
        '',
        '0',
        V_BATHYEAR,
        V_TIME,
        '1',
        '1',
        MYROW.STORAGE_ATTR,
        MYROW.STORAGE_ATTR_NAME,
        MYROW.STORAGE_TYPE_NO,
        MYROW.STORAGE_TYPE_NAME,
        MYROW.MEMO,
        ?,
        V_TIME,
        MYROW.GROUD_NO,
        ?);
    DELETE YDM_GP_BUTTRESS T WHERE T.MAT_NO = MYROW.MAT_NO;
    V_OCOUNT := V_OCOUNT + 1;
  END LOOP;
END;
]]>
</query>
<query id = "FrmStuffMoveOut.selectMatData" desc = "查询库存信息是否存在">
SELECT COUNT(1) ACOUNT
  FROM MAT_GP_M T, YDM_GP_BUTTRESS S
 WHERE T.MAT_NO = S.MAT_NO
   AND NVL(T.STOVE_NO,'/') = NVL(?,'/')
   AND T.JUDGE_STOVE_NO = ?
   AND NVL(T.BATCH_NO,'/') = NVL(?,'/')
   AND T.GROUD_NO = ?
   AND T.PRODUCT_FLAG = ?
   AND T.MAT_STATUS = ?
   AND NVL(S.STORAGE_NO,'/') = NVL(?,'/')
</query>
<query id = "FrmStuffMoveOut.SelectOutListData" desc = "倒库记录是否被接收">
SELECT COUNT(1) ACOUNT
  FROM YMD_GP_OUTLIST T
 WHERE T.TAR_REC_FLAG = '1'
   AND T.STOVE_NO = ?
   AND T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   AND T.GROUD_NO = ?
</query>
<query id = "FrmStuffMoveOut.deleteOutListData" desc= "撤销倒库记录">
<![CDATA[
DECLARE
  V_TIME YMD_GP_OUTLIST.CREATE_TIME%TYPE := SYSDATE;
BEGIN
  FOR MYROW IN (SELECT T.*
                  FROM ymd_gp_outlist t
                 WHERE T.STOVE_NO = ?
                   AND T.JUDGE_STOVE_NO = ?
                   AND T.BATCH_NO = ?
                   AND T.GROUD_NO = ?
                   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,
        LARY_NO,
        LOC_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.storage_no,
        myrow.location_no,
        '',
        '',
        myrow.storage_attr,
        myrow.storage_attr_name,
        myrow.storage_type_no,
        myrow.storage_type_name,
        ?,
        ?,
        ?,
        ?,
        myrow.memo,
        ?,
        V_TIME
        );
        DELETE ymd_gp_outlist T WHERE t.Outstock_Sqe = MYROW.Outstock_Sqe;
  END LOOP;
END;
]]>
</query>
<query id = "FrmStuffMoveOut.doQueryDoc" desc = "生成单号">
SELECT 'OC' || TO_CHAR(SYSDATE, 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(OUTSTOCK_DOC, 9)), 0) + 1, 5, 0) OUTSTOCK_DOC
    FROM YMD_GP_OUTLIST T
   WHERE T.OUTSTOCK_TYPE_CODE = ?
     AND TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD') =
         TO_CHAR(SYSDATE, 'YYYY-MM-DD')
</query>
</queryMap>