<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "管坯收料">
<query id = "FrmStuffMoveIn.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 ICCAR_NO || '&' LIKE ('%' || ? || '%')
 AND OUTSTOCK_TYPE_CODE = '800803'
 AND TAR_REC_FLAG = '0'
 ]]>
</query>
<query id  = "FrmStuffMoveIn.douQueryInList" desc = "查询入库实绩">
<![CDATA[
 SELECT 
       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,
       Sum(ACT_COUNT)ACT_COUNT,
       sum(ACT_WEIGHT)ACT_WEIGHT,
       BELONG_CODE,
       BELONG_NAME,
       STORAGE_NO,
       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,
       MEMO,
       CREATE_NAME,
       max(TO_CHAR(CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS')) CREATE_TIME,
       INSTOCK_DOC,
       VEHICLE_NO,
       PRODUCT_FLAG,
       MAT_STATUS,
       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
 FROM YMD_GP_INLIST
 WHERE INSTOCK_DOC || '&' LIKE ('%' || ? || '%')
 AND JUDGE_STOVE_NO || '&' LIKE ('%' || ? || '%')
 AND INSTOCK_TYPE_CODE = '800703'
 ]]>
</query>
<query id = "FrmStuffMoveIn.selectOutListData" desc = "查询出库实绩是否已接收">
SELECT  COUNT(1)ACOUNT FROM YMD_GP_OUTLIST T WHERE T.OUTSTOCK_DOC = ? AND T.TAR_REC_FLAG = '1'
</query>
<query id = "FrmStuffMoveIn.doAddInListData" 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 ymd_gp_outlist t where t.outstock_doc = ?) 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.storage_no,
       myrow.location_no,
       myrow.storage_attr,
       myrow.storage_attr_name,
       myrow.storage_type_no,
       myrow.storage_type_name,
       ?,
       ?,
       ?,
       ?,
       myrow.memo,
       ?,
       v_time);
    v_instock_sqe := v_Instock_doc || Lpad(v_Icount, 4, 0);
    INSERT INTO YMD_GP_INLIST
      (GROUD_NO,
       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,
       BELONG_CODE,
       BELONG_NAME,
       STORAGE_NO,
       LOCATION_NO,
       DEPARTMENT_CODE,
       DEPARTMENT_DESC,
       MANAGEMENT_NO,
       MANAGEMENT_NAME,
       INSTOCK_TIME,
       IN_BC,
       IN_BZ,
       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,
       VEHICLE_NO,
       MAT_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,
       PLINE_CODE,
       PLINE_NAME,
       PRO_ORDER_NO,
       PRO_ORDER_ID)
    VALUES
      (myrow.groud_no,
       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_len,
       myrow.act_len_min,
       myrow.act_len_max,
       myrow.act_fix_num,
       myrow.act_fix_len,
       myrow.act_count,
       myrow.act_weight,
       myrow.belong_code,
       myrow.belong_name,
       myrow.storage_no,
       myrow.location_no,
       ?,
       ?,
       ?,
       ?,
       v_time,
       '1',
       '1',
       v_time,
       v_bathYear,
       myrow.storage_attr,
       myrow.storage_attr_name,
       myrow.storage_type_no,
       myrow.storage_type_name,
       myrow.memo,
       ?,
       v_time,
       v_instock_sqe,
       v_Instock_doc,
       ?,
       v_baseName,
       myrow.vehicle_no,
       myrow.mat_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.pline_code,
       myrow.pline_name,
       myrow.pro_order_no,
       myrow.pro_order_id);
    update ymd_gp_outlist t
       set t.TAR_REC_FLAG        = '1',
           t.tar_department_code = ?,
           t.tar_department_desc = ?,
           t.tar_management_no   = ?,
           t.tar_management_name = ?,
           t.instock_time = to_date(v_time,'YYYY-MM-DD HH24:mi:ss')
           where t.outstock_sqe = myrow.outstock_sqe;
    v_Icount := v_Icount + 1;
  end loop;
end;
]]>
</query>
<query id = "FrmStuffMoveIn.selectInListData" desc = "查询材料状态">
<![CDATA[
SELECT COUNT(1)ACOUNT
  FROM MAT_GP_M T, YDM_GP_BUTTRESS S
 WHERE T.MAT_NO = S.MAT_NO
   AND T.STOVE_NO = ?
   AND T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   AND T.GROUD_NO = ?
   AND S.STORAGE_NO = ?
   AND T.MAT_STATUS <>'80150302'
   ]]>
</query>
<query id = "FrmStuffMoveIn.deleteInListData" desc = "撤销收料">
<![CDATA[
DECLARE
BEGIN
  FOR MYROW IN (SELECT T.*
                  FROM YMD_GP_INLIST T
                 WHERE T.INSTOCK_DOC = ?
                 ORDER BY T.MAT_NO DESC) LOOP
    UPDATE YMD_GP_OUTLIST S
       SET S.TAR_REC_FLAG = '0'
     WHERE S.MAT_NO = MYROW.MAT_NO;
    DELETE YDM_GP_BUTTRESS W WHERE W.MAT_NO = MYROW.MAT_NO;
    DELETE YMD_GP_INLIST T WHERE T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
END;
]]>
</query>
</queryMap>