<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "库存红冲">
<query id = "FrmPipStoreRed.getMat" desc = "查询库存实绩">
<![CDATA[
      SELECT T1.JUDGE_STOVE_NO,
       T1.BATCH_NO,
       T1.BATCH_GROUD_NO,
       T1.PRODUCCODE,
       T1.PRODUCNAME,
       T1.STEELCODE,
       T1.STEELNAME,
       T1.SPEC_CODE,
       T1.SPEC_NAME,
       T1.MODEL_CODE,
       T1.MODEL_DESC,
       T1.STD_CODE,
       T1.STD_NAME,
       T1.ORDER_NO,
       T1.ORDER_SEQ,
       T1.ORDER_SEQ_NO,
       T1.ACT_DIMATER,
       T1.ACT_HEIGHT,
       T1.BELONG_CODE,
       T1.BELONG_NAME,
       T1.STD_STYLE,
       T1.STD_STYLE_DESC,
       T1.GRADECODE,
       T1.GRADENAME,
      sum(T1.ACT_COUNT)
            UNIT,
            to_char(sum(T1.Act_Weight),'FM999999990.000')
           WEIGHT,
           sum(T1.ACT_COUNT)
            REDCOUNT,
            to_char(sum(T1.Act_Weight),'FM999999990.000')
           REDWEIGHT,
       sum(nvl(T1.ACT_LEN,0)) as ACT_LEN,
       sum(nvl(T1.ACT_LEN,0)) as LENGTH,
       max(to_char(T1.ACT_LEN_MIN,'FM999990.00')) AS ACT_LEN_MIN,
       max(to_char(T1.ACT_LEN_MAX,'FM999990.00')) AS ACT_LEN_MAX,
       max(to_char(T1.ACT_LEN_MIN,'FM999990.00')||'-'||to_char(T1.ACT_LEN_MAX,'FM999990.00')) as LEN,
       max(to_char(T1.INSTOCK_TIME,'YYYY-MM-DD HH24:MI:SS')) INSTOCK_TIME,
       T2.STORAGE_NO,
       S.STORAGE_NAME,
       T1.MEMO,
       T1.MAT_STATUS,
       T1.JUDGE_STD_CODE,
       T1.JUDGE_STD_NAME,
       T1.PLINE_CODE,
       T1.PLINE_NAME,
       T1.ORD_LN_PK,
       T1.ORD_PK,
       T1.ORD_LN_DLY_PK,
       MAX(to_char(to_date(T1.BAL_YEAR_MONTH,'YYYY-MM'),'yyyy-MM')) as BAL_YEAR_MONTH,
       DECODE(T1.PRODUCT_FLAG,'801401','在制品','801402','成品','801403','商品')PRODUCT_FLAG,
       T1.MATERIAL_NO,
       T1.MATERIAL_NAME
  FROM MAT_ZC_M T1, YDM_ZC_BUTTRESS T2
 LEFT JOIN ydm_bs_storage S ON S.STORAGE_NO=T2.STORAGE_NO
 WHERE T1.JUDGE_STOVE_NO = T2.JUDGE_STOVE_NO
   AND T1.BATCH_NO = T2.BATCH_NO
    AND T1.MAT_NO=T2.MAT_NO
  AND T1.MAT_STATUS <>'80150302'
  AND T1.PRODUCT_FLAG = '801402'
		]]>
</query>

<query id = "FrmPipStoreRed.getInList" desc = "查询入库实绩">
<![CDATA[
 SELECT 
       t.INSTOCK_DOC,
       t.JUDGE_STOVE_NO,
       t.BATCH_NO,
       t.BATCH_GROUD_NO,
       t.PRODUCCODE,
       t.PRODUCNAME,
       t.STD_CODE,
       t.STD_NAME,
       t.STEELCODE,
       t.STEELNAME,
       t.STD_STYLE,
       t.STD_STYLE_DESC,
       t.SPEC_CODE,
       t.SPEC_NAME,
       t.MODEL_CODE,
       t.MODEL_DESC,
       t.ACT_DIMATER,
       t.ACT_HEIGHT,
       to_char(t.ACT_LEN_MIN,'FM999990.00') AS ACT_LEN_MIN,
       to_char(t.ACT_LEN_MAX,'FM999990.00') AS ACT_LEN_MAX,
       to_char(t.ACT_LEN_MIN,'FM999990.00')||'-'||to_char(t.ACT_LEN_MAX,'FM999990.00') as LEN,
       sum(t.ACT_COUNT) as ACT_COUNT,
       to_char(sum(t.ACT_WEIGHT),'FM999999990.000') as ACT_WEIGHT,
       sum(nvl(t.ACT_LEN,0)) as ACT_LEN,
       t.BELONG_CODE,
       t.BELONG_NAME,
       s.STORAGE_NAME,
       t.MEMO,
       t.CREATE_NAME,
       max(to_char(t.INSTOCK_TIME,'YYYY-MM-DD HH24:MI:SS')) as INSTOCK_TIME,
       max(to_char(t.IN_TIME_F,'YYYY-MM-DD HH24:MI:SS')) AS IN_TIME_F,
       to_char(to_date(t.BAL_YEAR_MONTH,'YYYY-MM'),'yyyy-MM') as BAL_YEAR_MONTH,
       --t.BAL_YEAR_MONTH,
       t.ORDER_NO,
     t.ORDER_SEQ,
     t.DELIVERY_NO,
     t.JUDGE_STD_CODE,
     t.JUDGE_STD_NAME,
     t.PLINE_CODE,
     t.PLINE_NAME,
     t.GRADECODE,
     t.GRADENAME,
     DECODE(t.PRODUCT_FLAG,'801401','在制品','801402','成品','801403','商品')PRODUCT_FLAG,
     t.ZB_RCDID,
     d.SALE_AREA_DESC,
       d.create_name AS ordercreatename,
       t.ORD_LN_PK,
       t.ORD_LN_DLY_PK
 FROM YDM_ZC_INLIST t
  left join  ydm_bs_storage s
  on t.STORAGE_NO = s.STORAGE_NO
  left join  SLM_ORDER_HEAD d on 
   t.ord_pk = d.ord_pk
 where t.INSTOCK_TYPE_CODE ='800704'
   AND t.JUDGE_STOVE_NO || '&' LIKE ('%' || upper(?) || '%')
   AND t.ORDER_NO || '&' LIKE ('%' || upper(?) || '%')
   AND t.STORAGE_NO || '&' LIKE ('%' || upper(?) || '%')
   ]]>
