CREATE OR REPLACE procedure mes_cx_ydm_zc_initialnew_hand is
begin

  insert into cx_ydm_zc_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)
    select substr(t1.bal_year_month, 0, 4) || '-' ||
            substr(t1.bal_year_month, 5, 2) as bal_year_month,
           '天淮成品库' as ckmc, t2.material_code as material_no,
           t2.material_name as material_name, spec_code,
           t2.outer_diam || '*' || t2.wall_thickness as spec_name, std_code,
           std_name, produccode,
           nvl(t2.prod_name, t1.producname) as producname, gradecode,
           nvl(t2.sg_grade, t1.gradename) as gradename, steelcode,
           nvl(t2.sg_sign, t1.steelname) as steelname, act_count, act_weight,
           0 as act_in_count, 0 as act_in_weight, 0 as act_out_count,
           0 as act_out_weight,
           getislljg(t1.judge_stove_no,
                      nvl(replace(pro_order_no, '/', ''),
                          replace(get_cp_order(t1.judge_stove_no), '/', ''))) as is_lljg,
           case PLINE_CODE when 'C108' then '车丝' else
           (case process_desc
              when '轧制' then
               '热轧'
              when '加工线' then
               '加工'
              else
               process_desc
            end) end as process_name, 
            
            --'否' as is_ckc, 
             (case
             when nvl(t2.if_export,'内贸') ='内贸' then
              '否'
             when nvl(t2.if_export,'内贸') ='外贸' then
              '是'
             else
              '否'
            end) is_ckc, 
            
            dimater, height,
           get_cp_pass(nvl(t1.pro_order_no, get_cp_order(t1.judge_stove_no))) as pass,
           model_desc,
           get_cp_buyer(nvl(t1.pro_order_no,
                             get_cp_order(t1.judge_stove_no))) as buyer,
           nvl(replace(t1.pro_order_no, '/', ''),nvl(t1.order_no||t1.order_seq,replace(get_cp_order(t1.judge_stove_no), '/', ''))) as orderid,
           '成品期初库存' as bc_type, t1.judge_stove_no,T1.instock_time,SYSDATE
           
      from cxuser.ydm_zc_initial t1, mvm_order_matno_info t2 --增加MVN
      
     where nvl(replace(t1.pro_order_no, '/', ''),nvl(t1.order_no||t1.order_seq,replace(get_cp_order(t1.judge_stove_no), '/', ''))) =t2.contractno_num(+)
           
       and t1.handle_log = '1'
       and t1.bal_year_month in ('{0}')
       and belong_code in ('100101', '100102', '100105')
       and t1.supply_unit_code = '120504'
       and nvl(replace(t1.pro_order_no, '/', ''),
               replace(get_cp_order(t1.judge_stove_no), '/', '')) not like
           'ZZBY%'
       and t1.judge_stove_no = 'A25120129'
    ;
  commit;
end mes_cx_ydm_zc_initialnew_hand;