Jelajahi Sumber

提交一部分脚本

Signed-off-by: zhangguo <zhangguo@qq.com>
zhangguo 4 hari lalu
induk
melakukan
4d15bf9012

+ 208 - 0
MES_FIN_MONTH/FinMES202602/MES_CX_YDM_BC_INITIAL_hand.md

@@ -0,0 +1,208 @@
+# MES_CX_YDM_BC_INITIAL_hand 存储过程(什么什么热轧)
+
+## 模板下载
+
+[模板](./MES_CX_YDM_BC_INITIAL_hand.sql)
+
+用{0}表达 当前月份 替换成02
+
+用{1}表达 下个月份 替换成03
+
+用{2}表达 下个月份 替换成01
+
+## 原始脚本内容
+
+```sql
+CREATE OR REPLACE procedure MES_CX_YDM_BC_INITIAL_hand is
+      a number(4);
+      b varchar(200);
+
+
+
+
+ CURSOR OPOrder_Cursor IS
+
+
+select --t1.bal_year_month 记账日期,
+ substr(t1.bal_year_month, 0, 4) || '-' || substr(t1.bal_year_month, 5, 2) bal_year_month,
+  --记账日期
+ --  'BZJ3' 库存地编码,
+ '天淮中间库' ckmc,
+  --库存地名称,
+ --material_no 物料编码,
+ --GET_CP_CODE4(GET_CP_ORDER(T1.Judge_Stove_No)) material_no,--物料编码,
+ --换成取产销提供的视图 tzh 24.12.4
+ /*GET_CP_CODE6(GET_CP_ORDER(T1.Judge_Stove_No)) material_no,--物料编码,
+ material_name , --物料名称,
+ spec_code, --产品规格代码,
+ spec_name,-- 产品规格描述,
+ std_code ,--执行标准代码,
+ std_name ,--执行标准名称,
+ produccode ,--品名代码,
+ producname ,--品名描述,
+ gradecode ,--钢种代码,
+ gradename ,--钢种名称,
+ steelcode ,--钢级代码,
+ steelname ,--钢级名称,*/ t1.judge_stove_no, t2.material_code material_no,
+  --物料编码,
+ t2.material_name material_name,
+  --物料名称,
+ spec_code,
+  --产品规格代码,
+ t2.outer_diam || '*' || t2.wall_thickness spec_name,
+  -- 产品规格描述,
+ std_code,
+  --执行标准代码,
+ std_name,
+  --执行标准名称,
+ produccode,
+  --品名代码,
+ t2.prod_name producname,
+  --品名描述,
+ gradecode,
+  --钢种代码,
+ t2.sg_grade gradename,
+  --钢种名称,
+ steelcode,
+  --钢级代码,
+ t2.sg_sign steelname,
+  --钢级名称,
+ act_count,
+  --期初库存支数,
+ act_weight,
+  --期初库存重量,
+ 0 act_in_count,
+  --本期入库支数,
+ 0 act_in_weight,
+  --本期入库重量,
+ 0 act_out_count,
+  --本期出库支数,
+ 0 act_out_weight,
+  --本期出库重量,
+ --0 期末库存支数,
+ --0 期末库存重量,
+ t1.INSTOCK_TIME, --入库时间
+ getislljg(t1.judge_stove_no,
+            nvl((t1.order_no || t1.order_seq),
+                replace(get_cp_order(t1.judge_stove_no), '/', ''))) is_lljg,
+  --是否来料加工,
+ --t1.process_desc 工序,
+ --t1.process_cdoe,
+ --(case when t1.pline_code = 'C072' then '热轧'when  t1.pline_code = 'C091' then '热处理' else t1.pline_code end) xx,
+ (case
+   when t1.process_cdoe = 'D' then
+    '热轧'
+   when t1.process_cdoe = 'E' then
+    '镦拔扩'
+   when t1.process_cdoe = 'F' then
+    '热处理'
+   else
+    t1.process_cdoe
+ end) process_name,
+  --工序,
+ --nvl(t1.process_cdoe,(case when t1.pline_code = 'C072' then '热轧'when  t1.pline_code = 'C091' then '热处理' else t1.pline_code end)) 工序,
+ --(case when t1.pline_code = 'C072' then '热轧'when  t1.pline_code = 'C091' then '热处理' else t1.pline_code end) 工序,
+
+ --'否' is_ckc,
+  --是否出口材
+      (case
+       when nvl(t2.if_export,'内贸') ='内贸' then
+        '否'
+       when nvl(t2.if_export,'内贸') ='外贸' then
+        '是'
+       else
+        '否'
+      end) is_ckc,
+
+ dimater,
+  --外径
+ height,
+  --壁厚
+ nvl((t1.order_no || t1.order_seq),
+      replace(get_cp_order(t1.judge_stove_no), '/', '')) orderid,
+  --合同号
+ model_desc,
+  -- 扣型描述
+ get_cp_buyer(get_cp_order(t1.judge_stove_no)) buyer,
+  --客户名称
+ get_cp_pass(get_cp_order(t1.judge_stove_no)) pass --孔型
+
+  from ydm_bc_initial t1, mvm_order_matno_info t2 --添加MVM
+
+ where nvl((t1.order_no || t1.order_seq),
+           replace(get_cp_order(t1.judge_stove_no), '/', '')) =
+       t2.contractno_num(+)
+
+
+   and
+      --t1.bal_year_month = to_char(sysdate,'yyyymm')
+       t1.bal_year_month in ('202602')
+   and t1.belong_code = '002023005'
+   and nvl((t1.order_no || t1.order_seq),
+           replace(get_cp_order(t1.judge_stove_no), '/', ''))
+
+       not in ('XSXPQ-21A1666001',
+               'XSXPQ-21A0068001',
+               'XSXPQ-21A0067001',
+               'XSXPQ-20A2850002',
+               'XSXPQ-20A2496001',
+               'XSXPQ-20A2487001',
+               'XSXPQ-20A2458002',
+               'XSXPQ-20A2398001',
+               'XSXPQ-20A2378001',
+               'XSXPQ-20A2292001',
+               'XSXPQ-20A2247001',
+               'XSXPQ-20A1104001',
+               'GMXPQ-20A2235002',
+               'GMXPQ-20A2235001',
+               'EXSPQ-200072X001',
+               'EXMGQ-210634E003',
+               'EXMGQ-210604E012',
+               'EXMGQ-210263E001',
+               'EXMGQ-200457E001',
+               'ZZBY-D230116007')
+and nvl((t1.order_no || t1.order_seq),
+               replace(get_cp_order(t1.judge_stove_no), '/', '')) not like 'ZZBY%'
+      -- and t1.judge_stove_no like 'F%'
+;
+
+curoporder oporder_cursor%rowtype;
+
+begin
+  open oporder_cursor;
+  loop
+    fetch oporder_cursor
+      into curoporder;
+    exit when oporder_cursor%notfound;
+
+    insert into cx_ydm_bc_initial
+      (bal_year_month, ckmc, material_no, material_name, spec_code,
+       spec_name, std_code, std_name, produccode, producname, gradecode,
+       gradename, steelcode, steelname, act_count, act_weight, act_in_count,
+       act_in_weight, act_out_count, act_out_weight, is_lljg, process_name,
+       is_ckc, dimater, height, pass, model_desc, buyer, orderid, bc_type,
+       judge_stove_no,INSTOCK_TIME,INSERT_TIME)
+    values
+      (curoporder.bal_year_month, curoporder.ckmc, curoporder.material_no,
+       curoporder.material_name, curoporder.spec_code, curoporder.spec_name,
+       curoporder.std_code, curoporder.std_name, curoporder.produccode,
+       curoporder.producname, curoporder.gradecode, curoporder.gradename,
+       curoporder.steelcode, curoporder.steelname, curoporder.act_count,
+       curoporder.act_weight, curoporder.act_in_count,
+       curoporder.act_in_weight, curoporder.act_out_count,
+       curoporder.act_out_weight, curoporder.is_lljg,
+       curoporder.process_name, curoporder.is_ckc, curoporder.dimater,
+       curoporder.height, curoporder.pass, curoporder.model_desc,
+       curoporder.buyer, curoporder.orderid, '半成品期初库存',
+       curoporder.judge_stove_no,curOPOrder.INSTOCK_TIME,sysdate);
+  end loop;
+  close oporder_cursor;
+  commit;
+
+  /*
+
+  exception
+    when others then
+      null;*/
+end mes_cx_ydm_bc_initial_hand;
+```