</query>
<query id = "pipRedStore.deleteMat" desc = "删除物料表">
DELETE  FROM  MAT_ZC_M T WHERE T.MAT_NO = ?
</query>
<query id = "pipRedStore.deleteButess" desc = "删除位置表">
DELETE  FROM  YDM_ZC_BUTTRESS T WHERE T.MAT_NO = ?
</query>
<query id = "pipRedStore.insertInList" desc = "插入入库表">
INSERT INTO YDM_ZC_INLIST
  (MANAGEMENT_NO,
   MANAGEMENT_NAME,
   INSTOCK_SQE,
   INSTOCK_DOC,
   INSTOCK_TYPE_CODE,
   INSTOCK_TYPE_NAME,
   MAT_NO,
   LOT_NO,
   STOVE_NO,
   JUDGE_STOVE_NO,
   BATCH_NO,
   BATCH_GROUD_NO,
   
   PRODUCCODE,
   PRODUCNAME,
   STD_CODE,
   STD_NAME,
   
   STEELCODE,
   STEELNAME,
   STD_STYLE,
   STD_STYLE_DESC,
   SPEC_CODE,
   SPEC_NAME,
   MODEL_CODE,
   MODEL_DESC,
   ACT_DIMATER,
   ACT_HEIGHT,
   ACT_LEN_MIN,
   ACT_LEN_MAX,
   ACT_COUNT,
   ACT_WEIGHT,
   ACT_THEORY_WEIGHT,
   BELONG_CODE,
   BELONG_NAME,
   STORAGE_NO,
   
   MEMO,
   VALIDFLAG,
   CREATE_NAME,
   CREATE_TIME,
   ORDER_NO,
     ORDER_SEQ,
     DELIVERY_NO,
     ORD_PK,
     ORD_LN_PK,
     ORD_LN_DLY_PK,
     PRODUCT_FLAG,
     MAT_STATUS,
     INSTOCK_TIME,ZB_RCDID,ACT_LEN,DEPARTMENT_CODE,DEPARTMENT_DESC,JUDGE_STD_NAME,PLINE_CODE,PLINE_NAME,GRADECODE,GRADENAME,BAL_YEAR_MONTH,IN_TIME_F,LEN_NO,LEN_DESC,LEN_UNIT,PIPMEMO,MAT_ORIGIN_CODE,MAT_ORIGIN_NAME,SOURE_CODE,SOURE_NAME,MATERIAL_NO,MATERIAL_NAME)
VALUES
  (?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   to_date(?,'YYYY-MM-DD HH24:MI:SS'),?,?,?,?,?,?,?,?,to_date(?,'YYYY-MM-DD HH24:MI:SS'),?,?,?,?,?,?,?,?,?,?,to_date(?,'YYYY-MM-DD HH24:MI:SS'),?,?,?,?,?,?,?,?,?,?)
</query>
<query id = "pipRedStore.selectMatNo" desc = "查询材料号">
<![CDATA[
SELECT S.MAT_NO FROM (SELECT T.MAT_NO
  FROM MAT_ZC_M T,YDM_ZC_BUTTRESS S
 WHERE T.MAT_NO = S.MAT_NO
   AND T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   AND T.BATCH_GROUD_NO = ?
   AND T.MAT_STATUS = ?
   AND S.STORAGE_NO = ?
   AND T.BAL_YEAR_MONTH = ?
   AND T.BELONG_CODE = ?
   ORDER BY T.MAT_NO DESC)S
   where  ROWNUM < ?
]]>
</query>
<query id = "pipRedStore.selectMatNoStore" desc = "查询剩余材料号">
<![CDATA[
SELECT S.MAT_NO FROM (SELECT T.MAT_NO
  FROM MAT_ZC_M T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   AND T.BATCH_GROUD_NO = ?
   AND T.BELONG_CODE = ?
   AND T.PRODUCT_FLAG = '801402'
   order by T.MAT_NO)S
   WHERE ROWNUM < ?
]]>
</query>
<query id = "pipRedStore.selectMatData" desc = "查询所有信息">
select t.mat_no,
	       t.lot_no,
	       t.stove_no,
	       t.judge_stove_no,
	       t.batch_no,
	       t.batch_groud_no,
	       t.material_no,
	       t.material_name,
	       t.produccode,
	       t.producname,
	       t.spec_code,
	       t.spec_name,     
	       t.gradecode,
	       t.gradename,
	       t.steelcode,
	       t.steelname,
	       t.std_style,
	       t.std_style_desc,
	       t.std_code,
	       t.std_name,
	       t.model_code,
	       t.model_desc,
	       t.pro_order_no,
	       t.pline_code,
	       t.pline_name,
	       t.act_dimater,
	       t.act_height,
	       t.act_len,
	       t.act_len_min,
	       t.act_len_max,
	       t.act_count,
	       t.act_weight,
	       t.act_theory_weight,
	       t.belong_code,
	       t.belong_name,   
	       t.rpo_time,
	       t.pro_bc,
	       t.pro_bz,  
	       b.STORAGE_NO,
	       b.LOCATION_NO,
	       b.LARY_NO,
	       b.LOC_NO,
	       b.STORAGE_ATTR,
	       b.STORAGE_ATTR_NAME,
	       b.STORAGE_TYPE_NO,
	       b.STORAGE_TYPE_NAME,
	       b.MANAGEMENT_NO,
	       b.MANAGEMENT_NAME,
	       t.ORDER_NO,
	       t.ORDER_SEQ,
	       t.ORDER_SEQ_NO,
	       t.ORD_PK,
	       t.ORD_LN_PK,
	       t.ORD_LN_DLY_PK,
	       t.PRODUCT_FLAG,
	       t.MAT_STATUS,
	       t.BAL_YEAR_MONTH,
	       to_char(t.INSTOCK_TIME,'yyyy-MM-dd HH24:mi:ss')INSTOCK_TIME,
	       t.memo,
	       t.JUDGE_STD_NAME,
	       t.LEN_NO,
	       t.LEN_DESC,
	       t.LEN_UNIT,
	       t.SOURE_CODE,
	       t.SOURE_NAME,
	       t.MAT_ORIGIN_CODE,
	       t.MAT_ORIGIN_NAME
	  from Mat_zc_m t,ydm_zc_buttress b 
	  where t.mat_no=b.mat_no
	  and t.mat_no=? 
</query>
<query id = "pipRedStore.updatePlan" desc = "修改计划缴库量">
<![CDATA[
	UPDATE PLN_SALEORD
   SET PAYDOWN_NUM  =
       to_number(nvl((SELECT T.PAYDOWN_NUM
          FROM PLN_SALEORD T
         WHERE T.ORDER_NO = ?
           AND T.ORDER_SEQ = ?
           AND T.DELIVERY_NO = ?),0)) + to_number(?),
       PAYDOWNWEIGHT =
       to_number(nvl((SELECT T.PAYDOWNWEIGHT
          FROM PLN_SALEORD T
         WHERE T.ORDER_NO = ?
           AND T.ORDER_SEQ = ?
           AND T.DELIVERY_NO = ?),0)) + to_number(?)
 WHERE ORDER_NO = ?
   AND ORDER_SEQ = ?
   AND DELIVERY_NO = ?
   ]]>
</query>
<query id = "pipRedStore.updateMatWgtLen" desc = "修改剩余材料重量支数">
UPDATE MAT_ZC_M T SET T.ACT_WEIGHT = ?,T.ACT_LEN = ? WHERE T.MAT_NO = ?
</query>
<query id = "pipCancelRedStore.insertMat" desc = "插入材料表">
<![CDATA[
	   INSERT INTO MAT_ZC_M
     (
     JUDGE_STOVE_NO,
     BATCH_NO,
     BATCH_GROUD_NO,
     PRODUCCODE,
     PRODUCNAME,
     STEELCODE,
     STEELNAME,
     SPEC_CODE,
     SPEC_NAME,
     MODEL_CODE,
     MODEL_DESC,
     STD_CODE,
     STD_NAME,
     BELONG_CODE,
     BELONG_NAME,
     STD_STYLE,
     STD_STYLE_DESC,
     ORDER_NO,
     ORDER_SEQ,
     ORDER_SEQ_NO,
     ORD_PK,
     ORD_LN_PK,
     ORD_LN_DLY_PK,
     ACT_DIMATER,
     ACT_HEIGHT,
     LEN_NO,
     LEN_DESC,
     LEN_UNIT,
     ACT_LEN_MIN,
     ACT_LEN_MAX,
     CREATE_NAME,
 	 
     ACT_COUNT,		 
     ACT_WEIGHT,
     CREATE_TIME, 
     INSTOCK_TIME,  
     MAT_NO,
     MEMO,
     JUGDE_APPLY_FLAG,
     INSTOCK_FLAG,
     PRODUCT_FLAG,
     MAT_STATUS,
     ACT_LEN,
     JUDGE_STD_NAME,
     BAL_YEAR_MONTH,
     PLINE_CODE,
     PLINE_NAME,
     GRADECODE,
     GRADENAME,
     PIPMEMO,
     MAT_ORIGIN_CODE,
     MAT_ORIGIN_NAME,
     SOURE_CODE,
     SOURE_NAME,
     MATERIAL_NO,
     MATERIAL_NAME
     ) VALUES  (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,
             ?,?,?,?,?,?,?,?,?,?,?,?,
             TO_NUMBER(?),ROUND(TO_NUMBER(?),4),TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),
             ?,?,'1','1',?,?,TO_NUMBER(?),?,?,?,?,?,?,?,?,?,?,?,?,?)
		]]>
