mes_cx_rz_zzpnew_hand.sql 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. CREATE OR REPLACE procedure mes_cx_ydm_zc_outlist_new_hand is
  2. a number(4);
  3. b varchar(200);
  4. gxstr varchar(200);
  5. prod_name_cx varchar(200);
  6. prod_code_cx varchar(200);
  7. sg_grade_cx varchar(200);
  8. sg_gradename_cx varchar(200);
  9. sg_sign_cx varchar(200);
  10. sg_signname_cx varchar(200);
  11. wall_thickness_cx varchar(200);
  12. material_code_cx varchar(200);
  13. MATERIAL_NAME_cx varchar(200);
  14. outer_diam_cx varchar(200);
  15. cursor oporder_cursor is
  16. select substr(t1.bal_year_month, 0, 4) || '-' ||
  17. substr(t1.bal_year_month, 5, 2) bal_year_month,
  18. --记账日期
  19. '天淮成品库' ckmc, t1.judge_stove_no,
  20. --库存地名称,
  21. spec_code,
  22. --产品规格代码,
  23. spec_name,
  24. -- 产品规格描述,
  25. max(std_code) std_code,
  26. --执行标准代码,
  27. max(std_name) std_name,
  28. --执行标准名称,
  29. produccode,
  30. --品名代码,
  31. producname,
  32. --品名描述,
  33. gradecode,
  34. --钢种代码,
  35. gradename,
  36. --钢种名称,
  37. steelcode,
  38. --钢级代码,
  39. steelname,
  40. --钢级名称,
  41. 0 act_count,
  42. --期初库存支数,
  43. 0 act_weight,
  44. --期初库存重量,
  45. 0 act_in_count,
  46. --本期入库支数,
  47. 0 act_in_weight,
  48. --本期入库重量,
  49. sum(act_count) act_out_count,
  50. --本期出库支数,
  51. sum(nvl(PONDER_GROSS_WT,act_weight)) act_out_weight,
  52. (select nvl(sum(act_weight), 0)
  53. from ydm_zc_stocktakinglist t
  54. where t.judge_stove_no = t1.judge_stove_no
  55. and t.stocktaking_type_code = '800603'
  56. and t.bal_year_month = '{0}') lc,
  57. --本期出库重量,
  58. getislljg(t1.judge_stove_no,
  59. nvl(replace(pro_order_no, '/', ''),
  60. replace(get_cp_order(t1.judge_stove_no), '/', ''))) is_lljg,
  61. --是否来料加工,
  62. case max(PLINE_CODE) when 'C108' then '车丝' else
  63. (case process_desc
  64. when '轧制' then
  65. '热轧'
  66. when '加工线' then
  67. '加工'
  68. else
  69. process_desc
  70. end) end as process_name,
  71. --工序,
  72. -- '否' is_ckc,
  73. --是否出口材
  74. (case
  75. when nvl(mvm.if_export,'内贸') ='内贸' then
  76. '否'
  77. when nvl(mvm.if_export,'内贸') ='外贸' then
  78. '是'
  79. else
  80. '否'
  81. end) is_ckc,
  82. act_dimater dimater,
  83. --外径
  84. act_height height,
  85. --壁厚
  86. nvl(replace(pro_order_no, '/', ''),
  87. replace(get_cp_order(t1.judge_stove_no), '/', '')) orderid,
  88. --合同号
  89. model_desc,
  90. -- 扣型描述
  91. outstock_type_name,
  92. --入库类型名称
  93. get_cp_buyer(get_cp_order(t1.judge_stove_no)) buyer,
  94. --客户名称
  95. get_cp_pass(get_cp_order(t1.judge_stove_no)) pass --孔型
  96. from ydm_zc_outlist t1,mvm_order_matno_info mvm--增加MVN
  97. where nvl(replace(pro_order_no, '/', ''),
  98. replace(get_cp_order(t1.judge_stove_no), '/', '')) =
  99. mvm.CONTRACTNO_NUM
  100. and outstock_type_code in
  101. -- ('800805', '800804', '800802', '800808', '800806','800812')
  102. ('800805', '800804', '800802', '800808', '800806')
  103. and belong_code in ('100101', '100102', '100105')
  104. and supply_unit_code = '120504'
  105. and t1.bal_year_month in ('{0}')
  106. and t1.order_no || '/' || t1.order_seq not in
  107. ('XSXGQ-25A0432/001',
  108. 'XSXGQ-25A0975/001',
  109. 'XSXGQ-25A0975/002',
  110. 'XSXKQ-25A0174/007',
  111. 'XSXKQ-25A0174/008',
  112. 'XSXKQ-25A0795/001')
  113. and nvl(replace(pro_order_no, '/', ''),
  114. replace(get_cp_order(t1.judge_stove_no), '/', '')) not like
  115. 'ZZBY%'
  116. --and t1.judge_stove_no like 'F%'
  117. group by bal_year_month, spec_code,
  118. --产品规格代码,
  119. produccode,
  120. --品名代码,
  121. producname, gradecode,
  122. --钢种代码,
  123. gradename, steelcode,
  124. --钢级代码,
  125. steelname, judge_stove_no, process_desc, act_dimater,
  126. --外径
  127. act_height,
  128. --壁厚
  129. model_desc, t1.pro_order_no,-- t1.order_no, t1.order_seq,
  130. spec_code, spec_name, batch_no,mvm.if_export,outstock_type_name;
  131. curoporder oporder_cursor%rowtype;
  132. begin
  133. open oporder_cursor;
  134. loop
  135. fetch oporder_cursor
  136. into curoporder;
  137. exit when oporder_cursor%notfound;
  138. --获取期初或入库的工序
  139. select count(*)
  140. into a
  141. from cxuser.ydm_zc_initial t
  142. where t.judge_stove_no = curoporder.judge_stove_no
  143. and bal_year_month = replace(curoporder.bal_year_month, '-', '');
  144. if a > 0 then
  145. select (case PLINE_CODE when 'C108' then '车丝' else
  146. (case process_desc
  147. when '轧制' then
  148. '热轧'
  149. when '加工线' then
  150. '加工'
  151. else
  152. process_desc
  153. end) end)
  154. into gxstr
  155. from cxuser.ydm_zc_initial t
  156. where t.judge_stove_no = curoporder.judge_stove_no
  157. and bal_year_month = replace(curoporder.bal_year_month, '-', '')
  158. and rownum = 1;
  159. else
  160. select count(*)
  161. into a
  162. from cxuser.ydm_zc_inlist t
  163. where t.judge_stove_no = curoporder.judge_stove_no
  164. and bal_year_month = replace(curoporder.bal_year_month, '-', '');
  165. if a > 0 then
  166. select (case PLINE_CODE when 'C108' then '车丝' else
  167. (case process_desc
  168. when '轧制' then
  169. '热轧'
  170. when '加工线' then
  171. '加工'
  172. else
  173. process_desc
  174. end) end)
  175. into gxstr
  176. from cxuser.ydm_zc_inlist t
  177. where t.judge_stove_no = curoporder.judge_stove_no
  178. and bal_year_month = replace(curoporder.bal_year_month, '-', '')
  179. and rownum = 1;
  180. else
  181. gxstr := curoporder.process_name;
  182. end if;
  183. end if;
  184. select count(*)
  185. into a
  186. from mvm_order_matno_info t
  187. where t.contractno_num = curoporder.orderid
  188. and material_code is not null;
  189. if a > 0 then
  190. select outer_diam,prod_code,prod_name,SG_GRADE_CODE,sg_grade,SG_SIGN_CODE,sg_sign,wall_thickness,material_code,MATERIAL_NAME
  191. into outer_diam_cx,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
  192. from mvm_order_matno_info t
  193. where t.contractno_num = curoporder.orderid
  194. and material_code is not null
  195. and rownum = 1;
  196. elsif substr(curoporder.orderid, 1, 2) in ('TH', 'XS','EX') then
  197. select count(*)
  198. into a
  199. from mvm_order_matno_info t
  200. where substr(t.contractno_num, 3) = substr(curoporder.orderid, 3)
  201. and material_code is not null
  202. and rownum = 1;
  203. if a > 0 then
  204. select outer_diam,prod_code,prod_name,SG_GRADE_CODE,sg_grade,SG_SIGN_CODE,sg_sign,wall_thickness,material_code,MATERIAL_NAME
  205. into outer_diam_cx,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
  206. from mvm_order_matno_info t
  207. where substr(t.contractno_num, 3) = substr(curoporder.orderid, 3)
  208. and material_code is not null
  209. and rownum = 1;
  210. end if;
  211. end if;
  212. if a > 0 then
  213. -- 检查是否已存在相同judge_stove_no且differential不为空的记录
  214. declare
  215. v_count number;
  216. begin
  217. select count(*)
  218. into v_count
  219. from cx_ydm_zc_outlist t
  220. where judge_stove_no = curoporder.judge_stove_no
  221. and differential <> 0
  222. and bal_year_month = curoporder.bal_year_month;
  223. if v_count > 0 then
  224. insert into cx_ydm_zc_outlist
  225. (bal_year_month, ckmc, material_no, material_name, spec_code,
  226. spec_name, std_code, std_name, produccode, producname, gradecode,
  227. gradename, steelcode, steelname, act_count, act_weight,
  228. act_in_count, act_in_weight, act_out_count, act_out_weight, is_lljg,
  229. process_name, is_ckc, dimater, height, pass, model_desc, buyer,
  230. orderid, bc_type, judge_stove_no,INSERT_TIME,DIFFERENTIAL,bak1)
  231. values
  232. (curoporder.bal_year_month, curoporder.ckmc, material_code_cx,
  233. MATERIAL_NAME_cx, curoporder.spec_code,
  234. outer_diam_cx || '*' || wall_thickness_cx,
  235. curoporder.std_code, curoporder.std_name, prod_code_cx,
  236. prod_name_cx, sg_grade_cx, sg_gradename_cx,
  237. sg_sign_cx, sg_signname_cx, curoporder.act_count,
  238. curoporder.act_weight, curoporder.act_in_count,
  239. curoporder.act_in_weight, curoporder.act_out_count,
  240. curoporder.act_out_weight, curoporder.is_lljg, gxstr,
  241. curoporder.is_ckc, curoporder.dimater, curoporder.height,
  242. curoporder.pass, curoporder.model_desc, curoporder.buyer,
  243. curoporder.orderid, '成品出库', curoporder.judge_stove_no,sysdate,curoporder.lc,curoporder.outstock_type_name);
  244. else
  245. insert into cx_ydm_zc_outlist
  246. (bal_year_month, ckmc, material_no, material_name, spec_code,
  247. spec_name, std_code, std_name, produccode, producname, gradecode,
  248. gradename, steelcode, steelname, act_count, act_weight,
  249. act_in_count, act_in_weight, act_out_count, act_out_weight, is_lljg,
  250. process_name, is_ckc, dimater, height, pass, model_desc, buyer,
  251. orderid, bc_type, judge_stove_no,INSERT_TIME,DIFFERENTIAL,bak1)
  252. values
  253. (curoporder.bal_year_month, curoporder.ckmc, material_code_cx,
  254. MATERIAL_NAME_cx, curoporder.spec_code,
  255. outer_diam_cx || '*' || wall_thickness_cx,
  256. curoporder.std_code, curoporder.std_name, prod_code_cx,
  257. prod_name_cx, sg_grade_cx, sg_gradename_cx,
  258. sg_sign_cx, sg_signname_cx, curoporder.act_count,
  259. curoporder.act_weight, curoporder.act_in_count,
  260. curoporder.act_in_weight, curoporder.act_out_count,
  261. curoporder.act_out_weight, curoporder.is_lljg, gxstr,
  262. curoporder.is_ckc, curoporder.dimater, curoporder.height,
  263. curoporder.pass, curoporder.model_desc, curoporder.buyer,
  264. curoporder.orderid, '成品出库', curoporder.judge_stove_no,sysdate,curoporder.lc,curoporder.outstock_type_name);
  265. end if;
  266. end;
  267. else
  268. insert into cx_ydm_zc_outlist
  269. (bal_year_month, ckmc, material_no, material_name, spec_code,
  270. spec_name, std_code, std_name, produccode, producname, gradecode,
  271. gradename, steelcode, steelname, act_count, act_weight,
  272. act_in_count, act_in_weight, act_out_count, act_out_weight, is_lljg,
  273. process_name, is_ckc, dimater, height, pass, model_desc, buyer,
  274. orderid, bc_type, judge_stove_no,DIFFERENTIAL,bak1)
  275. values
  276. (curoporder.bal_year_month, curoporder.ckmc, null, null,
  277. curoporder.spec_code, null, curoporder.std_code,
  278. curoporder.std_name, null, null, null, null, null, null,
  279. curoporder.act_count, curoporder.act_weight,
  280. curoporder.act_in_count, curoporder.act_in_weight,
  281. curoporder.act_out_count, curoporder.act_out_weight,
  282. curoporder.is_lljg, gxstr, curoporder.is_ckc, curoporder.dimater,
  283. curoporder.height, curoporder.pass, curoporder.model_desc,
  284. curoporder.buyer, curoporder.orderid, '成品出库',
  285. curoporder.judge_stove_no,curoporder.lc,curoporder.outstock_type_name);
  286. end if;
  287. end loop;
  288. close oporder_cursor;
  289. commit;
  290. /*
  291. exception
  292. when others then
  293. null;*/
  294. end mes_cx_ydm_zc_outlist_new_hand;