+ 164 - 0
MES_FIN_MONTH/FinMES202602/MES_CX_YDM_BC_INITIAL_hand.sql

@@ -0,0 +1,164 @@
+CREATE OR REPLACE procedure MES_CX_YDM_BC_INITIAL_hand is
+      a number(4);
+      b varchar(200);
+
+ CURSOR OPOrder_Cursor IS
+
+
+select --t1.bal_year_month 记账日期,
+ substr(t1.bal_year_month, 0, 4) || '-' || substr(t1.bal_year_month, 5, 2) bal_year_month,
+  --记账日期
+ '天淮中间库' ckmc,
+ t1.judge_stove_no, 
+ t2.material_code material_no,
+  --物料编码,
+ t2.material_name material_name,
+  --物料名称,
+ spec_code,
+  --产品规格代码,
+ t2.outer_diam || '*' || t2.wall_thickness spec_name,
+  -- 产品规格描述,
+ std_code,
+  --执行标准代码,
+ std_name,
+  --执行标准名称,
+ produccode,
+  --品名代码,
+ t2.prod_name producname,
+  --品名描述,
+ gradecode,
+  --钢种代码,
+ t2.sg_grade gradename,
+  --钢种名称,
+ steelcode,
+  --钢级代码,
+ t2.sg_sign steelname,
+  --钢级名称,
+ act_count,
+  --期初库存支数,
+ act_weight,
+  --期初库存重量,
+ 0 act_in_count,
+  --本期入库支数,
+ 0 act_in_weight,
+  --本期入库重量,
+ 0 act_out_count,
+  --本期出库支数,
+ 0 act_out_weight,
+  --本期出库重量,
+ --0 期末库存支数,
+ --0 期末库存重量,
+ t1.INSTOCK_TIME, --入库时间
+ getislljg(t1.judge_stove_no,
+            nvl((t1.order_no || t1.order_seq),
+                replace(get_cp_order(t1.judge_stove_no), '/', ''))) is_lljg,
+ (case
+   when t1.process_cdoe = 'D' then
+    '热轧'
+   when t1.process_cdoe = 'E' then
+    '镦拔扩'
+   when t1.process_cdoe = 'F' then
+    '热处理'
+   else
+    t1.process_cdoe
+ end) process_name,
+  --工序,
+ --nvl(t1.process_cdoe,(case when t1.pline_code = 'C072' then '热轧'when  t1.pline_code = 'C091' then '热处理' else t1.pline_code end)) 工序,
+ --(case when t1.pline_code = 'C072' then '热轧'when  t1.pline_code = 'C091' then '热处理' else t1.pline_code end) 工序,
+ 
+ --'否' is_ckc,
+  --是否出口材
+      (case
+       when nvl(t2.if_export,'内贸') ='内贸' then
+        '否'
+       when nvl(t2.if_export,'内贸') ='外贸' then
+        '是'
+       else
+        '否'
+      end) is_ckc,
+  
+ dimater,
+  --外径
+ height,
+  --壁厚
+ nvl((t1.order_no || t1.order_seq),
+      replace(get_cp_order(t1.judge_stove_no), '/', '')) orderid,
+  --合同号
+ model_desc,
+  -- 扣型描述
+ get_cp_buyer(get_cp_order(t1.judge_stove_no)) buyer,
+  --客户名称
+ get_cp_pass(get_cp_order(t1.judge_stove_no)) pass --孔型
+ 
+  from ydm_bc_initial t1, mvm_order_matno_info t2 --添加MVM
+
+ where nvl((t1.order_no || t1.order_seq),
+           replace(get_cp_order(t1.judge_stove_no), '/', '')) =
+       t2.contractno_num(+)
+
+           
+   and
+      --t1.bal_year_month = to_char(sysdate,'yyyymm')
+       t1.bal_year_month in ('{0}}')
+   and t1.belong_code = '002023005'
+   and nvl((t1.order_no || t1.order_seq),
+           replace(get_cp_order(t1.judge_stove_no), '/', ''))
+    
+       not in ('XSXPQ-21A1666001',
+               'XSXPQ-21A0068001',
+               'XSXPQ-21A0067001',
+               'XSXPQ-20A2850002',
+               'XSXPQ-20A2496001',
+               'XSXPQ-20A2487001',
+               'XSXPQ-20A2458002',
+               'XSXPQ-20A2398001',
+               'XSXPQ-20A2378001',
+               'XSXPQ-20A2292001',
+               'XSXPQ-20A2247001',
+               'XSXPQ-20A1104001',
+               'GMXPQ-20A2235002',
+               'GMXPQ-20A2235001',
+               'EXSPQ-200072X001',
+               'EXMGQ-210634E003',
+               'EXMGQ-210604E012',
+               'EXMGQ-210263E001',
+               'EXMGQ-200457E001',
+               'ZZBY-D230116007')
+and nvl((t1.order_no || t1.order_seq),
+               replace(get_cp_order(t1.judge_stove_no), '/', '')) not like 'ZZBY%'
+;
+
+curoporder oporder_cursor%rowtype;
+
+begin
+  open oporder_cursor;
+  loop
+    fetch oporder_cursor
+      into curoporder;
+    exit when oporder_cursor%notfound;
+
+    insert into cx_ydm_bc_initial
+      (bal_year_month, ckmc, material_no, material_name, spec_code,
+       spec_name, std_code, std_name, produccode, producname, gradecode,
+       gradename, steelcode, steelname, act_count, act_weight, act_in_count,
+       act_in_weight, act_out_count, act_out_weight, is_lljg, process_name,
+       is_ckc, dimater, height, pass, model_desc, buyer, orderid, bc_type,
+       judge_stove_no,INSTOCK_TIME,INSERT_TIME)
+    values
+      (curoporder.bal_year_month, curoporder.ckmc, curoporder.material_no,
+       curoporder.material_name, curoporder.spec_code, curoporder.spec_name,
+       curoporder.std_code, curoporder.std_name, curoporder.produccode,
+       curoporder.producname, curoporder.gradecode, curoporder.gradename,
+       curoporder.steelcode, curoporder.steelname, curoporder.act_count,
+       curoporder.act_weight, curoporder.act_in_count,
+       curoporder.act_in_weight, curoporder.act_out_count,
+       curoporder.act_out_weight, curoporder.is_lljg,
+       curoporder.process_name, curoporder.is_ckc, curoporder.dimater,
+       curoporder.height, curoporder.pass, curoporder.model_desc,
+       curoporder.buyer, curoporder.orderid, '半成品期初库存',
+       curoporder.judge_stove_no,curOPOrder.INSTOCK_TIME,sysdate);
+  end loop;
+  close oporder_cursor;
+  commit;
+
+end mes_cx_ydm_bc_initial_hand;

+ 388 - 108
MES_FIN_MONTH/FinMES202602/mes_cx_rz_zxnew_hand.md