</query>
<query id = "pipCancelRedStore.insertButress" desc = "插入位置表">
<![CDATA[
       INSERT INTO YDM_ZC_BUTTRESS
    (
     JUDGE_STOVE_NO,
     BATCH_NO,
     BATCH_GROUD_NO,
     STORAGE_NO,
     LOCATION_NO,
     STORAGE_TYPE_NO,
     STORAGE_TYPE_NAME,
     
     CREATE_NAME,
     MAT_NO,
     CREATE_TIME,
     MANAGEMENT_NO,
     MANAGEMENT_NAME,
     DEPARTMENT_CODE,
     DEPARTMENT_DESC
     )
    VALUES ( ?,?,?,?,?,?,?,?,?,to_date(?,'YYYY-MM-DD HH24:MI:SS'),?,?,?,?)
		]]>
</query>
<query id = "pipCancelRedStore.deleteInList" desc = "删除入库表">
DELETE FROM YDM_ZC_INLIST T WHERE T.INSTOCK_DOC = ?
</query>
<query id = "pipCancelRedStore.updatePlan" desc = "修改计划表">
<![CDATA[
		UPDATE PLN_SALEORD
   SET PAYDOWN_NUM  =
       to_number(nvl((SELECT T.PAYDOWN_NUM
          FROM PLN_SALEORD T
         WHERE T.ORDER_NO = ?
           AND T.ORDER_SEQ = ?
           AND T.DELIVERY_NO = ?),0)) + to_number(?),
       PAYDOWNWEIGHT =
       to_number(nvl((SELECT T.PAYDOWNWEIGHT
          FROM PLN_SALEORD T
         WHERE T.ORDER_NO = ?
           AND T.ORDER_SEQ = ?
           AND T.DELIVERY_NO = ?),0)) + to_number(?)
 WHERE ORDER_NO = ?
   AND ORDER_SEQ = ?
   AND DELIVERY_NO = ?
		]]>
