<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "">
<query id="OverstockPipe.queryOutList" desc="查询出库单号">
	<![CDATA[
SELECT (SELECT S.MEMO FROM COM_BASE_INFO S WHERE S.BASECODE = ?) ||
       OUTSTOCK_DOC OUTSTOCK_DOC
  FROM (SELECT TO_CHAR(SYSDATE, 'YYMMDD') ||
               LPAD(NVL(MAX(SUBSTR(T.OUTSTOCK_DOC, 9)), 0) + 1, 5, 0) OUTSTOCK_DOC
          FROM YDM_BC_OUTLIST T
         WHERE OUTSTOCK_SQE LIKE
               (SELECT S.MEMO FROM COM_BASE_INFO S WHERE S.BASECODE = ?) ||
               TO_CHAR(SYSDATE, 'YYMMDD') || '%')
	]]>
	</query>
	
	<query id="OverstockPipe.addOutstockDoc" desc="余材转压库综合判定增加产权出库记录">
	<![CDATA[
DECLARE
  V_JUGDE_APPLY_CODE MAT_BC_M.JUGDE_APPLY_CODE%TYPE := ?;
  V_BAL_YEAR_MONTH   QCM_ZG_JUGDE_APPLY.BAL_YEAR_MONTH%TYPE := ?; --结转年月
  V_OUTSTOCK_DOC2    YDM_BC_OUTLIST.OUTSTOCK_DOC%TYPE := ?; --产权出库单号
  V_ICOUNT           NUMBER := 1;
BEGIN

  FOR MYROW1 IN (SELECT T.*
                   FROM MAT_BC_M T
                  WHERE T.JUGDE_APPLY_CODE = V_JUGDE_APPLY_CODE
                  ORDER BY T.MAT_NO ASC) LOOP
    insert into ydm_bc_outlist
      (outstock_sqe,
       outstock_doc,
       outstock_type_code,
       outstock_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,
       outstock_time,
       create_name,
       create_time,
       ord_pk,
       ord_ln_pk,
       ord_ln_dly_pk,
       /*department_code,
       department_desc,
       tar_department_code,
       tar_department_desc,*/
       order_no,
       order_seq,
       delivery_no,
       product_flag,
       mat_status,
       /*judge_std_name,
       judge_std_code,*/
       bal_year_month,
       qcm_staus,
       PROCESS_CDOE,
       PROCESS_DESC)
    values
      (V_OUTSTOCK_DOC2 || LPAD(V_ICOUNT, 4, 0),
       V_OUTSTOCK_DOC2,
       '800809',
       '产权出库',
       MYROW1.MAT_NO,
       MYROW1.LOT_NO,
       MYROW1.STOVE_NO,
       MYROW1.JUDGE_STOVE_NO,
       MYROW1.BATCH_NO,
       MYROW1.batch_groud_no,
       MYROW1.material_no,
       MYROW1.material_name,
       MYROW1.produccode,
       MYROW1.producname,
       MYROW1.std_code,
       MYROW1.std_name,
       MYROW1.gradecode,
       MYROW1.gradename,
       MYROW1.steelcode,
       MYROW1.steelname,
       MYROW1.std_style,
       MYROW1.std_style_desc,
       MYROW1.spec_code,
       MYROW1.spec_name,
       MYROW1.model_code,
       MYROW1.model_desc,
       '',
       MYROW1.pline_code,
       MYROW1.pline_name,
       MYROW1.ACT_DIMATER,
       MYROW1.ACT_HEIGHT,
       MYROW1.act_len,
       MYROW1.act_len_min,
       MYROW1.act_len_max,
       MYROW1.act_count,
       MYROW1.act_weight,
       MYROW1.act_theory_weight,
       MYROW1.belong_code,
       MYROW1.belong_name,
       SYSDATE,
       '',
       SYSDATE,
       '',
       '',
       '',
       '',
       '',
       '',
       MYROW1.product_flag,
       MYROW1.mat_status,
       /* MYROW1.judge_std_name,
       MYROW1.judge_std_code,*/
       V_BAL_YEAR_MONTH,
       MYROW1.qcm_staus,
       MYROW1.PROCESS_CDOE,
       MYROW1.PROCESS_DESC);
    V_ICOUNT := V_ICOUNT + 1;
  END LOOP;
END;

	]]>
	</query>
	
	<query id="OverstockPipe.deleteOutstockDoc" desc="撤销综合判定调用">
	<![CDATA[
DECLARE
  V_JUGDE_APPLY_CODE MAT_BC_M.JUGDE_APPLY_CODE%TYPE := ?;
BEGIN
  FOR MYROW1 IN (SELECT T.*
                   FROM MAT_BC_M T
                  WHERE T.JUGDE_APPLY_CODE = V_JUGDE_APPLY_CODE
                  ORDER BY T.MAT_NO ASC) LOOP
    DELETE FROM ydm_bc_outlist T1
     WHERE T1.OUTSTOCK_TYPE_CODE = '800809'
       AND T1.MAT_NO = MYROW1.MAT_NO;
  
  END LOOP;
END;
	]]>
	</query>

</queryMap>