@@ -13,7 +13,7 @@
 ## 原始脚本内容
 
 ```sql
-CREATE OR REPLACE procedure MES_CX_RCL_zxNEW_HAND is
+CREATE OR REPLACE procedure MES_CX_RZ_ZXNEW_HAND is
   a                 number(4);
   b                 varchar(200);
   cxdata            orderdetail_v@th_cx_link%rowtype;
@@ -25,7 +25,258 @@ CREATE OR REPLACE procedure MES_CX_RCL_zxNEW_HAND is
   MATERIAL_NAME_cx  varchar(200);
   outer_diam_cx     varchar(200);
 
-  CURSOR OPOrder_Cursor_rcl IS
+  --热轧
+  CURSOR OPOrder_Cursor_rz IS
+
+  /*
+      select CONTRACT_TYPE,--合同类型
+      PROD_VARIETY,--品名、品种
+      STEEL_LEVEL,--钢级
+      STEEL_NO,--钢号
+      SPEC,--规格
+      PROD_TYPE,--产量类型
+      sum(PROD_WEIGHT) PROD_WEIGHT,--成品重量
+      sum(MATE_WEIGHT) MATE_WEIGHT,--来料重量
+      (case when sum(MATE_WEIGHT) <>0 then round(sum(PROD_WEIGHT)/sum(MATE_WEIGHT),4)*100  else 0 end) STEEL_WASTE,--消耗占比
+      '热轧' PROCESS,--工序
+      null HIGH_TECH_CODE,
+      null HIGH_TECH_NAME,
+      0 HIGH_PROD_WEIGHT,
+      0 HIGH_MATE_WEIGHT,
+      0 ESTIMATED_UNIT_PRICE,
+      0 ESTIMATED_COST,
+      substr(BAL_YEAR_MONTH,0,4)||'-'||substr(BAL_YEAR_MONTH,5,2)  ACCT_PERIOD,
+      MATE_CODE || xx MATE_CODE,--物料编码
+      RESOURCE_TYPE RESOURCE_TYPE,--是否来料加工
+      BILLET_CODE BILLET_CODE --钢坯编码
+       from (
+      select t.*,GET_CP_CODE2(STEEL_NO, --钢种
+                 STEEL_LEVEL, --钢级
+                 jhzt, --交货状态
+                 PROD_VARIETY, --品名
+                   MODEL_DESC, --端部
+                   jg,
+                 ACT_DIMATER, -- 外径
+                 ACT_HEIGHT) MATE_CODE,--壁厚
+                      GET_PL_CODE(STEEL_NO, --钢种
+                 (select xxx.dimater from cxuser.ydm_gp_outlist xxx where xxx.stove_no =
+                  ( select stove_no  from cxuser.PLN_ZY_ZG_M  where stove_no =  t.stove_no and ROWNUM =1) and ROWNUM =1)--规格
+                 ) BILLET_CODE
+                  from (
+
+      select t.judge_stove_no,
+             --T.JUGDE_APPLY_CODE,
+             t.lot_no,
+             t.pro_order_no,
+             t.ACT_DIMATER,
+             t.ACT_HEIGHT,
+             t.stove_no,--tzh
+             (case when t.Judge_Stove_No like 'W%' then '是' else '否' end) RESOURCE_TYPE,
+             (CASE
+               WHEN t.pro_order_no IS NULL THEN
+                (SELECT DECODE(MAX(S.ORDER_TYP),
+                               '120108',
+                               '双经销',
+                               '120109',
+                               '定销订购',
+                               '120107',
+                               '来料加工',
+                               '自用')
+                   FROM cxuser.SLM_ORDER_HEAD S
+                  WHERE S.ORDER_NO = REGEXP_REPLACE(T1.CONTRACT_NO, '/.*', ''))
+               ELSE
+                (SELECT DECODE(MAX(S.ORDER_TYP),
+                               '120108',
+                               '双经销',
+                               '120109',
+                               '定销订购',
+                               '120107',
+                               '来料加工',
+                               '自用')
+                   FROM cxuser.SLM_ORDER_HEAD S
+                  WHERE S.ORDER_NO = REGEXP_REPLACE(T.PRO_ORDER_NO, '/.*', ''))
+             END) CONTRACT_TYPE,--合同类型 --是否双经销,
+
+             (SELECT (case when INSTR(a.whole_backlog,'D-F-G')>0 then 'C'
+             when INSTR(a.whole_backlog,'D-G')>0 then 'C'
+      when INSTR(a.whole_backlog,'D-F')>0 then 'B'
+      ELSE 'A' END ) XX FROM cxuser.CRAFT_ORD_DESIGN_MSC_PL A WHERE A.ORD_LN_PK =
+      (select ORD_LN_PK from  cxuser.slm_order_line b where b.ord_pk =
+      (select ord_pk from cxuser.slm_order_head xx
+      where xx.order_no = REGEXP_REPLACE(T.PRO_ORDER_NO, '/.*', '') and rownum =1 and xx.validflag =1)
+      and b.order_seq= SUBSTR(T.PRO_ORDER_NO, LENGTH(T.PRO_ORDER_NO)-2) and b.validflag =1
+      ) and rownum =1) xx, --下线状态
+
+             t.pline_code,
+             t.pline_name,
+             t.producname PROD_VARIETY,--品名、品种
+             t.steelname STEEL_LEVEL,--钢级
+             t.GRADENAME STEEL_NO,--钢号
+             t.spec_name SPEC,--规格
+             t.model_desc,
+             t.std_name,
+             T.STD_STYLE_DESC 标准类别,
+             (case when T.TARGET ='A' THEN '产成品' else '半成品' end) PROD_TYPE,--产量类型
+             MAX(T2.MEMO) MEMO,
+             MAX(t1.target) 原去向,
+             MAX(T1.DB_LENGTH) 单倍长,
+             MAX(T1.SAW_NUM) 分切数,
+             MAX(T1.PIPE_SECTION) 断面,
+             MAX(T1.TUBE_TYPE) 管坯类型,
+             MAX(T1.TUBE_SUORCE) 管坯来源,
+             MAX(T1.FEED_TIME) FEED_TIME,
+
+
+             TO_CHAR(DECODE(T.TARGET,
+                            'A',
+                            MAX(T.JUDGE_TOLRESULT_TIME),
+                            MAX(t.JUDGE_RESULT_TIME)),
+                     'YYYY-MM-DD') JUDGE_RESULT_TIME,
+             SUM(DECODE(t.ACT_WEIGHT, NULL, t.ACT_THEORY_WEIGHT, t.ACT_WEIGHT)) PROD_WEIGHT,--成品重量--HGD,
+             SUM(T.ACT_COUNT) 合格支,
+             sum(t.INPUT_WEIGHT) INPUT_WEIGHT,
+             sum(t.OUTPUT_WEIGHT) MATE_WEIGHT, --来料重量--OUTPUT_WEIGHT
+             T.BAL_YEAR_MONTH,
+             GET_DELIVERY_STATE2((select max(y.desgin_key) from cxuser.craft_ord_design_msc_pl y
+                   where y.desgin_key in (select x.desgin_key from cxuser.craft_ord_design_msc x where x.ord_ln_pk in (select b.ord_ln_pk from cxuser.slm_order_line b
+                  where b.ord_pk in (select a.ord_pk from cxuser.slm_order_head a where a.order_no = substr(t.pro_order_no,1,instr(t.pro_order_no,'/')-1))
+                   and x.order_seq = substr(t.pro_order_no,instr(t.pro_order_no,'/')+1,3)))),
+                   (select max(y.msc_pline) from cxuser.craft_ord_design_msc_pl y
+                   where y.desgin_key in (select x.desgin_key from cxuser.craft_ord_design_msc x where x.ord_ln_pk in (select b.ord_ln_pk from cxuser.slm_order_line b
+                  where b.ord_pk in (select a.ord_pk from cxuser.slm_order_head a where a.order_no = substr(t.pro_order_no,1,instr(t.pro_order_no,'/')-1))
+                   and x.order_seq = substr(t.pro_order_no,instr(t.pro_order_no,'/')+1,3))))) jhzt,
+
+                    (select max(y.value_text) from cxuser.craft_ord_design_std_gic y
+                   where y.desgin_key in (select x.desgin_key from cxuser.craft_ord_design_msc x where x.ord_ln_pk in (select b.ord_ln_pk from cxuser.slm_order_line b
+                  where b.ord_pk in (select a.ord_pk from cxuser.slm_order_head a where a.order_no = substr(t.pro_order_no,1,instr(t.pro_order_no,'/')-1))
+                   and x.order_seq = substr(t.pro_order_no,instr(t.pro_order_no,'/')+1,3))) AND SPECL_FL = '2') jg
+
+        from cxuser.QCM_ZG_JUGDE_APPLY t
+        LEFT JOIN cxuser.MIL_PLAN T1
+          ON T.JUDGE_STOVE_NO = REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')
+         AND T1.BACK_SLAB_FLAG <> '2'
+         AND SUBSTR(T1.JUDGE_STOVE_NO, -2) = '01'
+         LEFT JOIN cxuser.PLN_ZY_ZG_M T2
+         ON T2.HEAT_PLAN_NO = T.HEAT_PLAN_NO
+       where T.IS_FLAG = '0'
+         AND T.IS_ALL_SCRAP IN ('0', '1', '2', '7', '8')
+         AND ((T.VALIDFLAG = '20' AND T.TARGET <> 'A' AND
+             T.JUDGE_RESULT_CODE IN ('40740701', '40740705', '40740709')) OR
+             (T.VALIDFLAG = '20' AND T.TARGET = 'A' AND
+             T.JUDGE_TOLRESULT_CODE IN ('40740701', '40740705', '40740709')) OR
+             (T.VALIDFLAG = '20' AND T.TARGET = 'A' AND T.IS_ALL_SCRAP = '1') OR
+             T.INSTANCY_FLAG = '1')
+         AND T.PROCESS_CODE = 'D'
+          and t.JUDGE_TOLRESULT_CODE <> '40740705' --tzh
+          --AND T.BAL_YEAR_MONTH =  to_char(sysdate,'yyyymm')
+              -- AND substr(T.BAL_YEAR_MONTH,0,4) ='2024'
+         AND T.BAL_YEAR_MONTH = '202411'
+         AND T.PLINE_CODE = 'C072'
+       group by t.judge_stove_no,
+                T1.JUDGE_STOVE_NO,
+                T1.PRO_PLAN_ID,
+                t.lot_no,
+                t.pro_order_no,
+                T1.CONTRACT_NO,
+                t.pline_code,
+                t.pline_name,
+                t.producname,
+                t.steelname,
+                t.GRADENAME,
+                t.spec_name,
+                T.STD_STYLE_DESC,
+                t.model_desc,
+                T.TARGET,
+                t.std_name,
+                T.BAL_YEAR_MONTH,
+                  t.ACT_DIMATER,
+                  t.stove_no,--tzh
+             t.ACT_HEIGHT
+       order by T.PLINE_CODE, t.judge_stove_no
+       ) t
+       )
+      group by
+      CONTRACT_TYPE,--合同类型
+      PROD_VARIETY,--品名、品种
+      STEEL_LEVEL,--钢级
+      STEEL_NO,--钢号
+      SPEC,--规格
+      PROD_TYPE,--产量类型
+      BAL_YEAR_MONTH,
+      MATE_CODE,
+      BILLET_CODE,
+      RESOURCE_TYPE,
+      xx;*/
+  /*
+      select  (SELECT DECODE(MAX(S.ORDER_TYP),
+                            '120108',
+                            '双经销',
+                            '120109',
+                            '定销订购',
+                            '120107',
+                            '来料加工',
+                            '自用')
+                FROM cxuser.SLM_ORDER_HEAD S
+               WHERE S.ORDER_NO = REGEXP_REPLACE(T.PRO_ORDER_NO, '/.*', '')) CONTRACT_TYPE,--合同类型
+      t.producname PROD_VARIETY,--品名、品种
+       t.steelname STEEL_LEVEL,--钢级
+      t.GRADENAME STEEL_NO,--钢号
+      t.spec_name SPEC,--规格
+      (case when T.TARGET ='A' THEN '产成品' else '半成品' end) PROD_TYPE,--产量类型
+       SUM(DECODE(t.ACT_WEIGHT, NULL, t.ACT_THEORY_WEIGHT, t.ACT_WEIGHT)) PROD_WEIGHT,--成品重量
+      SUM(INPUT_WEIGHT) MATE_WEIGHT,--来料重量
+      (case when sum(INPUT_WEIGHT) <>0 then round(SUM(DECODE(t.ACT_WEIGHT, NULL, t.ACT_THEORY_WEIGHT, t.ACT_WEIGHT))/SUM(INPUT_WEIGHT),4)*100  else 0 end) STEEL_WASTE,--消耗占比
+      '热轧' PROCESS,--工序
+      null HIGH_TECH_CODE,
+      null HIGH_TECH_NAME,
+      0 HIGH_PROD_WEIGHT,
+      0 HIGH_MATE_WEIGHT,
+      0 ESTIMATED_UNIT_PRICE,
+      0 ESTIMATED_COST,
+       substr(BAL_YEAR_MONTH,0,4)||'-'||substr(BAL_YEAR_MONTH,5,2) ACCT_PERIOD,
+        --GET_CP_CODE4(t.pro_order_no) MATE_CODE,--物料编码
+       --换成取产销提供的视图 tzh 24.12.4
+       GET_CP_CODE6(t.pro_order_no) MATE_CODE,--物料编码
+      (case when t.Judge_Stove_No like 'W%' then '是' else '否' end)  RESOURCE_TYPE,--是否来料加工
+      --GET_PL_CODE(GRADENAME,ACT_dimater)  BILLET_CODE --钢坯编码,
+      GET_PL_CODE(GRADENAME,(select xxx.dimater from cxuser.ydm_gp_outlist xxx where xxx.stove_no =t.stove_no and ROWNUM =1)--规格
+                  ) BILLET_CODE --,stove_no,t.pro_order_no--钢坯编码,
+
+      from
+        cxuser.QCM_ZG_JUGDE_APPLY t
+         LEFT JOIN MIL_PLAN T1
+          ON T.JUDGE_STOVE_NO = REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')
+         AND T1.BACK_SLAB_FLAG <> '2'
+         AND SUBSTR(T1.JUDGE_STOVE_NO, -2) = '01'
+         LEFT JOIN PLN_ZY_ZG_M T2
+         ON T2.HEAT_PLAN_NO = T.HEAT_PLAN_NO
+       where T.IS_FLAG = '0'
+         AND T.IS_ALL_SCRAP IN ('0', '1', '2', '7', '8')
+         AND ((T.VALIDFLAG = '20' AND T.TARGET <> 'A' AND
+             T.JUDGE_RESULT_CODE IN ('40740701', '40740705', '40740709')) OR
+             (T.VALIDFLAG = '20' AND T.TARGET = 'A' AND
+             T.JUDGE_TOLRESULT_CODE IN ('40740701', '40740705', '40740709')) OR
+             (T.VALIDFLAG = '20' AND T.TARGET = 'A' AND T.IS_ALL_SCRAP = '1') OR
+             T.INSTANCY_FLAG = '1')
+         AND T.PROCESS_CODE = 'D'
+         AND T.PLINE_CODE = 'C072'
+         AND (T.TARGET = t1.target OR T.JUDGE_STOVE_NO <> 'F24070002' OR T.JUDGE_STOVE_NO <> 'F24070006')
+       \*where T.IS_FLAG = '0'
+         AND T.IS_ALL_SCRAP IN ('0', '1', '2', '7', '8')
+         AND ((T.VALIDFLAG = '20' AND T.TARGET <> 'A' AND
+             T.JUDGE_RESULT_CODE IN ('40740701', '40740705', '40740709')) OR
+             (T.VALIDFLAG = '20' AND T.TARGET = 'A' AND
+             T.JUDGE_TOLRESULT_CODE IN ('40740701', '40740705', '40740709')) OR
+             (T.VALIDFLAG = '20' AND T.TARGET = 'A' AND T.IS_ALL_SCRAP = '1') OR
+             T.INSTANCY_FLAG = '1')
+         AND T.PROCESS_CODE = 'D'
+         AND T.PLINE_CODE = 'C072'*\
+           AND T.BAL_YEAR_MONTH = '202411'
+                  group  by t.producname,t.steelname,--钢级
+      t.GRADENAME,--钢号
+      stove_no,
+      t.spec_name,--规格
+       T.TARGET,T.BAL_YEAR_MONTH,pro_order_no,T.Judge_Stove_No;*/
 
     select (select decode(max(s.order_typ),
                           '120108',
@@ -39,7 +290,8 @@ CREATE OR REPLACE procedure MES_CX_RCL_zxNEW_HAND is
              where s.order_no = regexp_replace(t.pro_order_no, '/.*', '')) contract_type,
            --合同类型
            t.producname prod_variety,
-           replace(t.PRO_ORDER_NO, '/', '') orderid,
+           nvl(replace(PRO_ORDER_NO, '/', ''),
+               replace(get_cp_order(t.judge_stove_no), '/', '')) orderid,
            --品名、品种
            t.steelname steel_level,
            --钢级
@@ -59,7 +311,7 @@ CREATE OR REPLACE procedure MES_CX_RCL_zxNEW_HAND is
               (sum(decode(t.act_weight,
                           null,
                           t.act_theory_weight,
-                          t.act_weight)) -
+                          t.act_weight)) +
               nvl((select SUM(nvl(T2.act_weight, 0))
                      from ydm_zc_stocktakinglist t2
                     where t2.judge_stove_no = t.judge_stove_no
@@ -78,12 +330,8 @@ CREATE OR REPLACE procedure MES_CX_RCL_zxNEW_HAND is
                 where t2.judge_stove_no = t.judge_stove_no
                   and t2.STOCKTAKING_TYPE_CODE = '800603'
                   and t2.BAL_YEAR_MONTH = '202602'),
-               0) LC_WEIGHT,
-           --量差
-           sum(decode(t.act_theory_weight,
-                      null,
-                      t.act_weight,
-                      t.act_theory_weight)) mate_weight,
+               0) lc_weight, --量差
+           sum(output_weight) mate_weight,
            --来料重量
            (case
              when sum(input_weight) <> 0 then
@@ -96,7 +344,7 @@ CREATE OR REPLACE procedure MES_CX_RCL_zxNEW_HAND is
               0
            end) steel_waste,
            --消耗占比
-           '热处理' process,
+           '热' process,
            --工序
            null high_tech_code,
            null high_tech_name,
@@ -104,8 +352,8 @@ CREATE OR REPLACE procedure MES_CX_RCL_zxNEW_HAND is
            0 high_mate_weight,
            0 estimated_unit_price,
            0 estimated_cost,
-           substr(bal_year_month, 0, 4) || '-' ||
-           substr(bal_year_month, 5, 2) acct_period,
+           substr(t.bal_year_month, 0, 4) || '-' ||
+           substr(t.bal_year_month, 5, 2) acct_period,
            --GET_CP_CODE4(t.pro_order_no) MATE_CODE,--物料编码
            --换成取产销提供的视图 tzh 24.12.4
            get_cp_code6(t.pro_order_no) mate_code,
@@ -113,101 +361,135 @@ CREATE OR REPLACE procedure MES_CX_RCL_zxNEW_HAND is
            getislljg(t.judge_stove_no, replace(t.PRO_ORDER_NO, '/', '')) resource_type,
            t.judge_stove_no,
            --是否来料加工
-           null billet_code --钢坯编码,
+           --GET_PL_CODE(GRADENAME,ACT_dimater)  BILLET_CODE --钢坯编码,
+           get_pl_code(t.gradename,
+                       (select xxx.dimater
+                          from cxuser.ydm_gp_outlist xxx
+                         where xxx.stove_no = CASE
+                                 WHEN t.stove_no IS NOT NULL THEN
+                                  t.stove_no
+                                 ELSE
+                                  get_max_stove_no(t.judge_stove_no)
+                               END
+                           and rownum = 1) --规格
+                       ) billet_code --,stove_no,t.pro_order_no--钢坯编码,
 
       from cxuser.qcm_zg_jugde_apply t
+      left join mil_plan t1
+        on t.judge_stove_no = regexp_replace(t1.judge_stove_no, '-.*', '')
+       and t1.back_slab_flag <> '2'
+       and substr(t1.judge_stove_no, -2) = '01'
+      left join pln_zy_zg_m t2
+        on t2.heat_plan_no = t.heat_plan_no
      where t.is_flag = '0'
-       and t.is_all_scrap in ('0', '2')
+       and t.is_all_scrap in ('0', '1', '2', '7', '8')
        and ((t.validflag = '20' and t.target <> 'A' and
-           t.judge_result_code in ('40740701', '40740705', '40740709')) or
+           t.judge_result_code in ('40740701', '40740709')) or
            (t.validflag = '20' and t.target = 'A' and
-           t.judge_tolresult_code in ('40740701', '40740705', '40740709')) or
+           t.judge_tolresult_code in ('40740701', '40740709')) or
+           (t.validflag = '20' and t.target = 'A' and t.is_all_scrap = '1') or
            t.instancy_flag = '1')
-       and t.process_code = 'F'
+       and t.process_code = 'D'
+          -- AND T.PLINE_CODE = 'C072'
+       and t.target = t1.target
+          /*where T.IS_FLAG = '0'
+          AND T.IS_ALL_SCRAP IN ('0', '1', '2', '7', '8')
+          AND ((T.VALIDFLAG = '20' AND T.TARGET <> 'A' AND
+              T.JUDGE_RESULT_CODE IN ('40740701', '40740705', '40740709')) OR
+              (T.VALIDFLAG = '20' AND T.TARGET = 'A' AND
+              T.JUDGE_TOLRESULT_CODE IN ('40740701', '40740705', '40740709')) OR
+              (T.VALIDFLAG = '20' AND T.TARGET = 'A' AND T.IS_ALL_SCRAP = '1') OR
+              T.INSTANCY_FLAG = '1')
+          AND T.PROCESS_CODE = 'D'
+          AND T.PLINE_CODE = 'C072'*/
        and t.bal_year_month in ('202602')
-          --AND T.BAL_YEAR_MONTH =  to_char(sysdate,'yyyymm')
-       AND t.PRO_ORDER_NO NOT LIKE 'ZZBY%'
-    --AND T.judge_stove_no in ('A25060356','F25070004')
-    --  and t.pline_code in ('C091','C105')
+       --and t.judge_stove_no in( 'A25030144','C26020468','C26020470','C26020471')
+       and nvl(replace(PRO_ORDER_NO, '/', ''),
+               replace(get_cp_order(t.judge_stove_no), '/', '')) not like
+           'ZZBY%'
+    --AND t.judge_stove_no not LIKE 'F%'
+    --AND t.judge_stove_no in('X25080001','X25080002','X25080003','X25080004','X25080005')
+
      group by t.producname,
               t.steelname,
               --钢级
               t.gradename,
               --钢号
+              t.stove_no,
               t.spec_name,
               --规格
               t.target,
-              bal_year_month,
+              t.bal_year_month,
               pro_order_no,
-              judge_stove_no;
-
-  curoporder_rcl oporder_cursor_rcl%rowtype;
+              t.judge_stove_no;
 
+  curoporder_jg oporder_cursor_rz%rowtype;
+  cnt           number;
 begin
-
-  open oporder_cursor_rcl;
+  cnt := 0;
+  open oporder_cursor_rz;
   loop
-    fetch oporder_cursor_rcl
-      into curoporder_rcl;
-    exit when oporder_cursor_rcl%notfound;
+    fetch oporder_cursor_rz
+      into curoporder_jg;
+    exit when oporder_cursor_rz%notfound;
+
     select count(*)
       into a
       from orderdetail_v@th_cx_link t
-     where t.contractno_num = curoporder_rcl.orderid
+     where t.contractno_num = curoporder_jg.orderid
        and material_code is not null;
 
     if a > 0 then
-      select prod_name,
+      select outer_diam,
+             prod_name,
              sg_grade,
              sg_sign,
-             outer_diam,
              wall_thickness,
              material_code,
              MATERIAL_NAME
-        into prod_name_cx,
+        into outer_diam_cx,
+             prod_name_cx,
              sg_grade_cx,
              sg_sign_cx,
-             outer_diam_cx,
              wall_thickness_cx,
              material_code_cx,
              MATERIAL_NAME_cx
         from orderdetail_v@th_cx_link t
-       where t.contractno_num = curoporder_rcl.orderid
+       where t.contractno_num = curoporder_jg.orderid
          and material_code is not null
          and rownum = 1;
 
-    elsif substr(curoporder_rcl.orderid, 1, 2) in ('TH', 'XS') then
+    elsif substr(curoporder_jg.orderid, 1, 2) in ('TH', 'XS') then
       select count(*)
         into a
         from orderdetail_v@th_cx_link t
-       where substr(t.contractno_num, 3) =
-             substr(curoporder_rcl.orderid, 3)
+       where substr(t.contractno_num, 3) = substr(curoporder_jg.orderid, 3)
          and material_code is not null
          and rownum = 1;
       if a > 0 then
-        select prod_name,
+        select outer_diam,
+               prod_name,
                sg_grade,
                sg_sign,
-               outer_diam,
                wall_thickness,
                material_code,
                MATERIAL_NAME
-          into prod_name_cx,
+          into outer_diam_cx,
+               prod_name_cx,
                sg_grade_cx,
                sg_sign_cx,
-               outer_diam_cx,
                wall_thickness_cx,
                material_code_cx,
                MATERIAL_NAME_cx
           from orderdetail_v@th_cx_link t
          where substr(t.contractno_num, 3) =
-               substr(curoporder_rcl.orderid, 3)
+               substr(curoporder_jg.orderid, 3)
            and material_code is not null
            and rownum = 1;
       end if;
     end if;
     if a > 0 then
-      insert into hot_heat_production_mes_gx
+      insert into hot_production_mes_rz
         (cx_no,
          contract_type,
          prod_variety,
@@ -231,60 +513,58 @@ begin
          billet_code,
          memo,
          flag,
+         go_there,
          mate_name,
          orderid,
-         GO_THERE,
          judge_stove_no,
          PRE_PROCESS,
          DELIVERY_STATUS,
          INSERT_TIME,
-         LC_WEIGHT)
+         lc_weight)
       values
         (seq_mes_cx.nextval,
-         curoporder_rcl.contract_type,
+         curoporder_jg.contract_type,
          prod_name_cx,
          sg_sign_cx,
          sg_grade_cx,
          outer_diam_cx || '*' || wall_thickness_cx,
-         curoporder_rcl.prod_type,
-         curoporder_rcl.prod_weight,
-         curoporder_rcl.mate_weight,
-         curoporder_rcl.steel_waste,
-         curoporder_rcl.process,
-         curoporder_rcl.high_tech_code,
-         curoporder_rcl.high_tech_name,
-         curoporder_rcl.high_prod_weight,
-         curoporder_rcl.high_mate_weight,
-         curoporder_rcl.estimated_unit_price,
-         curoporder_rcl.estimated_cost,
-         curoporder_rcl.acct_period,
+         curoporder_jg.prod_type,
+         curoporder_jg.prod_weight,
+         curoporder_jg.mate_weight,
+         curoporder_jg.steel_waste,
+         curoporder_jg.process,
+         curoporder_jg.high_tech_code,
+         curoporder_jg.high_tech_name,
+         curoporder_jg.high_prod_weight,
+         curoporder_jg.high_mate_weight,
+         curoporder_jg.estimated_unit_price,
+         curoporder_jg.estimated_cost,
+         curoporder_jg.acct_period,
          material_code_cx,
-         curoporder_rcl.resource_type,
-         --curOPOrder_rcl.BILLET_CODE,
-         curoporder_rcl.mate_code || '1',
-
+         curoporder_jg.resource_type,
+         curoporder_jg.billet_code,
          '',
          '0',
-         MATERIAL_NAME_cx,
-         curoporder_rcl.orderid,
          (case
-           when material_code_cx like '%B' then
+           when curoporder_jg.mate_code like '%B' then
             '加工'
-           when material_code_cx like '%C' then
+           when curoporder_jg.mate_code like '%C' then
             '热处理'
            else
             ''
          end),
-         curoporder_rcl.judge_stove_no,
-         '热轧',
+         MATERIAL_NAME_cx,
+         curoporder_jg.orderid,
+         curoporder_jg.judge_stove_no,
+         null,
          SUBSTR(MATERIAL_NAME_cx,
                 INSTR(MATERIAL_NAME_cx, ',', 1, 1) + 1,
                 INSTR(MATERIAL_NAME_cx, ',', 1, 2) -
                 INSTR(MATERIAL_NAME_cx, ',', 1, 1) - 1),
          sysdate,
-         curoporder_rcl.Lc_Weight);
+         curoporder_jg.lc_weight);
     else
-      insert into hot_heat_production_mes_gx
+      insert into hot_production_mes_rz
         (cx_no,
          contract_type,
          prod_variety,
@@ -308,52 +588,52 @@ begin
          billet_code,
          memo,
          flag,
+         go_there,
          mate_name,
          orderid,
-         GO_THERE,
          judge_stove_no,
          lc_weight)
       values
         (seq_mes_cx.nextval,
-         curoporder_rcl.contract_type,
-         curoporder_rcl.prod_variety,
-         curoporder_rcl.steel_level,
-         curoporder_rcl.steel_no,
-         curoporder_rcl.spec,
-         curoporder_rcl.prod_type,
-         curoporder_rcl.prod_weight,
-         curoporder_rcl.mate_weight,
-         curoporder_rcl.steel_waste,
-         curoporder_rcl.process,
-         curoporder_rcl.high_tech_code,
-         curoporder_rcl.high_tech_name,
-         curoporder_rcl.high_prod_weight,
-         curoporder_rcl.high_mate_weight,
-         curoporder_rcl.estimated_unit_price,
-         curoporder_rcl.estimated_cost,
-         curoporder_rcl.acct_period,
-         curoporder_rcl.mate_code,
-         curoporder_rcl.resource_type,
-         --curOPOrder_rcl.BILLET_CODE,
-         curoporder_rcl.mate_code || '1',
-
+         curoporder_jg.contract_type,
+         curoporder_jg.prod_variety,
+         curoporder_jg.steel_level,
+         curoporder_jg.steel_no,
+         curoporder_jg.spec,
+         curoporder_jg.prod_type,
+         curoporder_jg.prod_weight,
+         curoporder_jg.mate_weight,
+         curoporder_jg.steel_waste,
+         curoporder_jg.process,
+         curoporder_jg.high_tech_code,
+         curoporder_jg.high_tech_name,
+         curoporder_jg.high_prod_weight,
+         curoporder_jg.high_mate_weight,
+         curoporder_jg.estimated_unit_price,
+         curoporder_jg.estimated_cost,
+         curoporder_jg.acct_period,
+         curoporder_jg.mate_code,
+         curoporder_jg.resource_type,
+         curoporder_jg.billet_code,
          '',
          '0',
+         (case when curoporder_jg.mate_code like '%B' then '加工' when
+          curoporder_jg.mate_code like '%C' then '热处理' else '' end),
          null,
-         curoporder_rcl.orderid,
-         (case when cxdata.material_code like '%B' then '加工' when
-          cxdata.material_code like '%C' then '热处理' else '' end),
-         curoporder_rcl.judge_stove_no,
-         curoporder_rcl.lc_weight);
+         curoporder_jg.orderid,
+         curoporder_jg.judge_stove_no,
+         curoporder_jg.lc_weight);
+    end if;
+    cnt := cnt + 1;
+    if cnt = 6 then
+      cnt := 100;
     end if;
   end loop;
-  close oporder_cursor_rcl;
+  close oporder_cursor_rz;
   commit;
 
-  /*
-
-  exception
-    when others then
-      null;*/
-end mes_cx_rcl_zxnew_HAND;
+exception
+  when others then
+    DBMS_OUTPUT.PUT_LINE('错误:  ' || cnt || '条' || SQLERRM);
+end mes_cx_rz_zxnew_HAND;
 ```