</query>
<query id = "pipCancelRedStore.selectInList" desc = "查询对应单号的入库信息">
 SELECT 
       PRODUCT_FLAG,
       MAT_STATUS,
       ZB_RCDID,
       JUDGE_STD_NAME,
       JUDGE_STD_CODE,
       TO_CHAR(IN_TIME_F, 'YYYY-MM-DD HH24:MI:SS') IN_TIME_F,
       BAL_YEAR_MONTH,
       ORDER_NO,
       ORDER_SEQ,
       DELIVERY_NO,
       ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK,
       DEPARTMENT_CODE,
       DEPARTMENT_DESC,
       INSTOCK_SQE,
       INSTOCK_DOC,
       INSTOCK_TYPE_CODE,
       INSTOCK_TYPE_NAME,
       INSTOCK_BAR_CODE,
       ICCAR_NO,
       VEHICLE_NO,
       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,
       STORAGE_NO,
       LOCATION_NO,
       LARY_NO,
       LOC_NO,
       STORAGE_ATTR,
       STORAGE_ATTR_NAME,
       STORAGE_TYPE_NO,
       STORAGE_TYPE_NAME,
       MANAGEMENT_NO,
       MANAGEMENT_NAME,
       TO_CHAR(RPO_TIME, 'YYYY-MM-DD HH24:MI:SS') RPO_TIME,
       PRO_BC,
       PRO_BZ,
       IN_BC,
       IN_BZ,
       BAR_CODE,
       HAND_FLAG,
       MEMO,
       VALIDFLAG,
       CREATE_NAME,
       TO_CHAR(CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       UPDATE_NAME,
       TO_CHAR(UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
       DELETE_NAME,
       TO_CHAR(DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
       LEN_NO,
       LEN_DESC,
       LEN_UNIT,
       MAT_ORIGIN_CODE,
       MAT_ORIGIN_NAME,
       SOURE_CODE,
       SOURE_NAME,
       MATERIAL_NO,
       MATERIAL_NAME
 FROM YDM_ZC_INLIST
 WHERE INSTOCK_DOC = ?
</query>
<query id = "pipRedStore.updateProcessSql" desc = "写进程表">
UPDATE PROCESS_ORDER_M T
   SET T.NEG_PAY_NUM = TO_NUMBER(NVL(T.NEG_PAY_NUM,0)) + TO_NUMBER(?),
       T.NEG_PAY_WGT = TO_NUMBER(NVL(T.NEG_PAY_WGT,0)) + TO_NUMBER(?),
       T.NEG_PAY_LEN = TO_NUMBER(NVL(T.NEG_PAY_LEN,0)) + TO_NUMBER(?)
   WHERE ORD_LN_DLY_PK = ?
</query>
<query id = "pipCancelRedStore.updateProcess" desc = "进程表减量">
UPDATE PROCESS_ORDER_M T
   SET T.NEG_PAY_NUM = TO_NUMBER(NVL(T.NEG_PAY_NUM,0)) + TO_NUMBER(?),
       T.NEG_PAY_WGT = TO_NUMBER(NVL(T.NEG_PAY_WGT,0)) + TO_NUMBER(?),
       T.NEG_PAY_LEN = TO_NUMBER(NVL(T.NEG_PAY_LEN,0)) + TO_NUMBER(?)
   WHERE ORD_LN_DLY_PK = ?
</query>
<query id = "pipRedStore.insertMat" desc = "插入材料表">
<![CDATA[
	   INSERT INTO MAT_ZC_M
     (
     JUDGE_STOVE_NO,
     BATCH_NO,
     BATCH_GROUD_NO,
     PRODUCCODE,
     PRODUCNAME,
     STEELCODE,
     STEELNAME,
     SPEC_CODE,
     SPEC_NAME,
     MODEL_CODE,
     MODEL_DESC,
     STD_CODE,
     STD_NAME,
     BELONG_CODE,
     BELONG_NAME,
     STD_STYLE,
     STD_STYLE_DESC,
     ORDER_NO,
     ORDER_SEQ,
     ORDER_SEQ_NO,
     ORD_PK,
     ORD_LN_PK,
     ORD_LN_DLY_PK,
     ACT_DIMATER,
     ACT_HEIGHT,
     LEN_NO,
     LEN_DESC,
     LEN_UNIT,
     ACT_LEN_MIN,
     ACT_LEN_MAX,
     CREATE_NAME,
 	 
     ACT_COUNT,		 
     ACT_WEIGHT,
     CREATE_TIME, 
     INSTOCK_TIME,  
     MAT_NO,
     MEMO,
     JUGDE_APPLY_FLAG,
     INSTOCK_FLAG,
     PRODUCT_FLAG,
     MAT_STATUS,
     ACT_LEN,
     JUDGE_STD_NAME,
     BAL_YEAR_MONTH,
     PLINE_CODE,
     PLINE_NAME,
     GRADECODE,
     GRADENAME,
     PIPMEMO,
     MAT_ORIGIN_CODE,
     MAT_ORIGIN_NAME,
     SOURE_CODE,
     SOURE_NAME,
     MATERIAL_NO,
     MATERIAL_NAME
     ) VALUES  (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,
             ?,?,?,?,?,?,?,?,?,?,?,?,
             TO_NUMBER(?),ROUND(TO_NUMBER(?),4),TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),
             ?,?,'1','1',?,?,TO_NUMBER(?),?,?,?,?,?,?,?,?,?,?,?,?,?)
		]]>
</query>
<query id="pipRedStore.insertButress" desc = "插入位置表">
<![CDATA[
       INSERT INTO YDM_ZC_BUTTRESS
    (
     JUDGE_STOVE_NO,
     BATCH_NO,
     BATCH_GROUD_NO,
     STORAGE_NO,
     LOCATION_NO,
     STORAGE_TYPE_NO,
     STORAGE_TYPE_NAME,
     
     CREATE_NAME,
     MAT_NO,
     CREATE_TIME,
     MANAGEMENT_NO,
     MANAGEMENT_NAME,
     DEPARTMENT_CODE,
     DEPARTMENT_DESC
     )
    VALUES ( ?,?,?,?,?,?,?,?,?,to_date(?,'YYYY-MM-DD HH24:MI:SS'),?,?,?,?)
		]]>
</query>
<query id = "pipCancelRedStore.deleteMat" desc = "删除物料表">
DELETE FROM MAT_ZC_M T WHERE T.MAT_NO = ?
</query>
<query id = "pipCancelRedStore.deleteButess" desc = "删除位置表">
DELETE FROM YDM_ZC_BUTTRESS T WHERE T.MAT_NO = ?
</query>
<query id = "pipCancelRedStore.selectMatNo" desc = "查询状态">
select mat_no from MAT_ZC_M t where t.JUDGE_STOVE_NO = ? and t.BATCH_NO = ? and t.BATCH_GROUD_NO = ? and t.MAT_STATUS not in('80150301','80150202','80150203','80150204','80150205')
</query>
<query id = "FrmPipStoreRed.getStaueCount" desc= "查询支数">
SELECT SUM(T.ACT_COUNT) ACOUNT
  FROM MAT_ZC_M T, YDM_ZC_BUTTRESS S
 WHERE T.MAT_NO = S.MAT_NO
   AND T.JUDGE_STOVE_NO = ? 
   AND T.BATCH_NO = ?
   AND T.BATCH_GROUD_NO = ?
   AND T.MAT_STATUS = ?
   AND T.PLINE_CODE = ?
   AND NVL(T.STD_CODE,'/') = NVL(?,'/')
   AND S.STORAGE_NO = ?
   AND T.BAL_YEAR_MONTH = ?
</query>
<query id = "pipRedStore.insertBcM" desc= "退制造部插入半成品表(库存等于红冲支)">
<![CDATA[
DECLARE
  V_INSTOCK_SEQ  YDM_BC_INLIST.INSTOCK_SQE%TYPE := NULL;
  V_COUNT       NUMBER := 1;
  V_PROCESS_CDOE MAT_BC_M.PROCESS_CDOE%TYPE := NULL;
  V_PROCESS_DESC MAT_BC_M.PROCESS_DESC%TYPE := NULL;
  V_ACT_WEIGHT QCM_ZG_JUGDE_APPLY.ACT_WEIGHT%TYPE := NULL;
  V_ACT_THEORY_WEIGHT  QCM_ZG_JUGDE_APPLY.ACT_THEORY_WEIGHT%TYPE := NULL;
  V_ACT_LEN QCM_ZG_JUGDE_APPLY.ACT_LEN%TYPE := NULL;
  V_BELONG_CODE QCM_ZG_JUGDE_APPLY.BELONG_CODE%TYPE := NULL;
  V_BELONG_NAME QCM_ZG_JUGDE_APPLY.BELONG_NAME%TYPE := NULL;
  V_JUGDE_APPLY_CODE QCM_ZG_JUGDE_APPLY.JUGDE_APPLY_CODE%TYPE :=NULL;
  V_JUDGE_RESULT_CODE MAT_ZC_M.JUDGE_RESULT_CODE%TYPE := NULL;
  V_JUDGE_RESULT      MAT_ZC_M.JUDGE_RESULT%TYPE := NULL;
BEGIN

  FOR MYROW IN (SELECT S1.*
                  FROM (SELECT T.*, S.STORAGE_NO, S.LOCATION_NO, S.LARY_NO
                          FROM MAT_ZC_M T, YDM_ZC_BUTTRESS S
                         WHERE T.MAT_NO = S.MAT_NO
                           AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                           AND T.BATCH_NO = '#BATCH_NO#'
                           AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                           AND T.MAT_STATUS = '#MAT_STATUS#'
                           AND S.STORAGE_NO = '#STORAGE_NO#'
                           AND T.BELONG_CODE = '#BELONG_CODE#'
                           AND T.PRODUCT_FLAG = '801402'
                         ORDER BY T.MAT_NO DESC) S1
                 WHERE ROWNUM <= #ACT_COUNT#) LOOP
    SELECT S2.PROCESS_CODE, S2.PROCESS_DESC,S2.DEPARTMENT_CODE,S2.DEPARTMENT_DESC
      INTO V_PROCESS_CDOE, V_PROCESS_DESC,V_BELONG_CODE,V_BELONG_NAME
      FROM COM_BASE_PLINE S2
     WHERE S2.PLINE_CODE = MYROW.PLINE_CODE;
     IF(V_COUNT = 1)THEN
     SELECT 'H'||MYROW.PLINE_CODE||'801401'||TO_CHAR(SYSDATE, 'YYYYMMDD') ||
               LPAD(NVL(MAX(SUBSTR(T.JUGDE_APPLY_CODE, 19)), 0) + 1, 6, 0) JUGDE_APPLY_CODE INTO V_JUGDE_APPLY_CODE
          FROM QCM_ZG_JUGDE_APPLY T
         WHERE T.IS_ALL_SCRAP = '3'
           AND TRUNC(T.APPLY_TIME) = TRUNC(TO_DATE('#INSTOCK_TIME#','YYYY-MM-DD HH24:MI:SS'));
     END IF;
     IF(MYROW.JUDGE_RESULT_CODE IS NULL)THEN
     V_JUDGE_RESULT_CODE := '40740701';
     V_JUDGE_RESULT := '合格';
     ELSE
     V_JUDGE_RESULT_CODE := MYROW.JUDGE_RESULT_CODE;
     V_JUDGE_RESULT := MYROW.JUDGE_RESULT;
     END IF;
    INSERT INTO MAT_BC_M
      (MAT_NO,
       PRODUCT_FLAG,
       MAT_STATUS,
       LOT_NO,
       STOVE_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       MATERIAL_NO,
       MATERIAL_NAME,
       PRODUCCODE,
       PRODUCNAME,
       STEELCODE,
       STEELNAME,
       GRADECODE,
       GRADENAME,
       SPEC_CODE,
       SPEC_NAME,
       MODEL_CODE,
       MODEL_DESC,
       STD_CODE,
       STD_NAME,
       STD_STYLE,
       STD_STYLE_DESC,
       PRO_ORDER_NO,
       CRAF_NO,
       PROCESS_CDOE,
       PROCESS_DESC,
       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,
       JUDGE_RESULT_CODE,
       JUDGE_RESULT,
       JUDGE_RESULT_TIME,
       JUDGE_MAKER,
       INSTOCK_FLAG,
       INSTOCK_TIME,
       CREATE_NAME,
       CREATE_TIME,
       BAL_YEAR_MONTH,
       JUDGE_STD_NAME,
       PONDER_GROSS_WT,
       QCM_STAUS,
       TARGET,
       PROCESS_STATUS,
       FLAG_STOVE_NO_ZG,
       JUDGE_STD_DES,
       ZBS_FLAG,
       MEMO)
    VALUES
      (MYROW.MAT_NO,
       '801401',
       '80150102',
       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.STEELCODE,
       MYROW.STEELNAME,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       MYROW.SPEC_CODE,
       MYROW.SPEC_NAME,
       MYROW.MODEL_CODE,
       MYROW.MODEL_DESC,
       MYROW.STD_CODE,
       MYROW.STD_NAME,
       MYROW.STD_STYLE,
       MYROW.STD_STYLE_DESC,
       MYROW.PRO_ORDER_NO,
       MYROW.CRAF_NO,
       V_PROCESS_CDOE,
       V_PROCESS_DESC,
       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,
       MYROW.ACT_WEIGHT,
       MYROW.ACT_THEORY_WEIGHT,
       '002001001',
       '生产计划部',
       V_JUDGE_RESULT_CODE,
       V_JUDGE_RESULT,
       MYROW.JUDGE_RESULT_TIME,
       MYROW.JUDGE_MAKER,
       '1',
       MYROW.INSTOCK_TIME,
       MYROW.CREATE_NAME,
       MYROW.CREATE_TIME,
       MYROW.BAL_YEAR_MONTH,
       MYROW.JUDGE_STD_NAME,
       MYROW.PONDER_GROSS_WT,
       '00',
       'B',
       MYROW.PROCESS_STATUS,
       MYROW.FLAG_STOVE_NO_ZG,
       MYROW.JUDGE_STD_NAME,
       MYROW.ZBS_FLAG,
       MYROW.MEMO);
    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,
       MYROW.STORAGE_NO,
       MYROW.LOCATION_NO,
       MYROW.LARY_NO,
       MYROW.CREATE_NAME,
       MYROW.CREATE_TIME);
       V_INSTOCK_SEQ := '#INSTOCK_DOC#' || LPAD(V_COUNT, 4, 0);
    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,
       PRODUCT_FLAG,
       MAT_STATUS,
       JUDGE_STD_NAME,
       IN_TIME_F,
       BAL_YEAR_MONTH,
       QCM_STAUS)
    VALUES
      (V_INSTOCK_SEQ,
       '#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,
       MYROW.ACT_WEIGHT,
       MYROW.ACT_THEORY_WEIGHT,
       '002001001',
       '生产计划部',
       TO_DATE('#INSTOCK_TIME#','YYYY-MM-DD HH24:MI:SS'),
       '#CREATE_NAME#',
       TO_DATE('#INSTOCK_TIME#','YYYY-MM-DD HH24:MI:SS'),
       '801401',
       '80150102',
       MYROW.JUDGE_STD_NAME,
       TO_DATE('#INSTOCK_TIME#','YYYY-MM-DD HH24:MI:SS'),
       '#BAL_YEAR_MONTH#',
       '00');
       V_COUNT := V_COUNT + 1;
       V_ACT_WEIGHT := TO_NUMBER(NVL(V_ACT_WEIGHT,'0')) + TO_NUMBER(NVL(MYROW.ACT_WEIGHT,'0'));
       V_ACT_THEORY_WEIGHT := TO_NUMBER(NVL(V_ACT_THEORY_WEIGHT,'0')) + TO_NUMBER(NVL(MYROW.ACT_THEORY_WEIGHT,'0'));
       V_ACT_LEN := TO_NUMBER(NVL(V_ACT_LEN,'0')) + TO_NUMBER(NVL(MYROW.ACT_LEN,'0'));
  END LOOP;
    FOR MYROW1 IN(SELECT T.*, S.STORAGE_NO, S.LOCATION_NO, S.LARY_NO
                          FROM MAT_ZC_M T, YDM_ZC_BUTTRESS S
                         WHERE T.MAT_NO = S.MAT_NO
                           AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                           AND T.BATCH_NO = '#BATCH_NO#'
                           AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                           AND T.MAT_STATUS = '#MAT_STATUS#'
                           AND S.STORAGE_NO = '#STORAGE_NO#'
                           AND T.BAL_YEAR_MONTH = '#BAL_YEAR_MONTH#'
                           AND T.BELONG_CODE = '#BELONG_CODE#'
                           AND ROWNUM = 1)LOOP
   INSERT INTO QCM_ZG_JUGDE_APPLY(
        JUGDE_APPLY_CODE,
        JUDGE_STOVE_NO,
        BATCH_NO,
        BATCH_GROUD_NO,
        PROCESS_CODE,
        PLINE_CODE,
        ACT_COUNT,
        ACT_WEIGHT,
        ACT_THEORY_WEIGHT,
        VALIDFLAG,
        APPLY_NAME,
        APPLY_TIME,
        MATERIAL_NO,
        MATERIAL_NAME,
        PRODUCCODE,
        PRODUCNAME,
        STEELCODE,
        STEELNAME,
        GRADECODE,
        GRADENAME,
        SPEC_CODE,
        SPEC_NAME,
        MODEL_CODE,
        MODEL_DESC,
        STD_CODE,
        STD_NAME,
        STD_STYLE,
        STD_STYLE_DESC,
        LOT_NO,
        PLINE_NAME,
        PRO_ORDER_NO,
        TARGET,
        PROCESS_STATUS,
        ACT_DIMATER,
        ACT_HEIGHT,
        ACT_LEN_MIN,
        ACT_LEN_MAX,
        JUDGE_RESULT_CODE,
        JUDGE_RESULT,
        JUDGE_RESULT_TIME,
        JUDGE_MAKER,
        INSTOCK_FLAG,
        BELONG_CODE,
        BELONG_NAME,
        ACT_LEN,
        BELONG_CODE_JUGDE,
        BELONG_NAME_JUGDE,
        BAL_YEAR_MONTH,
        IS_ALL_SCRAP,
        STOVE_NO,
        STEEL_STANDRAD,
        JUGDE_APPLY_SEQUENO,
        QUALITY_GROUP,
        MAT_GOWHERE_CODE,
        MAT_GOWHERE_NAME)
 VALUES( 
        V_JUGDE_APPLY_CODE,
        MYROW1.JUDGE_STOVE_NO,
        MYROW1.BATCH_NO,
        MYROW1.BATCH_GROUD_NO,
        V_PROCESS_CDOE,
        MYROW1.PLINE_CODE,
        '-'||'#ACT_COUNT#',
        '-'||V_ACT_WEIGHT,
        '-'||V_ACT_THEORY_WEIGHT,
        '20',
        '#CREATE_NAME#',
        TO_DATE('#INSTOCK_TIME#','YYYY-MM-DD HH24:MI:SS'),
        MYROW1.MATERIAL_NO,
        MYROW1.MATERIAL_NAME,
        MYROW1.PRODUCCODE,
        MYROW1.PRODUCNAME,
        MYROW1.STEELCODE,
        MYROW1.STEELNAME,
        MYROW1.GRADECODE,
        MYROW1.GRADENAME,
        MYROW1.SPEC_CODE,
        MYROW1.SPEC_NAME,
        MYROW1.MODEL_CODE,
        MYROW1.MODEL_DESC,
        MYROW1.STD_CODE,
        MYROW1.STD_NAME,
        MYROW1.STD_STYLE,
        MYROW1.STD_STYLE_DESC,
        MYROW1.LOT_NO,
        MYROW1.PLINE_NAME,
        MYROW1.PRO_ORDER_NO,
        'A',
        MYROW1.PROCESS_STATUS,
        MYROW1.ACT_DIMATER,
        MYROW1.ACT_HEIGHT,
        MYROW1.ACT_LEN_MIN,
        MYROW1.ACT_LEN_MAX,
        '40740701',
        '合格',
        TO_DATE('#INSTOCK_TIME#','YYYY-MM-DD HH24:MI:SS'),
        '#CREATE_NAME#',
        '0',
        V_BELONG_CODE,
        V_BELONG_NAME,
        V_ACT_LEN,
        MYROW1.BELONG_CODE,
        MYROW1.BELONG_NAME,
        '#BAL_YEAR_MONTH#',
        '3',
        MYROW1.STOVE_NO,
        MYROW1.JUDGE_STD_NAME,
        '1',
        '1',
        '/',
        '/');
        END LOOP;
END;
]]>
</query>
<query id = "pipRedStore.insertBcM1" desc = "退制造部半成品(库存大于红冲支)">
DECLARE
  V_INSTOCK_SEQ  YDM_BC_INLIST.INSTOCK_SQE%TYPE := NULL;
  V_COUNT       NUMBER := 1;
  V_PROCESS_CDOE MAT_BC_M.PROCESS_CDOE%TYPE := NULL;
  V_PROCESS_DESC MAT_BC_M.PROCESS_DESC%TYPE := NULL;
BEGIN
  FOR MYROW IN (SELECT T.*, S.STORAGE_NO, S.LOCATION_NO, S.LARY_NO
                          FROM MAT_ZC_M T, YDM_ZC_BUTTRESS S
                         WHERE T.MAT_NO = S.MAT_NO
                           AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                           AND T.BATCH_NO = '#BATCH_NO#'
                           AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                           AND T.MAT_NO = '#MAT_NO#'
                         )LOOP

    INSERT INTO MAT_BC_M
      (MAT_NO,
       PRODUCT_FLAG,
       MAT_STATUS,
       LOT_NO,
       STOVE_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       MATERIAL_NO,
       MATERIAL_NAME,
       PRODUCCODE,
       PRODUCNAME,
       STEELCODE,
       STEELNAME,
       GRADECODE,
       GRADENAME,
       SPEC_CODE,
       SPEC_NAME,
       MODEL_CODE,
       MODEL_DESC,
       STD_CODE,
       STD_NAME,
       STD_STYLE,
       STD_STYLE_DESC,
       PRO_ORDER_NO,
       CRAF_NO,
       PROCESS_CDOE,
       PROCESS_DESC,
       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,
       JUDGE_RESULT_CODE,
       JUDGE_RESULT,
       JUDGE_RESULT_TIME,
       JUDGE_MAKER,
       INSTOCK_FLAG,
       INSTOCK_TIME,
       CREATE_NAME,
       CREATE_TIME,
       BAL_YEAR_MONTH,
       JUDGE_STD_NAME,
       PONDER_GROSS_WT,
       QCM_STAUS,
       TARGET,
       PROCESS_STATUS,
       FLAG_STOVE_NO_ZG,
       JUDGE_STD_DES,
       ZBS_FLAG,
       MEMO)
    VALUES
      (MYROW.MAT_NO,
       '801401',
       '80150102',
       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.STEELCODE,
       MYROW.STEELNAME,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       MYROW.SPEC_CODE,
       MYROW.SPEC_NAME,
       MYROW.MODEL_CODE,
       MYROW.MODEL_DESC,
       MYROW.STD_CODE,
       MYROW.STD_NAME,
       MYROW.STD_STYLE,
       MYROW.STD_STYLE_DESC,
       MYROW.PRO_ORDER_NO,
       MYROW.CRAF_NO,
       V_PROCESS_CDOE,
       V_PROCESS_DESC,
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.ACT_DIMATER,
       MYROW.ACT_HEIGHT,
       '#ACT_LEN#',
       MYROW.ACT_LEN_MIN,
       MYROW.ACT_LEN_MAX,
       MYROW.ACT_COUNT,
       '#ACT_WEIGHT#',
       '#ACT_WEIGHT#',
       '002001001',
       '生产计划部',
       MYROW.JUDGE_RESULT_CODE,
       MYROW.JUDGE_RESULT,
       MYROW.JUDGE_RESULT_TIME,
       MYROW.JUDGE_MAKER,
       '1',
       MYROW.INSTOCK_TIME,
       MYROW.CREATE_NAME,
       MYROW.INSTOCK_TIME,
       MYROW.BAL_YEAR_MONTH,
       MYROW.JUDGE_STD_NAME,
       MYROW.PONDER_GROSS_WT,
       '00',
       'B',
       MYROW.PROCESS_STATUS,
       MYROW.FLAG_STOVE_NO_ZG,
       MYROW.JUDGE_STD_NAME,
       MYROW.ZBS_FLAG,
       MYROW.MEMO);
    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,
       MYROW.STORAGE_NO,
       MYROW.LOCATION_NO,
       MYROW.LARY_NO,
       MYROW.CREATE_NAME,
       MYROW.CREATE_TIME);
    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,
       PRODUCT_FLAG,
       MAT_STATUS,
       JUDGE_STD_NAME,
       IN_TIME_F,
       BAL_YEAR_MONTH,
       QCM_STAUS)
    VALUES
      ('#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,
       '#ACT_LEN#',
       MYROW.ACT_LEN_MIN,
       MYROW.ACT_LEN_MAX,
       MYROW.ACT_COUNT,
       '#ACT_WEIGHT#',
       '#ACT_WEIGHT#',
       '002001001',
       '生产计划部',
       TO_DATE('#INSTOCK_TIME#','YYYY-MM-DD HH24:MI:SS'),
       '#CREATE_NAME#',
       TO_DATE('#INSTOCK_TIME#','YYYY-MM-DD HH24:MI:SS'),
       '801401',
       '80150102',
       MYROW.JUDGE_STD_NAME,
       TO_DATE('#INSTOCK_TIME#','YYYY-MM-DD HH24:MI:SS'),
       '#BAL_YEAR_MONTH#',
       '00');
  END LOOP;
