SQL.txt 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /*上传数据的存储过程*/
  2. create or replace procedure sp_uploadbarcode(barcode in BarCodeUpload_arr)
  3. as
  4. begin
  5. for i in 1 .. barcode.count loop
  6. update prodiobarcode set pib_lotno=barcode(i).pib_lotno,
  7. pib_datecode=barcode(i).pib_datecode,pib_outboxcode1=barcode(i).pib_outboxcode1,
  8. pib_outboxcode2=barcode(i).pib_outboxcode2,pib_custmidboxcode=barcode(i).pib_custmidboxcode,
  9. pib_custoutboxcode=barcode(i).pib_custoutboxcode,
  10. pib_ifupload=barcode(i).pib_ifupload,pib_ifpick=barcode(i).pib_ifpick,
  11. pib_ifprint=barcode(i).pib_ifprint
  12. where pib_id=barcode(i).pib_id;
  13. end loop;
  14. end;
  15. /*创建上传的类型*/
  16. create or replace type BarCodeUpload_arr as table of BarCodeUpload;
  17. /*上传的对象实体*/
  18. create or replace type BarCodeUpload as object(
  19. pib_id varchar2(20),
  20. pib_outboxcode1 varchar2(20),
  21. pib_outboxcode2 varchar2(20),
  22. pib_custmidboxcode varchar2(20),
  23. pib_custoutboxcode varchar2(20),
  24. pib_lotno varchar2(20),
  25. pib_datecode varchar2(20),
  26. pib_ifupload varchar2(20),
  27. pib_ifpick varchar2(20),
  28. pib_ifprint varchar2(20)
  29. );
  30. /*获取数据的视图*/
  31. CREATE OR REPLACE FORCE VIEW "PRODIOBARCODE_VIEW" as
  32. select 0 choose,pib_ordercode,pib_weight,pib_prdetail,pib_size,pd_ordercode,nvl(pr_midboxcapacity_user,0)pr_midboxcapacity_user,pi_cardcode,pr_madein,pr_vendcode,
  33. pib_year,pib_month,pib_day,pd_whcode,pd_batchcode,pr_barcode,pd_pdno,pr_brand,pr_detail,pd_orderdetno,pib_custoutboxcode,pib_datecode1,pd_remark,pib_custmidboxcode,
  34. pr_orispeccode,pi_maitou_user,pd_custprodcode,pib_indate,pi_date,pib_inoutno,pd_custprodspec,nvl(pib_ifrecheck,0)pib_ifrecheck,nvl(pib_ifupload,0)pib_ifupload,
  35. nvl(pib_ifmodify,0)pib_ifmodify,pd_pocode,pib_madein,pib_custbarcode,pib_id,pib_pdid,pib_piid,pib_pdno,pib_prodcode,nvl(nvl(pd_brand,pib_brand),pr_brand)pib_brand,
  36. pr_vendprodcode,pib_lotno,pib_datecode,pib_qty,pr_spec,pi_title,pr_zxbzs,pr_unit,pib_barcode,pib_outboxcode1,pib_outboxcode2,nvl(pib_ifpick,0)pib_ifpick,nvl
  37. (pib_ifprint,0)pib_ifprint,pd_outerboxgw,pd_outerboxnw from prodiobarcode left join prodinout on pib_piid=pi_id left join prodiodetail on pib_piid=pd_piid and
  38. pd_id=pib_pdid left join product on pr_code=pib_prodcode left join sale on sa_code=pib_ordercode order by to_number(pib_outboxcode2),pib_custoutboxcode;
  39. /*自动生成条码的存储过程*/
  40. create or replace PROCEDURE "GETCUSTBARCODE"
  41. -- =============================================
  42. -- Author: <zhangz>
  43. -- Create date: <2018-06-12>
  44. -- Description: <出货单-过账-自动生成条码-自定义客户条码>
  45. -- =============================================
  46. (KEYVALUE in varchar2,ICID in varchar2,V_ERRORMSG OUT varchar2)
  47. AS
  48. v_custcode varchar2(50); --客户编号
  49. v_nrcode varchar2(20); --编码规则编号
  50. v_nrddetno number; --编码明细序号
  51. v_nrdname varchar(20); --编码明细名称
  52. v_nrdtype varchar(20); --编码明细类型
  53. v_nrdsql varchar(500); --编码明细SQL
  54. v_serialindex number; --流水所在索引
  55. v_nrdlength number; --编码明细流水长度
  56. v_seriallen number; --流水长度
  57. v_sqltemp varchar(50); --SQL查询出来的临时变量
  58. v_prefix varchar(50); --流水前面的前缀(临时)
  59. v_v_prefix varchar(50); --拼接时前缀
  60. v_suffix varchar(50); --流水的后缀
  61. v_maxnum varchar(50); --当前编号+前缀最大的流水
  62. v_inoutno varchar(30); --出货单号
  63. v_getcustrule number:=0; --是否维护了客户自定义规则
  64. v_pi_id ProdInout.pi_id%type;
  65. v_p_piclass ProdInout.pi_class%type;
  66. v_p_piinoutno ProdInout.pi_inoutno%type;
  67. v_p_commitname EMPLOYEE.EM_NAME%TYPE;
  68. v_pi_inoutman ProdInout.pi_inoutman%type;
  69. v_pd_ordercode prodiodetail.pd_ordercode%type;
  70. v_pd_prodCode prodiodetail.pd_prodcode%type;
  71. v_pd_thisqty prodiodetail.pd_outqty%type;
  72. v_pd_outqty prodiodetail.pd_outqty%type;
  73. v_pd_id ProdioDetail.pd_id%type;
  74. v_pd_piclass ProdioDetail.pd_piclass%type;
  75. v_pd_pdno ProdioDetail.pd_pdno%type;
  76. v_max_barcode prodiobarcode.pib_barcode%type;
  77. v_max_outboxcode prodiobarcode.pib_outboxcode1%type;
  78. v_max_prodcode prodiobarcode.pib_prodcode%type;
  79. v_max_custpo prodiobarcode.PIB_CUSTPO%type;
  80. v_pib_barcode prodiobarcode.pib_barcode%type;
  81. v_pib_custbarcode prodiobarcode.pib_custbarcode%type;
  82. v_pr_zxbzs product.pr_zxbzs%type;
  83. v_pr_id product.pr_id%type;
  84. v_sa_pocode sale.sa_pocode%type;
  85. v_bar_num NUMBER(8,0);
  86. v_box_num NUMBER(8,0);
  87. v_barcount NUMBER:=0; --条码数量
  88. v_restqty FLOAT:=0; --尾盘数量
  89. -- 默认箱内容量 :3,7,10. 默认最优分配箱内容量
  90. --最小包装数为1的暂时不自动生成条码
  91. CURSOR c_PDIOBarCur IS
  92. select pd_id,pd_pdno,pd_prodcode,pd_totalqty pd_outqty,pr_zxbzs,pd_qty pd_thisqty ,pr_id,pd_piclass, pd_ordercode,sa_pocode
  93. from PRODIOBARCODE_VIEW left join sale on sa_code=pd_ordercode
  94. where pd_piid=v_pi_id and pd_qty>0 and pr_zxbzs>1 order by pd_prodcode,pd_id;
  95. --存在客户编号的时候
  96. CURSOR NR IS
  97. select nrd_detno,nrd_name,nrd_type,nrd_sql,nrd_length,nr_code from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_custcode=v_custcode order by nrd_detno;
  98. --不存在客户编号取默认公用规则
  99. CURSOR NR_Default IS
  100. select nrd_detno,nrd_name,nrd_type,nrd_sql,nrd_length,nr_code from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_custcode is null and nr_isdefault <> 0 order by nrd_detno;
  101. BEGIN
  102. BEGIN
  103. select pi_id,pi_inoutno,pi_class,pi_inoutman,pi_cardcode
  104. into v_pi_id,v_p_piinoutno,v_p_piclass,v_pi_inoutman,v_custcode
  105. from prodinout where pi_id=KEYVALUE;
  106. EXCEPTION
  107. WHEN NO_DATA_FOUND THEN
  108. V_ERRORMSG := '没有当前出入库记录!' ;
  109. RETURN;
  110. END;
  111. select pi_inoutno into v_inoutno from prodinout where pi_id=KEYVALUE;
  112. IF(v_p_piclass='出货单') THEN --目前只先针对出货单自动生成条码
  113. --单据不存在判断
  114. /*SELECT count(1) into v_recordcount
  115. FROM prodiodetail
  116. WHERE pd_piid=v_pi_id and pd_status=0;
  117. IF v_recordcount >0 THEN
  118. v_return_string := '数据错误,单据未过账成功!' ;
  119. RETURN;
  120. END IF;
  121. --有过一条记录就不给生成
  122. select count(1) into v_recordcount from PRODIOBARCODE where PIB_PIID=v_pi_id;
  123. IF v_recordcount >0 THEN
  124. RETURN;
  125. END IF;*/
  126. --修改20170724 根据客户需求如果记录清空,重新生成,以免用户生成之后又修改数据,导致打印不了
  127. delete from PRODIOBARCODE where PIB_PIID=v_pi_id;
  128. OPEN NR;
  129. LOOP
  130. FETCH NR INTO v_nrddetno,v_nrdname,v_nrdtype,v_nrdsql,v_nrdlength,v_nrcode;
  131. IF NR%ROWCOUNT =0 THEN
  132. v_getcustrule:=1;
  133. END IF;
  134. --使用用户指定的规则
  135. EXIT WHEN NR%NOTFOUND;
  136. IF v_nrdtype='SQL' THEN --如果是SQL则取出
  137. BEGIN
  138. v_nrdsql:=regexp_replace(v_nrdsql,'{\w+}',''''||v_inoutno||'''');
  139. execute IMMEDIATE v_nrdsql into v_sqltemp;
  140. v_prefix:=v_prefix || v_sqltemp;
  141. v_suffix:=v_suffix || v_sqltemp;
  142. EXCEPTION
  143. WHEN OTHERS THEN
  144. BEGIN
  145. v_sqltemp:='';
  146. v_prefix:=v_prefix || v_sqltemp;
  147. v_suffix:=v_suffix || v_sqltemp;
  148. END;
  149. END;
  150. END IF;
  151. IF v_nrdtype='常量' THEN
  152. v_prefix :=v_prefix || v_nrdsql;
  153. v_suffix :=v_suffix || v_nrdsql;
  154. END IF;
  155. IF v_nrdtype='流水' THEN
  156. --前缀和后缀正常拼接,如果中间含有流水则清除后缀的值,拼接后缀的值
  157. v_nrdsql :='';
  158. v_serialindex :=v_nrddetno;
  159. v_suffix :='';
  160. v_v_prefix :=v_prefix;
  161. v_seriallen:=v_nrdlength;
  162. END IF;
  163. END LOOP;
  164. CLOSE NR;
  165. IF v_getcustrule<>0 THEN
  166. OPEN NR_Default;
  167. LOOP
  168. FETCH NR_Default INTO v_nrddetno,v_nrdname,v_nrdtype,v_nrdsql,v_nrdlength,v_nrcode;
  169. --使用用户指定的规则
  170. EXIT WHEN NR_Default%NOTFOUND;
  171. IF v_nrdtype='SQL' THEN --如果是SQL则取出
  172. BEGIN
  173. v_nrdsql:=regexp_replace(v_nrdsql,'{\w+}',''''||v_inoutno||'''');
  174. execute IMMEDIATE v_nrdsql into v_sqltemp;
  175. v_prefix:=v_prefix || v_sqltemp;
  176. v_suffix:=v_suffix || v_sqltemp;
  177. EXCEPTION
  178. WHEN OTHERS THEN
  179. BEGIN
  180. v_sqltemp:='';
  181. v_prefix:=v_prefix || v_sqltemp;
  182. v_suffix:=v_suffix || v_sqltemp;
  183. END;
  184. END;
  185. END IF;
  186. IF v_nrdtype='常量' THEN
  187. v_prefix :=v_prefix || v_nrdsql;
  188. v_suffix :=v_suffix || v_nrdsql;
  189. END IF;
  190. IF v_nrdtype='流水' THEN
  191. --前缀和后缀正常拼接,如果中间含有流水则清除后缀的值,拼接后缀的值
  192. v_nrdsql :='';
  193. v_serialindex :=v_nrddetno;
  194. v_suffix :='';
  195. v_v_prefix :=v_prefix;
  196. v_seriallen:=v_nrdlength;
  197. END IF;
  198. END LOOP;
  199. CLOSE NR_Default;
  200. END IF;
  201. BEGIN
  202. select rmn_maxnumber into v_maxnum from RuleMaxNum where rmn_nrcode=v_nrcode and rmn_prefix=v_prefix;
  203. EXCEPTION
  204. WHEN OTHERS THEN
  205. BEGIN
  206. v_maxnum:=1;
  207. insert into RuleMaxNum(rmn_id,rmn_maxnumber,rmn_nrcode,rmn_prefix)values(RuleMaxNum_seq.nextval,1,v_nrcode,v_prefix);
  208. END;
  209. END;
  210. OPEN c_PDIOBarCur ;
  211. LOOP
  212. FETCH c_PDIOBarCur into v_pd_id,v_pd_pdno,v_pd_prodcode,v_pd_outqty,v_pr_zxbzs,v_pd_thisqty,v_pr_id,v_pd_piclass,v_pd_ordercode,v_sa_pocode ;
  213. exit when c_PDIOBarCur%NOTFOUND;
  214. -- 查询当前物料的最大的条码和箱号流水
  215. select max(pib_barcode) into v_max_barcode from PRODIOBARCODE where pib_piid=v_pi_id and pib_prodcode=v_pd_prodcode;
  216. --获取该单据的最大箱号(在同一个单据内中盒号是唯一的)
  217. select max(to_number(pib_outboxcode1))into v_max_outboxcode from prodiobarcode where pib_piid=v_pi_id;
  218. IF(nvl(v_max_outboxcode,' ')<>' ')THEN
  219. select max(PIB_PRODCODE),MAX(PIB_CUSTPO) INTO v_max_prodcode,v_max_custpo from prodiobarcode where pib_piid=v_pi_id and pib_outboxcode1=v_max_outboxcode;
  220. END IF;
  221. if(nvl(v_max_barcode,' ')<>' ') then --计算条码流水
  222. v_bar_num := to_number(LTRIM(substr(v_max_barcode,-4),'0'))+1; --截取后四位,去掉前面的0,转成数字+1,可能会抛异常,无法转成数字
  223. else
  224. v_bar_num := 1;
  225. end if;
  226. --出货单最大箱号
  227. if(nvl(v_max_outboxcode,' ')<>' ' and (v_max_prodcode=v_pd_prodcode and nvl(v_max_custpo,' ')=nvl(v_sa_pocode,' '))) then --箱号
  228. v_box_num := to_number(v_max_outboxcode);
  229. else if (nvl(v_max_outboxcode,' ')<>' ') then
  230. v_box_num := to_number(v_max_outboxcode)+1;
  231. else
  232. v_box_num := 1;
  233. end if;
  234. end if;
  235. v_barcount := floor(v_pd_thisqty/v_pr_zxbzs); ---获取最小包装数整数倍的条码个数
  236. v_restqty := v_pd_thisqty - v_barcount*v_pr_zxbzs; -- 取尾数箱条码数量
  237. if(v_restqty >0) then
  238. v_barcount := v_barcount+1;
  239. end if ;
  240. for i in 1..v_barcount Loop
  241. --判断一盒是否已经装满 ,循环查询速度很慢
  242. /*select count(1) into v_recordcount from prodiobarcode where pib_piid=v_pi_id and PIB_OUTBOXCODE1=v_box_num ;--and pib_prodcode<>v_pd_prodcode;
  243. if(v_recordcount=10) then
  244. v_box_num := v_box_num+1;
  245. end if;*/
  246. v_pib_barcode := v_pd_id||'-'||v_pr_id||'-'||trim(to_char(v_bar_num,'0999')); --流水四位 pd_id-pr_id-四位流水(0001) 如 123-2345-0002格式
  247. select replace(lpad(v_maxnum,v_seriallen),' ','0') into v_maxnum from dual ;
  248. v_pib_custbarcode := v_v_prefix || v_maxnum || v_suffix;
  249. if(i = v_barcount and v_restqty>0) then --尾数盒
  250. insert into prodiobarcode(PIB_ID,PIB_PRODCODE,PIB_INDATE,PIB_INOUTNO,PIB_PIID,PIB_PDNO, PIB_PDID,PIB_PICLASS,
  251. PIB_BARCODE,PIB_CUSTBARCODE,PIB_QTY,PIB_PRODID,PIB_OUTBOXCODE1,PIB_IFPRINT,PIB_IFPICK,PIB_ORDERCODE,PIB_CUSTPO)
  252. values(prodiobarcode_seq.nextval,v_pd_prodcode,sysdate,v_p_piinoutno,v_pi_id,v_pd_pdno,v_pd_id,v_pd_piclass,
  253. v_pib_barcode,v_pib_custbarcode,v_restqty,v_pr_id,v_box_num,0,0,v_pd_ordercode,v_sa_pocode);
  254. else
  255. insert into prodiobarcode(PIB_ID,PIB_PRODCODE,PIB_INDATE,PIB_INOUTNO,PIB_PIID,PIB_PDNO, PIB_PDID,PIB_PICLASS,
  256. PIB_BARCODE,PIB_CUSTBARCODE,PIB_QTY,PIB_PRODID,PIB_OUTBOXCODE1,PIB_IFPRINT,PIB_IFPICK,PIB_ORDERCODE,PIB_CUSTPO)
  257. values(prodiobarcode_seq.nextval,v_pd_prodcode,sysdate,v_p_piinoutno,v_pi_id,v_pd_pdno,v_pd_id,v_pd_piclass,
  258. v_pib_barcode,v_pib_custbarcode,v_pr_zxbzs,v_pr_id,v_box_num,0,0,v_pd_ordercode,v_sa_pocode);
  259. end if;
  260. if(MOD(i,10) = 0 and i<>v_barcount)then --箱号加1
  261. v_box_num := v_box_num+1;
  262. end if;
  263. v_bar_num := v_bar_num+1 ; --条码号加1
  264. v_maxnum := v_maxnum+1;
  265. end loop;
  266. END LOOP;
  267. <<Exitlabel>>
  268. CLOSE c_PDIOBarCur;
  269. update RuleMaxNum set rmn_maxnumber=v_maxnum where rmn_nrcode=v_nrcode and rmn_prefix=v_prefix;
  270. --记录操作日志
  271. insert into messagelog (ml_id,ml_date,ml_man,ml_content,ml_result,ml_search)
  272. values(messagelog_seq.nextval,sysdate,v_p_commitname,'过账自动生成条码','生成条码成功','ProdInOut!Sale|pi_id='||v_pi_id);
  273. END IF;
  274. EXCEPTION
  275. WHEN OTHERS THEN
  276. V_ERRORMSG :=SQLERRM || dbms_utility.format_error_backtrace();
  277. END;
  278. /*自定义代码,根据不同客户进行页面设置*/
  279. create or replace PROCEDURE sp_custinit(
  280. KeyValue in varchar2,
  281. content out varchar2
  282. )as
  283. begin
  284. declare
  285. v_custcode varchar2(20);
  286. begin
  287. select pi_cardcode into v_custcode from prodinout where pi_id=KeyValue;
  288. content:='
  289. using System;
  290. using System.Windows.Forms;
  291. namespace CustInitSpace
  292. { public class CustInitClass
  293. {
  294. public void CustInit()
  295. {
  296. Form f=Form.ActiveForm;
  297. if(f.Controls["cu_code"].Text=="C000027")
  298. {
  299. (f.Controls["OutBoxLabel"].Controls["DiffCustOutBoxCode"] as CheckBox).Checked = false;
  300. }else
  301. {
  302. (f.Controls["OutBoxLabel"].Controls["DiffCustOutBoxCode"] as CheckBox).Checked = true;
  303. }
  304. }
  305. }
  306. }';
  307. end;
  308. end;
  309. /*获取数据页数据的SQL*/
  310. create or replace PROCEDURE sp_getDataSql(
  311. v_inoutno in varchar2,
  312. v_text in varchar2,
  313. v_sql out varchar2
  314. )as
  315. begin
  316. v_sql:='select' ||v_text|| ' from prodinout left join prodiodetail
  317. on pi_id=pd_piid left join chip_in_out on io_piid=pi_id and pd_id=io_pdid left join chip on ch_code=io_chipcode left join CHIP_WAFERTEST_VIEW on ch_code=chw_chipcode
  318. left join CHIP_EDCDATA_VIEW on che_chipcode=ch_code left join product on pr_code=pd_prodcode left join prodiobarcode on
  319. pib_piid=pi_id and pib_custbarcode=ch_code where pi_inoutno='''||v_inoutno||''' order by ch_code';
  320. end;
  321. insert into configs(id,caller,code,data) values(configs_seq.nextval,'Prodinout!Down','DownLoadLink','http://sisemi03.zicp.io/ERP');