+ 214 - 0
MES_FIN_MONTH/FinMES202602/mes_cx_ydm_bc_inlist_csjg_hand.md

@@ -0,0 +1,214 @@
+# mes_cx_rz_zxnew_hand 存储过程(什么什么热轧)
+
+## 模板下载
+
+[模板](./mes_cx_ydm_bc_inlist_csjg_hand.sql)
+
+用{0}表达 当前月份 替换成02
+
+用{1}表达 下个月份 替换成03
+
+用{2}表达 下个月份 替换成01
+
+## 原始脚本内容
+
+```sql
+CREATE OR REPLACE procedure mes_cx_ydm_bc_inlist_CSJG_hand is
+  a                 number(4);
+  b                 varchar(200);
+  cxdata            orderdetail_v@th_cx_link%rowtype;
+  prod_name_cx      varchar(200);
+  prod_code_cx      varchar(200);
+  sg_grade_cx       varchar(200);
+  sg_gradename_cx   varchar(200);
+  sg_sign_cx        varchar(200);
+  sg_signname_cx    varchar(200);
+  wall_thickness_cx varchar(200);
+  material_code_cx  varchar(200);
+  material_name_cx  varchar(200);
+
+  cursor oporder_cursor is
+
+    select substr(t1.bal_year_month, 0, 4) || '-' ||
+            substr(t1.bal_year_month, 5, 2) bal_year_month,
+           --记账日期
+           '天淮中间库' ckmc, t1.judge_stove_no,
+           --库存地名称,
+           spec_code,
+           --产品规格代码,
+           spec_name,
+           -- 产品规格描述,
+           max(std_code) std_code,
+           --执行标准代码,
+           max(std_name) std_name,
+           --执行标准名称,
+           produccode,
+           --品名代码,
+           producname,
+           --品名描述,
+           gradecode,
+           --钢种代码,
+           gradename,
+           --钢种名称,
+           steelcode,
+           --钢级代码,
+           steelname,
+           --钢级名称,
+           0 act_count,
+           --期初库存支数,
+           0 act_weight,
+           --期初库存重量,
+           sum(act_count) act_in_count,
+           --本期入库支数,
+           sum(act_weight) act_in_weight,
+           --本期入库重量,
+           0 act_out_count,
+           --本期出库支数,
+           0 act_out_weight,
+           --本期出库重量,
+           max(t1.instock_time) instock_time,
+           getislljg(t1.judge_stove_no,
+                      nvl(replace(pro_order_no, '/', ''),
+                          replace(get_cp_order(t1.judge_stove_no), '/', ''))) is_lljg,
+           --是否来料加工,
+           '加工' process_name,
+           --工序,
+           '否' is_ckc,
+           --是否出口材
+           act_dimater dimater,
+           --外径
+           act_height height,
+           --壁厚
+           nvl(replace(pro_order_no, '/', ''),
+                replace(get_cp_order(t1.judge_stove_no), '/', '')) orderid,
+           --合同号
+           model_desc,
+           -- 扣型描述
+           get_cp_buyer(get_cp_order(t1.judge_stove_no)) buyer,
+           --客户名称
+           get_cp_pass(get_cp_order(t1.judge_stove_no)) pass --孔型
+      from ydm_zc_inlist t1
+     where instock_type_code in ('800701', '800702', '800706')--产出盘盈改判
+        and BAL_YEAR_MONTH = '202602'
+       and belong_code in ('100101', '100102', '100105')
+       and supply_unit_code = '120504'
+       and nvl(replace(pro_order_no, '/', ''),
+               replace(get_cp_order(t1.judge_stove_no), '/', '')) not like
+           'ZZBY%'
+       AND T1.PLINE_CODE = 'C108'
+     group by bal_year_month, spec_code,
+              --产品规格代码,
+              produccode,
+              --品名代码,
+              producname, gradecode,
+              --钢种代码,
+              gradename, steelcode,
+              --钢级代码,
+              steelname, judge_stove_no, process_desc, act_dimater,
+              --外径
+              act_height,
+              --壁厚
+              model_desc, t1.pro_order_no, t1.order_no, t1.order_seq,
+              spec_code, spec_name;
+
+  curoporder oporder_cursor%rowtype;
+
+begin
+
+  open oporder_cursor;
+  loop
+    fetch oporder_cursor
+      into curoporder;
+    exit when oporder_cursor%notfound;
+
+    select count(*)
+      into a
+      from orderdetail_v@th_cx_link t
+     where t.contractno_num = curoporder.orderid
+       and material_code is not null;
+
+    if a > 0 then
+      select prod_code, prod_name, sg_grade_code, sg_grade, sg_sign_code,
+             sg_sign, wall_thickness, material_code, material_name
+        into prod_code_cx, prod_name_cx, sg_grade_cx, sg_gradename_cx,
+             sg_sign_cx, sg_signname_cx, wall_thickness_cx, material_code_cx,
+             material_name_cx
+        from orderdetail_v@th_cx_link t
+       where t.contractno_num = curoporder.orderid
+         and material_code is not null
+         and rownum = 1;
+
+    elsif substr(curoporder.orderid, 1, 2) in ('TH', 'XS') then
+      select count(*)
+        into a
+        from orderdetail_v@th_cx_link t
+       where substr(t.contractno_num, 3) = substr(curoporder.orderid, 3)
+         and material_code is not null
+         and rownum = 1;
+      if a > 0 then
+        select prod_code, prod_name, sg_grade_code, sg_grade, sg_sign_code,
+               sg_sign, wall_thickness, material_code, material_name
+          into prod_code_cx, prod_name_cx, sg_grade_cx, sg_gradename_cx,
+               sg_sign_cx, sg_signname_cx, wall_thickness_cx,
+               material_code_cx, material_name_cx
+          from orderdetail_v@th_cx_link t
+         where substr(t.contractno_num, 3) = substr(curoporder.orderid, 3)
+           and material_code is not null
+           and rownum = 1;
+      end if;
+    end if;
+
+    if a > 0 then
+      insert into cx_ydm_bc_inlist
+        (bal_year_month, ckmc, material_no, material_name, spec_code,
+         spec_name, std_code, std_name, produccode, producname, gradecode,
+         gradename, steelcode, steelname, act_count, act_weight,
+         act_in_count, act_in_weight, act_out_count, act_out_weight, is_lljg,
+         process_name, is_ckc, dimater, height, pass, model_desc, buyer,
+         orderid, bc_type, judge_stove_no, instock_time,INSERT_TIME)
+      values
+        (curoporder.bal_year_month, curoporder.ckmc, material_code_cx,
+         material_name_cx, curoporder.spec_code,
+         sg_sign_cx || '*' || wall_thickness_cx, curoporder.std_code,
+         curoporder.std_name, prod_code_cx, prod_name_cx, sg_grade_cx,
+         sg_gradename_cx, sg_sign_cx, sg_signname_cx, curoporder.act_count,
+         curoporder.act_weight, curoporder.act_in_count,
+         curoporder.act_in_weight, curoporder.act_out_count,
+         curoporder.act_out_weight, curoporder.is_lljg,
+         curoporder.process_name, curoporder.is_ckc, curoporder.dimater,
+         curoporder.height, curoporder.pass, curoporder.model_desc,
+         curoporder.buyer, curoporder.orderid, '半成品入库',
+         curoporder.judge_stove_no, curoporder.instock_time,sysdate);
+
+    else
+      insert into cx_ydm_bc_inlist
+        (bal_year_month, ckmc, material_no, material_name, spec_code,
+         spec_name, std_code, std_name, produccode, producname, gradecode,
+         gradename, steelcode, steelname, act_count, act_weight,
+         act_in_count, act_in_weight, act_out_count, act_out_weight, is_lljg,
+         process_name, is_ckc, dimater, height, pass, model_desc, buyer,
+         orderid, bc_type, judge_stove_no, instock_time)
+      values
+        (curoporder.bal_year_month, curoporder.ckmc, null, null,
+         curoporder.spec_code, null, curoporder.std_code,
+         curoporder.std_name, null, null, null, null, null, null,
+         curoporder.act_count, curoporder.act_weight,
+         curoporder.act_in_count, curoporder.act_in_weight,
+         curoporder.act_out_count, curoporder.act_out_weight,
+         curoporder.is_lljg, curoporder.process_name, curoporder.is_ckc,
+         curoporder.dimater, curoporder.height, curoporder.pass,
+         curoporder.model_desc, curoporder.buyer, curoporder.orderid,
+         '半成品入库', curoporder.judge_stove_no, curoporder.instock_time);
+    end if;
+
+  end loop;
+  close oporder_cursor;
+  commit;
+
+  /*
+
+  exception
+    when others then
+      null;*/
+end mes_cx_ydm_bc_inlist_CSJG_hand;
+```