END;
</query>
<query id = "FrmPipStoreRed.querySendSqlCx" desc = "查询入库流水号">
SELECT ? ||
       LPAD(NVL(MAX(SUBSTR(T.INSTOCK_SQE, LENGTH(T.INSTOCK_SQE) - 4)), 0) + 1,
            5,
            0) INSTOCK_SQE
  FROM YDM_BC_INLIST T
 WHERE TRUNC(T.CREATE_TIME) = TRUNC(SYSDATE)
   AND T.INSTOCK_DOC = ?
</query>
<query id = "FrmPipStoreRed.insertQcm" desc = "红冲写申请判定表">

DECLARE
  V_INSTOCK_SEQ  YDM_BC_INLIST.INSTOCK_SQE%TYPE := NULL;
  V_COUNT       NUMBER := 1;
  V_PROCESS_CDOE MAT_BC_M.PROCESS_CDOE%TYPE := NULL;
  V_PROCESS_DESC MAT_BC_M.PROCESS_DESC%TYPE := NULL;
  V_ACT_WEIGHT QCM_ZG_JUGDE_APPLY.ACT_WEIGHT%TYPE := NULL;
  V_ACT_THEORY_WEIGHT  QCM_ZG_JUGDE_APPLY.ACT_THEORY_WEIGHT%TYPE := NULL;
  V_ACT_LEN QCM_ZG_JUGDE_APPLY.ACT_LEN%TYPE := NULL;
  V_BELONG_CODE QCM_ZG_JUGDE_APPLY.BELONG_CODE%TYPE := NULL;
  V_BELONG_NAME QCM_ZG_JUGDE_APPLY.BELONG_NAME%TYPE := NULL;
  V_JUGDE_APPLY_CODE QCM_ZG_JUGDE_APPLY.JUGDE_APPLY_CODE%TYPE :=NULL;