+ 198 - 0
MES_FIN_MONTH/FinMES202602/mes_cx_ydm_bc_inlist_csjg_hand.sql

@@ -0,0 +1,198 @@
+CREATE OR REPLACE procedure mes_cx_ydm_bc_inlist_CSJG_hand is
+  a                 number(4);
+  b                 varchar(200);
+  cxdata            orderdetail_v@th_cx_link%rowtype;
+  prod_name_cx      varchar(200);
+  prod_code_cx      varchar(200);
+  sg_grade_cx       varchar(200);
+  sg_gradename_cx   varchar(200);
+  sg_sign_cx        varchar(200);
+  sg_signname_cx    varchar(200);
+  wall_thickness_cx varchar(200);
+  material_code_cx  varchar(200);
+  material_name_cx  varchar(200);
+
+  cursor oporder_cursor is
+
+    select substr(t1.bal_year_month, 0, 4) || '-' ||
+            substr(t1.bal_year_month, 5, 2) bal_year_month,
+           --记账日期
+           '天淮中间库' ckmc, t1.judge_stove_no,
+           --库存地名称,
+           spec_code,
+           --产品规格代码,
+           spec_name,
+           -- 产品规格描述,
+           max(std_code) std_code,
+           --执行标准代码,
+           max(std_name) std_name,
+           --执行标准名称,
+           produccode,
+           --品名代码,
+           producname,
+           --品名描述,
+           gradecode,
+           --钢种代码,
+           gradename,
+           --钢种名称,
+           steelcode,
+           --钢级代码,
+           steelname,
+           --钢级名称,
+           0 act_count,
+           --期初库存支数,
+           0 act_weight,
+           --期初库存重量,
+           sum(act_count) act_in_count,
+           --本期入库支数,
+           sum(act_weight) act_in_weight,
+           --本期入库重量,
+           0 act_out_count,
+           --本期出库支数,
+           0 act_out_weight,
+           --本期出库重量,
+           max(t1.instock_time) instock_time,
+           getislljg(t1.judge_stove_no,
+                      nvl(replace(pro_order_no, '/', ''),
+                          replace(get_cp_order(t1.judge_stove_no), '/', ''))) is_lljg,
+           --是否来料加工,
+           '加工' process_name,
+           --工序,
+           '否' is_ckc,
+           --是否出口材
+           act_dimater dimater,
+           --外径
+           act_height height,
+           --壁厚
+           nvl(replace(pro_order_no, '/', ''),
+                replace(get_cp_order(t1.judge_stove_no), '/', '')) orderid,
+           --合同号
+           model_desc,
+           -- 扣型描述
+           get_cp_buyer(get_cp_order(t1.judge_stove_no)) buyer,
+           --客户名称
+           get_cp_pass(get_cp_order(t1.judge_stove_no)) pass --孔型
+      from ydm_zc_inlist t1
+     where instock_type_code in ('800701', '800702', '800706')--产出盘盈改判
+        and BAL_YEAR_MONTH = '{0}}'
+       and belong_code in ('100101', '100102', '100105')
+       and supply_unit_code = '120504'
+       and nvl(replace(pro_order_no, '/', ''),
+               replace(get_cp_order(t1.judge_stove_no), '/', '')) not like
+           'ZZBY%'
+       AND T1.PLINE_CODE = 'C108'
+     group by bal_year_month, spec_code,
+              --产品规格代码,
+              produccode,
+              --品名代码,
+              producname, gradecode,
+              --钢种代码,
+              gradename, steelcode,
+              --钢级代码,
+              steelname, judge_stove_no, process_desc, act_dimater,
+              --外径
+              act_height,
+              --壁厚
+              model_desc, t1.pro_order_no, t1.order_no, t1.order_seq,
+              spec_code, spec_name;
+
+  curoporder oporder_cursor%rowtype;
+
+begin
+
+  open oporder_cursor;
+  loop
+    fetch oporder_cursor
+      into curoporder;
+    exit when oporder_cursor%notfound;
+
+    select count(*)
+      into a
+      from orderdetail_v@th_cx_link t
+     where t.contractno_num = curoporder.orderid
+       and material_code is not null;
+
+    if a > 0 then
+      select prod_code, prod_name, sg_grade_code, sg_grade, sg_sign_code,
+             sg_sign, wall_thickness, material_code, material_name
+        into prod_code_cx, prod_name_cx, sg_grade_cx, sg_gradename_cx,
+             sg_sign_cx, sg_signname_cx, wall_thickness_cx, material_code_cx,
+             material_name_cx
+        from orderdetail_v@th_cx_link t
+       where t.contractno_num = curoporder.orderid
+         and material_code is not null
+         and rownum = 1;
+
+    elsif substr(curoporder.orderid, 1, 2) in ('TH', 'XS') then
+      select count(*)
+        into a
+        from orderdetail_v@th_cx_link t
+       where substr(t.contractno_num, 3) = substr(curoporder.orderid, 3)
+         and material_code is not null
+         and rownum = 1;
+      if a > 0 then
+        select prod_code, prod_name, sg_grade_code, sg_grade, sg_sign_code,
+               sg_sign, wall_thickness, material_code, material_name
+          into prod_code_cx, prod_name_cx, sg_grade_cx, sg_gradename_cx,
+               sg_sign_cx, sg_signname_cx, wall_thickness_cx,
+               material_code_cx, material_name_cx
+          from orderdetail_v@th_cx_link t
+         where substr(t.contractno_num, 3) = substr(curoporder.orderid, 3)
+           and material_code is not null
+           and rownum = 1;
+      end if;
+    end if;
+
+    if a > 0 then
+      insert into cx_ydm_bc_inlist
+        (bal_year_month, ckmc, material_no, material_name, spec_code,
+         spec_name, std_code, std_name, produccode, producname, gradecode,
+         gradename, steelcode, steelname, act_count, act_weight,
+         act_in_count, act_in_weight, act_out_count, act_out_weight, is_lljg,
+         process_name, is_ckc, dimater, height, pass, model_desc, buyer,
+         orderid, bc_type, judge_stove_no, instock_time,INSERT_TIME)
+      values
+        (curoporder.bal_year_month, curoporder.ckmc, material_code_cx,
+         material_name_cx, curoporder.spec_code,
+         sg_sign_cx || '*' || wall_thickness_cx, curoporder.std_code,
+         curoporder.std_name, prod_code_cx, prod_name_cx, sg_grade_cx,
+         sg_gradename_cx, sg_sign_cx, sg_signname_cx, curoporder.act_count,
+         curoporder.act_weight, curoporder.act_in_count,
+         curoporder.act_in_weight, curoporder.act_out_count,
+         curoporder.act_out_weight, curoporder.is_lljg,
+         curoporder.process_name, curoporder.is_ckc, curoporder.dimater,
+         curoporder.height, curoporder.pass, curoporder.model_desc,
+         curoporder.buyer, curoporder.orderid, '半成品入库',
+         curoporder.judge_stove_no, curoporder.instock_time,sysdate);
+
+    else
+      insert into cx_ydm_bc_inlist
+        (bal_year_month, ckmc, material_no, material_name, spec_code,
+         spec_name, std_code, std_name, produccode, producname, gradecode,
+         gradename, steelcode, steelname, act_count, act_weight,
+         act_in_count, act_in_weight, act_out_count, act_out_weight, is_lljg,
+         process_name, is_ckc, dimater, height, pass, model_desc, buyer,
+         orderid, bc_type, judge_stove_no, instock_time)
+      values
+        (curoporder.bal_year_month, curoporder.ckmc, null, null,
+         curoporder.spec_code, null, curoporder.std_code,
+         curoporder.std_name, null, null, null, null, null, null,
+         curoporder.act_count, curoporder.act_weight,
+         curoporder.act_in_count, curoporder.act_in_weight,
+         curoporder.act_out_count, curoporder.act_out_weight,
+         curoporder.is_lljg, curoporder.process_name, curoporder.is_ckc,
+         curoporder.dimater, curoporder.height, curoporder.pass,
+         curoporder.model_desc, curoporder.buyer, curoporder.orderid,
+         '半成品入库', curoporder.judge_stove_no, curoporder.instock_time);
+    end if;
+
+  end loop;
+  close oporder_cursor;
+  commit;
+
+  /*
+
+  exception
+    when others then
+      null;*/
+end mes_cx_ydm_bc_inlist_CSJG_hand;