BEGIN
FOR MYROW1 IN(SELECT T.*, S.STORAGE_NO, S.LOCATION_NO, S.LARY_NO
                          FROM MAT_ZC_M T, YDM_ZC_BUTTRESS S
                         WHERE T.MAT_NO = S.MAT_NO
                           AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                           AND T.BATCH_NO = '#BATCH_NO#'
                           AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                           AND T.MAT_STATUS = '#MAT_STATUS#'
                           AND S.STORAGE_NO = '#STORAGE_NO#'
                           AND T.BELONG_CODE = '#BELONG_CODE_JUGDE#'
                           AND ROWNUM = 1)LOOP
                           SELECT S2.PROCESS_CODE, S2.PROCESS_DESC,S2.DEPARTMENT_CODE,S2.DEPARTMENT_DESC
      INTO V_PROCESS_CDOE, V_PROCESS_DESC,V_BELONG_CODE,V_BELONG_NAME
      FROM COM_BASE_PLINE S2
     WHERE S2.PLINE_CODE = MYROW1.PLINE_CODE;
     SELECT 'H'||MYROW1.PLINE_CODE||'801401'||TO_CHAR(SYSDATE, 'YYYYMMDD') ||
               LPAD(NVL(MAX(SUBSTR(T.JUGDE_APPLY_CODE, 19)), 0) + 1, 6, 0) JUGDE_APPLY_CODE INTO V_JUGDE_APPLY_CODE
          FROM QCM_ZG_JUGDE_APPLY T
         WHERE T.IS_ALL_SCRAP = '3'
           AND TRUNC(T.APPLY_TIME) = TRUNC(TO_DATE('#APPLY_TIME#','YYYY-MM-DD HH24:MI:SS'));
   INSERT INTO QCM_ZG_JUGDE_APPLY(
        JUGDE_APPLY_CODE,
        JUDGE_STOVE_NO,
        BATCH_NO,
        BATCH_GROUD_NO,
        PROCESS_CODE,
        PLINE_CODE,
        ACT_COUNT,
        ACT_WEIGHT,
        ACT_THEORY_WEIGHT,
        VALIDFLAG,
        APPLY_NAME,
        APPLY_TIME,
        MATERIAL_NO,
        MATERIAL_NAME,
        PRODUCCODE,
        PRODUCNAME,
        STEELCODE,
        STEELNAME,
        GRADECODE,
        GRADENAME,
        SPEC_CODE,
        SPEC_NAME,
        MODEL_CODE,
        MODEL_DESC,
        STD_CODE,
        STD_NAME,
        STD_STYLE,
        STD_STYLE_DESC,
        LOT_NO,
        PLINE_NAME,
        PRO_ORDER_NO,
        TARGET,
        PROCESS_STATUS,
        ACT_DIMATER,
        ACT_HEIGHT,
        ACT_LEN_MIN,
        ACT_LEN_MAX,
        JUDGE_RESULT_CODE,
        JUDGE_RESULT,
        JUDGE_RESULT_TIME,
        JUDGE_MAKER,
        INSTOCK_FLAG,
        BELONG_CODE,
        BELONG_NAME,
        ACT_LEN,
        BELONG_CODE_JUGDE,
        BELONG_NAME_JUGDE,
        BAL_YEAR_MONTH,
        IS_ALL_SCRAP,
        STOVE_NO,
        STEEL_STANDRAD,
        JUGDE_APPLY_SEQUENO)
 VALUES( 
        V_JUGDE_APPLY_CODE,
        MYROW1.JUDGE_STOVE_NO,
        MYROW1.BATCH_NO,
        MYROW1.BATCH_GROUD_NO,
        V_PROCESS_CDOE,
        MYROW1.PLINE_CODE,
        '#ACT_COUNT#',
        '#ACT_WEIGHT#',
        '#ACT_THEORY_WEIGHT#',
        '20',
        '#APPLY_NAME#',
        TO_DATE('#APPLY_TIME#','YYYY-MM-DD HH24:MI:SS'),
        MYROW1.MATERIAL_NO,
        MYROW1.MATERIAL_NAME,
        MYROW1.PRODUCCODE,
        MYROW1.PRODUCNAME,
        MYROW1.STEELCODE,
        MYROW1.STEELNAME,
        MYROW1.GRADECODE,
        MYROW1.GRADENAME,
        MYROW1.SPEC_CODE,
        MYROW1.SPEC_NAME,
        MYROW1.MODEL_CODE,
        MYROW1.MODEL_DESC,
        MYROW1.STD_CODE,
        MYROW1.STD_NAME,
        MYROW1.STD_STYLE,
        MYROW1.STD_STYLE_DESC,
        MYROW1.LOT_NO,
        MYROW1.PLINE_NAME,
        MYROW1.PRO_ORDER_NO,
        'A',
        MYROW1.PROCESS_STATUS,
        MYROW1.ACT_DIMATER,
        MYROW1.ACT_HEIGHT,
        MYROW1.ACT_LEN_MIN,
        MYROW1.ACT_LEN_MAX,
        '40740701',
        '合格',
        TO_DATE('#APPLY_TIME#','YYYY-MM-DD HH24:MI:SS'),
        '#CREATE_NAME#',
        '0',
        V_BELONG_CODE,
        V_BELONG_NAME,
        V_ACT_LEN,
        MYROW1.BELONG_CODE,
        MYROW1.BELONG_NAME,
        '#BAL_YEAR_MONTH#',
        '3',
        MYROW1.STOVE_NO,
        MYROW1.JUDGE_STD_NAME,
        '1');
        END LOOP;
END;
</query>
<query id = "pipCancelRedStore.selectMatBcPro" desc = "查询半成品是否已利库">
SELECT COUNT(1) ACOUNT
  FROM MAT_BC_M T
 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.BATCH_NO = '#BATCH_NO#'
   AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
   AND T.PRO_PLAN_ID_NEXT IS NOT NULL
</query>
<query id = "pipCancelRedStore.cancelRed" desc = "撤销红冲">
DECLARE
BEGIN
  FOR MYROW IN (SELECT T1.*,
                       T.INSTOCK_SQE,
                       S.STORAGE_NO,
                       S.LOCATION_NO,
                       S.LARY_NO
                  FROM YDM_ZC_INLIST T, MAT_BC_M T1, YDM_BC_BUTTRESS S
                 WHERE T.MAT_NO = T1.MAT_NO
                   AND T.MAT_NO = S.MAT_NO
                   AND T1.MAT_NO = S.MAT_NO
                   AND T.INSTOCK_DOC = '#INSTOCK_DOC#'
                 ORDER BY T1.MAT_NO ASC) LOOP
    INSERT INTO MAT_ZC_M
      (STOVE_NO,
       LOT_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       MATERIAL_NO,
       MATERIAL_NAME,
       PRODUCCODE,
       PRODUCNAME,
       STD_STYLE,
       STD_STYLE_DESC,
       STEELCODE,
       STEELNAME,
       SPEC_CODE,
       SPEC_NAME,
       MODEL_CODE,
       MODEL_DESC,
       STD_CODE,
       STD_NAME,
       PRO_ORDER_NO,
       BELONG_CODE,
       BELONG_NAME,
       ACT_DIMATER,
       ACT_HEIGHT,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_LEN,
       ACT_COUNT,
       ACT_WEIGHT,
       ACT_THEORY_WEIGHT,
       CREATE_NAME,
       CREATE_TIME,
       INSTOCK_TIME,
       MAT_NO,
       MEMO,
       JUGDE_APPLY_FLAG,
       INSTOCK_FLAG,
       PRODUCT_FLAG,
       MAT_STATUS,
       JUDGE_STD_NAME,
       BAL_YEAR_MONTH,
       PLINE_CODE,
       PLINE_NAME,
       GRADECODE,
       GRADENAME,
       JUDGE_RESULT_CODE,
       JUDGE_RESULT,
       JUDGE_RESULT_TIME,
       JUDGE_MAKER)
    VALUES
      (MYROW.STOVE_NO,
       MYROW.LOT_NO,
       MYROW.JUDGE_STOVE_NO,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_NAME,
       MYROW.PRODUCCODE,
       MYROW.PRODUCNAME,
       MYROW.STD_STYLE,
       MYROW.STD_STYLE_DESC,
       MYROW.STEELCODE,
       MYROW.STEELNAME,
       MYROW.SPEC_CODE,
       MYROW.SPEC_NAME,
       MYROW.MODEL_CODE,
       MYROW.MODEL_DESC,
       MYROW.STD_CODE,
       MYROW.STD_NAME,
       MYROW.PRO_ORDER_NO,
       '#BELONG_CODE#',
       '#BELONG_NAME#',
       MYROW.ACT_DIMATER,
       MYROW.ACT_HEIGHT,
       MYROW.ACT_LEN_MIN,
       MYROW.ACT_LEN_MAX,
       MYROW.ACT_LEN,
       MYROW.ACT_COUNT,
       MYROW.ACT_WEIGHT,
       MYROW.ACT_THEORY_WEIGHT,
       MYROW.CREATE_NAME,
       MYROW.CREATE_TIME,
       MYROW.INSTOCK_TIME,
       MYROW.MAT_NO,
       MYROW.MEMO,
       '1',
       '1',
       '801402',
       '80150202',
       MYROW.JUDGE_STD_DES,
       MYROW.BAL_YEAR_MONTH,
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       MYROW.JUDGE_TOLRESULT_CODE,
       MYROW.JUDGE_TOLRESULT,
       MYROW.JUDGE_TOLRESULT_TIME,
       MYROW.JUDGE_TOLMAKER);
       
       INSERT INTO MAT_ZC_M_XS
      (STOVE_NO,
       LOT_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       MATERIAL_NO,
       MATERIAL_NAME,
       PRODUCCODE,
       PRODUCNAME,
       STD_STYLE,
       STD_STYLE_DESC,
       STEELCODE,
       STEELNAME,
       SPEC_CODE,
       SPEC_NAME,
       MODEL_CODE,
       MODEL_DESC,
       STD_CODE,
       STD_NAME,
       PRO_ORDER_NO,
       BELONG_CODE,
       BELONG_NAME,
       ACT_DIMATER,
       ACT_HEIGHT,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_LEN,
       ACT_COUNT,
       ACT_WEIGHT,
       ACT_THEORY_WEIGHT,
       CREATE_NAME,
       CREATE_TIME,
       INSTOCK_TIME,
       MAT_NO,
       MEMO,
       JUGDE_APPLY_FLAG,
       INSTOCK_FLAG,
       PRODUCT_FLAG,
       MAT_STATUS,
       JUDGE_STD_NAME,
       BAL_YEAR_MONTH,
       PLINE_CODE,
       PLINE_NAME,
       GRADECODE,
       GRADENAME,
       JUDGE_RESULT_CODE,
       JUDGE_RESULT,
       JUDGE_RESULT_TIME,
       JUDGE_MAKER)
    VALUES
      (MYROW.STOVE_NO,
       MYROW.LOT_NO,
       MYROW.JUDGE_STOVE_NO,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_NAME,
       MYROW.PRODUCCODE,
       MYROW.PRODUCNAME,
       MYROW.STD_STYLE,
       MYROW.STD_STYLE_DESC,
       MYROW.STEELCODE,
       MYROW.STEELNAME,
       MYROW.SPEC_CODE,
       MYROW.SPEC_NAME,
       MYROW.MODEL_CODE,
       MYROW.MODEL_DESC,
       MYROW.STD_CODE,
       MYROW.STD_NAME,
       MYROW.PRO_ORDER_NO,
       '#BELONG_CODE#',
       '#BELONG_NAME#',
       MYROW.ACT_DIMATER,
       MYROW.ACT_HEIGHT,
       MYROW.ACT_LEN_MIN,
       MYROW.ACT_LEN_MAX,
       MYROW.ACT_LEN,
       MYROW.ACT_COUNT,
       MYROW.ACT_WEIGHT,
       MYROW.ACT_THEORY_WEIGHT,
       MYROW.CREATE_NAME,
       MYROW.CREATE_TIME,
       MYROW.INSTOCK_TIME,
       MYROW.MAT_NO,
       MYROW.MEMO,
       '1',
       '1',
       '801402',
       '80150202',
       MYROW.JUDGE_STD_DES,
       MYROW.BAL_YEAR_MONTH,
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       MYROW.JUDGE_TOLRESULT_CODE,
       MYROW.JUDGE_TOLRESULT,
       MYROW.JUDGE_TOLRESULT_TIME,
       MYROW.JUDGE_TOLMAKER);
    INSERT INTO YDM_ZC_BUTTRESS
      (JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       STORAGE_NO,
       LOCATION_NO,
       LARY_NO,
       CREATE_NAME,
       MAT_NO,
       CREATE_TIME)
    VALUES
      (MYROW.JUDGE_STOVE_NO,
       MYROW.BATCH_NO,
       MYROW.BATCH_GROUD_NO,
       MYROW.STORAGE_NO,
       MYROW.LOCATION_NO,
       MYROW.LARY_NO,
       MYROW.CREATE_NAME,
       MYROW.MAT_NO,
       MYROW.CREATE_TIME);
    DELETE FROM YDM_ZC_INLIST T WHERE T.INSTOCK_SQE = MYROW.INSTOCK_SQE;
    DELETE FROM YDM_ZC_INLIST_XS T WHERE T.INSTOCK_SQE = MYROW.INSTOCK_SQE;
    DELETE FROM MAT_BC_M T WHERE T.MAT_NO = MYROW.MAT_NO;
    DELETE FROM YDM_BC_BUTTRESS T WHERE T.MAT_NO = MYROW.MAT_NO;
    DELETE FROM YDM_BC_INLIST T
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.INSTOCK_TYPE_CODE = '800709';
  END LOOP;
  DELETE FROM QCM_ZG_JUGDE_APPLY T
   WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     AND T.BATCH_NO = '#BATCH_NO#'
     AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
     AND T.IS_ALL_SCRAP = '3'
     AND T.BELONG_CODE_JUGDE = '#BELONG_CODE#';
END;
</query>
</queryMap>