-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPHSCWMS_DB Body.sql
More file actions
2973 lines (2760 loc) · 118 KB
/
PHSCWMS_DB Body.sql
File metadata and controls
2973 lines (2760 loc) · 118 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--------------------------------------------------------
-- 文件已创建 - 星期五-三月-07-2014
--------------------------------------------------------
-- 无法呈现对象 HSCMP 的 PACKAGE BODY DDL。带有 DBMS_METADATA 的 PHSCWMS_DB 正在尝试内部生成器。
CREATE
PACKAGE BODY PHSCWMS_DB is
/*===============================================*/
--标题:PHSCWMS_DB
--版本:5.10.5.4
/*===============================================*/
--功能:记录操作日志
procedure WriteIOCmpLog
(ps_LogType IN IO_HsCmpLog.LogType%type,
pd_LogTime IN IO_HsCmpLog.LogTime%type,
pi_UserId IN IO_HsCmpLog.UserId%type,
ps_YwType IN IO_HsCmpLog.YwType%type,
ps_YwName IN IO_HsCmpLog.YwName%type,
ps_DataKey IN Io_HsCmpLog.Datakey%type,
ps_LogMeg IN IO_HsCmpLog.LogMeg%type)
Is
pragma autonomous_transaction;
Begin
insert into IO_HscmpLog(LogType,LogTime,UserId,YwType,YwName,DataKey,LogMeg)
values (ps_LogType,sysdate,pi_UserId,ps_YwType,ps_YwName,ps_DataKey,ps_LogMeg);
commit;
Exception
When Others then rollback;
End WriteIOCmpLog;
--取得用户信息
procedure SysGet_Usr_Info
(pi_UserId IN tUsrUser.UserId%type,
pr_Out OUT PHSCWMS_VAR.P_UsrUser_RecType,
pi_Result Out integer,
ps_Message Out varchar2)
Is
cursor CurHSC_GetUsr is
select UserCode,UserName
from tUsrUser
where UserId=pi_UserId;
Begin
pi_Result:=-1;
ps_Message:='取得用户信息失败';
/*=================提取用户信息================*/
pr_Out.UserId:=pi_UserId;
if CurHSC_GetUsr%isopen then close CurHSC_GetUsr; end if;
open CurHSC_GetUsr;
fetch CurHSC_GetUsr
into pr_Out.UserCode,pr_Out.UserName;
if CurHSC_GetUsr%notfound then
if CurHSC_GetUsr%isopen then close CurHSC_GetUsr; end if;
return;
end if;
if CurHSC_GetUsr%isopen then close CurHSC_GetUsr; end if;
/*=================成功================*/
pi_Result:=1;
ps_Message:='取得用户信息成功';
Exception when others then
begin
pi_Result:=-1;
ps_Message:=substr(nvl(ps_Message,'取得用户信息失败!')||'发生位置:'||Sqlerrm,1,2000);
if CurHSC_GetUsr%isopen then close CurHSC_GetUsr; end if;
end;
End SysGet_Usr_Info;
--功能:根据商品编码取得商品信息
procedure SysGet_PluCode_Plu
(ps_PluCode IN tSkuPlu.PluCode%type, --输入:商品条形码
pr_Out OUT PHSCWMS_VAR.P_OutPlu_RecType, --输出:商品信息
pi_Result Out integer,
ps_Message Out varchar2) --输出:返回错误信息
Is
Cursor CurHSC_GetPlu is
select PluId,PluCode,PluName,Spec,Unit,BarCode
from tSkuPlu
where PluCode=ps_PluCode
and IsActive='1';
vr_B CurHSC_GetPlu%rowtype;
Begin
/*=================变量初始化=================*/
pi_Result:=-1;
ps_Message:='根据商品编码取得商品信息失败';
/*=================取得商品信息=================*/
open CurHSC_GetPlu;
fetch CurHSC_GetPlu into vr_B;
if CurHSC_GetPlu%found then
select vr_B.PluId,vr_B.PluCode,vr_B.PluName,vr_B.Spec,vr_B.Unit,vr_B.BarCode
into pr_Out.PluId,pr_Out.PluCode,pr_Out.PluName,pr_Out.Spec,pr_Out.Unit,pr_Out.BarCode
from dual;
end if;
if CurHSC_GetPlu%isopen then close CurHSC_GetPlu; end if;
/*=================成功===========================*/
pi_Result:=1;
ps_Message:='根据商品编码取得商品信息成功';
Exception when others then
begin
pi_Result:=-1;
ps_Message:=nvl(ps_Message,'调用“SysGet_PluCode_Plu”时发生未知错误:')||Sqlerrm;
ps_Message:=substr(ps_Message,1,2000);
if CurHSC_GetPlu%isopen then close CurHSC_GetPlu; end if;
return;
end;
End;
--判断接收数据和单据明细表中的数据是否一致
procedure Sys_CheckData
(ps_BillNoIO In tOrdCgHead.BillNo%type,
ps_TableIO In varchar2,
ps_BillNo In tOrdCgHead.BillNo%type,
ps_TableBill In varchar2,
pi_Result Out integer,
ps_Message Out varchar2)
Is
vi_Count_IO integer;
vi_Count_Bill integer;
vs_Sql varchar2(2000);
vc_Data sys_refcursor;
Begin
pi_Result:=-1;
ps_Message:='判断数据一致性失败:业务单据('||ps_BillNo||')接收数据与原单据记录数不同!';
/*=================判断记录数是否相同===========================*/
execute immediate('select count(1) from '||ps_TableIO||
' where FSRCORDNUM =:ms_BillNo ')
into vi_Count_IO
using ps_BillNoIO;
execute immediate('select count(1) from '||ps_TableBill||
' where BillNo=:ms_BillNo')
into vi_Count_Bill
using ps_BillNo;
if vi_Count_IO<>vi_Count_Bill then
ps_Message:='业务单据('||ps_BillNo||')接收数据与原单据记录数不同:接收记录数('||
to_char(vi_Count_IO)||')'||',原单据记录数('||to_char(vi_Count_Bill)||')';
return;
end if;
/*=================判断SerialNo和商品与原单据是否完全相同===========================*/
vs_Sql:='select ''序号为''||to_char(A.SerialNo)||''的商品(''||A.PluCode||'')''
from '||ps_TableBill||' A where A.BillNo='''||ps_BillNo||''' '||
' and not exists ( select 1 from '||ps_TableIO||' B
where B.FSRCORDNUM='''||ps_BillNoIO||''' '||
' and A.SerialNo=B.LINE
and A.PluCode=B.FARTICLECODE
)';
open vc_Data for vs_Sql;
fetch vc_Data into ps_Message;
if vc_Data%found then
ps_Message:='判断数据一致性失败:原单据('||ps_BillNo||')中'||ps_Message||
'记录与接收数据中不相符!';
if vc_Data%isopen then close vc_Data; end if;
return;
end if;
if vc_Data%isopen then close vc_Data; end if;
/*=================成功===========================*/
pi_Result:=1;
ps_Message:='判断数据一致性成功';
Exception when others then
begin
pi_Result:=-1;
ps_Message:=nvl(ps_Message,'调用“Sys_CheckData”时发生未知错误:')||Sqlerrm;
ps_Message:=substr(ps_Message,1,2000);
if vc_Data%isopen then close vc_Data; end if;
return;
end;
End Sys_CheckData;
--功能:转移接收表中的数据到历史表
procedure IO_MovHis
(ps_DataKey IN tSkuPlu.PluName%type,
ps_DataType IN tSkuPlu.PluName%type,
pi_Result Out integer,
ps_Message Out varchar2)
Is
Begin
pi_Result:=1;
return;
/*=================初始化变量================*/
pi_Result:=-1;
ps_Message:='数据转移历史时出错!';
/*=================合法性判断================*/
if upper(ps_DataType) not in (upper('WM_MIS_TSTKNORD'),
upper('WM_MIS_TSTORERTN'),upper('IO_tEtpCustomer'),upper('IO_tOrdCg'),
upper('IO_tDstPs'),upper('IO_tDstRtn'),upper('IO_tOrdTh'),
upper('WM_MIS_TSTKNORD'),upper('IO_tDstPs'),upper('IO_tDstRtn'),
upper('IO_tOrdTh'),upper('IO_tStkKc'),upper('IO_tStkYk')) then
return;
end if;
/*=================转移验收信息===============*/
if upper(ps_DataType) in ('WM_MIS_TSTKNORD') then
Insert into WM_MIS_TSTKNORDHIS
select * from WM_MIS_TSTKNORD where FSRCORDNUM=ps_DataKey;
delete from WM_MIS_TSTKNORD where FSRCORDNUM=ps_DataKey;
Insert into WM_MIS_TSTKNORDDTLHIS
select * from WM_MIS_TSTKNORDDTL where FSRCORDNUM=ps_DataKey;
delete from WM_MIS_TSTKNORDDTL where FSRCORDNUM=ps_DataKey;
end if;
if upper(ps_DataType) in ('WM_MIS_TSTORERTN') then
Insert into WM_MIS_TSTORERTNDTLHIS
select *
from WM_MIS_TSTORERTNDTL
where NUM in
(select NUM from WM_MIS_TSTORERTN where FSRCNUM = ps_DataKey);
delete from WM_MIS_TSTORERTNDTL
where NUM in
(select NUM from WM_MIS_TSTORERTN where FSRCNUM = ps_DataKey);
Insert into WM_MIS_TSTORERTNHIS
select * from WM_MIS_TSTORERTN where FSRCNUM=ps_DataKey;
delete from WM_MIS_TSTORERTN where FSRCNUM=ps_DataKey;
end if;
/*=================成功退出================*/
pi_Result:=1;
ps_Message:='数据转移到历史成功';
Exception
When Others then
begin
pi_Result:=-1;
ps_Message:=nvl(ps_Message,'调用“IO_MovHis”时发生未知错误:')||Sqlerrm;
ps_Message:=substr(ps_Message,1,2000);
return;
end;
End IO_MovHis;
procedure GetWlBillData
(ps_BillNo IN tOrdCgHead.BillNo%type,
ps_YwType IN tOrdJhHead.YwType%type,
pi_UserId IN tOrdJhHead.UserId%type,
ps_UserCode IN tOrdJhHead.UserCode%type,
ps_UserName IN tOrdJhHead.UserName%type,
pd_Date IN tOrdJhHead.JzDate%type,
pi_Result OUT integer,
ps_Message OUT varchar2)
Is
vs_SQL varchar2(2000);
vs_HOrgCode tOrdCgHead.HOrgCode%type;
vs_TBN varchar2(255);
vc_Data sys_refcursor;
vs_YwName Tsysywtype.Ywtypename%type;
vd_Date date;
vi_count integer;
cur_all Sys_Refcursor;
vs_PsType tOrdCgHead.Pstype%type;
Begin
/*=================初始化变量================*/
pi_Result:=-1;
vd_Date:=sysdate;
ps_Message:='从海信系统导出单据失败:传入的业务类型('||ps_YwType||')非法!';
if ps_YwType not in ('0902','2003','2007','0914','0912','2004') then return; end if;
ps_Message:='从海信系统导出单据失败:取得总部编码失败!';
select InOrgCode into vs_HOrgCode from tOrgManage where OrgType='1001';
select decode(ps_YwType,'0902','tOrdCgHead','2003','tDstPsHead','2007','tDstPsHead','2004','tDstRtnHead','tOrdThHead') As TNB
into vs_TBN
from dual;
/*=================合法性判断================*/
vs_SQL:=' select 1 as MyData from '||vs_TBN||' where BillNo='''||ps_BillNo||''' ';
if ps_YwType in ('0902') then
vs_SQL:=vs_SQL||' and HOrgCode='''||vs_HOrgCode||''' ';
end if;
if ps_YwType in ('0914') then
vs_SQL:=vs_SQL||' and InOrgCode='''||vs_HOrgCode||''' ';
end if;
/* if ps_YwType in ('0912') then
vs_SQL:=vs_SQL||' and InOrgCode='''||vs_HOrgCode||''' ';
end if;*/
if ps_YwType in ('2003','2007','0914','0912','2004') then
vs_SQL:=vs_SQL||' and TjDate is null and DataStatus<>''9'' ';
end if;
if not PSTO.IsExistsData(vs_SQL) then goto GetWlBillData; end if;
if ps_YwType in ('0902','2003','0914','0912','2004') then
if ps_YwType='0902' then
vs_SQL:= ' select ''商品(''||M.PluCode||'')的同种类型存在多条明细数据''
from
( select PluCode,PluTYpe
from tOrdCgHead H,tOrdCgBody B
where H.BillNo=B.BillNo
and h.Billno='''||ps_BillNo||'''
) M
group by PluCode,PluType
having Count(1)>1';
end if;
if ps_YwType in ('2003') then
vs_SQL:= 'select ''商品(''||M.PluCode||'')存在同种类型具有不同的价格''
from
( select PluCode,PluType
from tDstPsHead H,tDstPsBody B
where H.BillNo=B.BillNo
and h.Billno='''||ps_BillNo||'''
group by PluCode,PluType,
case when H.Orgtype=''0'' then B.price
when H.OrgType=''1'' then B.psprice
end
) M
group by PluCode,PluType
having Count(1)>1';
end if;
if ps_YwType in ('0912','0914') then
vs_SQL:= 'select ''商品(''||M.PluCode||'')存在同种类型多条明细数据''
from
( select PluCode,PluType
from tOrdThHead H,tOrdThBody B
where H.BillNo=B.BillNo
and h.Billno='''||ps_BillNo||'''
) M
group by PluCode,PluType
having Count(1)>1';
end if;
if ps_YwType in ('2004') then
vs_SQL:= 'select ''商品(''||M.PluCode||'')存在同种类型多条明细数据''
from
( select PluCode,PluType
from tDstRtnHead H,tDstRtnBody B
where H.BillNo=B.BillNo
and h.Billno='''||ps_BillNo||'''
) M
group by PluCode,PluType
having Count(1)>1';
end if;
open vc_Data for vs_Sql;
fetch vc_Data into ps_Message;
if vc_Data%found then
ps_Message:='从海信系统导出单据失败:'||ps_Message||';单据无法传递';
if vc_Data%isopen then close vc_Data; end if;
return;
end if;
if vc_Data%isopen then close vc_Data; end if;
end if;
/*=================初始单据的状态表================*/
if ps_YwType='0902' then
vs_YwName := '采购单';
else
if ps_YwType in ('2003','2007') then
vs_YwName := '配送单';
else
if ps_YwType='2004' then
vs_YwName := '配送退货单';
else
if ps_YwType='0914' then
vs_YwName := '采购退货单';
end if;
if ps_YwType='0912' then
vs_YwName := '门店退货单';
end if;
end if;
end if;
end if;
ps_Message:='产生'||vs_YwName||'('||ps_BillNo||')的初始状态失败!';
insert into IO_tBillTranState(BillNo,YwType,BillState,TjTime,
CmpState,CmpTime,CmpMessage,PlatState,PlatTime,PlatMessage,WlState,WlTime,Wlmessage)
values(ps_BillNo,ps_YwType,'0',sysdate,
'0',null,null,'0',null,null,'0',null,null);
/*=================处理采购单================*/
if ps_YwType='0902' then
ps_Message:='从海信系统导出单据失败:产生采购单('||ps_BillNo||')导出数据失败!';
delete from MIS_WM_TSTKINORD where NUM=ps_BillNo;
Insert into MIS_WM_TSTKINORD(num,fcls,Fvendor,FVENDORCODE,FEXPECTEDDATE,FEXPIREDATE,FSRC,FWRH,
FFILLER,FCREATETIME,FSENDTIME,FRTNINFO,FMEMO,FSRCORG,FDESTORG,FISQUICK,FCODE)
select H.BillNo,case when H.Pstype='0' then '0' when psType='1' then '1' else '0' end,
456,H.Supcode,to_date(H.Zddate,'YYYY-MM-DD'),to_date(H.YxDate,'YYYY-MM-DD'),
'HSCMP','01',H.Usercode,H.Lrdate,vd_Date,null,
H.Remark,'HSCMP','WMS1','0',H.Ysorgcode
from tOrdCgHead H
where H.BillNo=ps_BillNo;
delete from MIS_WM_TSTKINORDDTL where NUM=ps_BillNo;
Insert into MIS_WM_TSTKINORDDTL(NUM,LINE,FARTICLE,FARTICLECODE,FQTY,FPRICE,FSENDTIME,
FSRCORG,FDESTORG,FTAXRATE,FQPCSTR,FQPC)
select H.BillNo,B.SERIALNO,123,B.PluCode,B.Cgcount,B.Hjprice,vd_Date,'HSCMP','WMS1',
B.JTAXRATE,B.SPEC,B.Packcount
from tOrdCgHead H,tOrdCgBody B
where H.BillNo=B.BillNo and H.BillNo=ps_BillNo;
open cur_all for select PsType from tOrdCgHead where BillNo=ps_BillNo;
fetch cur_all into vs_PsType;
close cur_all;
if vs_PsType='1' then
ps_Message:='从海信系统导出订单越库单据对应失败';
delete from MIS_WM_TORDALC where FORDNUM=ps_BillNo;
insert into MIS_WM_TORDALC(Fordnum,FALCNUM,FSENDTIME,FSRCORG,FDESTORG)
select A.BillNo, 'P'||B.Billno, vd_Date, 'HSCMP', 'WMS1'
from tOrdCgHead A,tDstPsHead B
where A.BillNo=ps_BillNo and A.BillNo=B.Refbillno;
/*from (select BillNo from tOrdCgHead where BillNo = ps_BillNo) X,
(select Refbillno
from Tdstpsjobbill
where RefBillType = '2'
and PsJobNo in (select PsJobNo
from Tdstpsjobbill
where refBillNo = ps_BillNo
and refBillType = '3')) Y;*/
select count(*) into vi_count from WM_MIS_TSENDLIST where FCLS='订单配单对应';
if vi_count=0 then
Insert into WM_MIS_TSENDLIST(FSENDTIME,FCLS,FNOTE,FSRCORG,FDESTORG,FDELTIME)
values(vd_Date,'订单配单对应',null,'HSCMP','WMS1',null);
else
update WM_MIS_TSENDLIST set FSENDTIME=vd_Date where FCLS='订单配单对应';
end if;
ps_Message:='从海信系统导出越库配送单据失败';
delete from MIS_WM_TALCNTC where NUM=ps_BillNo;
Insert into MIS_WM_TALCNTC(NUM,FSTORECODE,FALCREASON,FSRC,FWRH,FFILLER,FCREATETIME,
FSENDTIME,FALCTIME,FMEMO,FSRCORG,FDESTORG,FCLS,FISQUICK)
select 'P' || H.BIllNo,H.Shorgcode,'越库配货','HSCMP','01',H.Usercode,H.Lrdate,vd_Date,
vd_Date,H.Remark,'HSCMP','WMS1',case when H.YwType='2003' then '0'
when H.YwType='2007' then '1' end,'0'
from tDstPsHead H
where 'P'||BillNo in (select FALCNUM from MIS_WM_TORDALC where FORDNUM=ps_BillNo)
and H.TjDate is null;
Insert into MIS_WM_TALCNTCDTL(num,LINE,FARTICLE,FARTICLECODE,FQTY,FPRICE,FSENDTIME,FMEMO,
FSRCORG,FDESTORG,FWRHCARD,FALCPRICE,FSTOREPRICE,FPRODUCEDATE,FDIRECT)
select 'P' || H.BillNo,B.Serialno,123,B.PluCode,B.Pscount,B.Psprice,vd_Date,B.Remark,'HSCMP','WMS1',
null,B.Psprice,B.Psprice,B.Scdate,null
from tDstPsHead H,tDstPsBody B
where H.BillNo=B.BillNo and 'P'||H.BillNo in (select FALCNUM from MIS_WM_TORDALC where FORDNUM=ps_BillNo)
and H.TjDate is null;
select count(*) into vi_count from WM_MIS_TSENDLIST where FCLS='配货通知单';
if vi_count=0 then
Insert into WM_MIS_TSENDLIST(FSENDTIME,FCLS,FNOTE,FSRCORG,FDESTORG,FDELTIME)
values(vd_Date,'配货通知单',null,'HSCMP','WMS1',null);
else
update WM_MIS_TSENDLIST set FSENDTIME=vd_Date where FCLS='配货通知单';
end if;
end if;
select count(*) into vi_count from WM_MIS_TSENDLIST where FCLS='自营定单';
if vi_count=0 then
Insert into WM_MIS_TSENDLIST(FSENDTIME,FCLS,FNOTE,FSRCORG,FDESTORG,FDELTIME)
values(vd_Date,'自营定单',null,'HSCMP','WMS1',null);
else
update WM_MIS_TSENDLIST set FSENDTIME=vd_Date where FCLS='自营定单';
end if;
end if;
/*=================处理配送单================*/
if ps_YwType in ('2003') then
ps_Message:='从海信系统导出单据失败:产生配送单('||ps_BillNo||')导出数据失败!';
delete from MIS_WM_TALCNTC where NUM=ps_BillNo;
Insert into MIS_WM_TALCNTC(NUM,FSTORECODE,FALCREASON,FSRC,FWRH,FFILLER,FCREATETIME,
FSENDTIME,FALCTIME,FMEMO,FSRCORG,FDESTORG,FCLS,FISQUICK)
select 'P' || H.BIllNo,H.Shorgcode,'统配正常','HSCMP','01',H.Usercode,H.Lrdate,vd_Date,
vd_Date,H.Remark,'HSCMP','WMS1',case when H.YwType='2003' then '0'
when H.YwType='2007' then '1' end,'0'
from tDstPsHead H
where H.BillNo=ps_BillNo
and H.TjDate is null;
Insert into MIS_WM_TALCNTCDTL(num,LINE,FARTICLE,FARTICLECODE,FQTY,FPRICE,FSENDTIME,FMEMO,
FSRCORG,FDESTORG,FWRHCARD,FALCPRICE,FSTOREPRICE,FPRODUCEDATE,FDIRECT)
select 'P' || H.BillNo,B.Serialno,123,B.PluCode,B.Pscount,B.Psprice,vd_Date,B.Remark,'HSCMP','WMS1',
null,B.Psprice,B.Psprice,B.Scdate,null
from tDstPsHead H,tDstPsBody B
where H.BillNo=B.BillNo and H.BillNo=ps_BillNo
and H.TjDate is null;
select count(*) into vi_count from WM_MIS_TSENDLIST where FCLS='配货通知单';
if vi_count=0 then
Insert into WM_MIS_TSENDLIST(FSENDTIME,FCLS,FNOTE,FSRCORG,FDESTORG,FDELTIME)
values(vd_Date,'配货通知单',null,'HSCMP','WMS1',null);
else
update WM_MIS_TSENDLIST set FSENDTIME=vd_Date where FCLS='配货通知单';
end if;
end if;
/*=================处理WSL单================*/
if ps_YwType in ('1601') then
ps_Message:='从海信系统导出单据失败:产生批发单('||ps_BillNo||')导出数据失败!';
delete from MIS_WM_TALCNTC where NUM=ps_BillNo;
Insert into MIS_WM_TALCNTC(NUM,FSTORECODE,FALCREASON,FSRC,FWRH,FFILLER,FCREATETIME,
FSENDTIME,FALCTIME,FMEMO,FSRCORG,FDESTORG,FCLS,FISQUICK)
select H.BIllNo,H.Etpcode,'统配正常','HSCMP','01',H.Usercode,H.Lrdate,vd_Date,
vd_Date,H.Remark,'HSCMP','WMS1','0','0'
from tWslXsHead H
where H.BillNo=ps_BillNo
and H.TjDate is null;
Insert into MIS_WM_TALCNTCDTL(num,LINE,FARTICLE,FARTICLECODE,FQTY,FPRICE,FSENDTIME,FMEMO,
FSRCORG,FDESTORG,FWRHCARD,FALCPRICE,FSTOREPRICE,FPRODUCEDATE,FDIRECT)
select 'W' || H.BillNo,B.Serialno,123,B.PluCode,B.Pfcount,B.Pfprice,vd_Date,B.Remark,'HSCMP','WMS1',
null,B.Pfprice,B.Pfprice,null,null
from tWslXsHead H,tWslXsBody B
where H.BillNo=B.BillNo and H.BillNo=ps_BillNo
and H.TjDate is null;
select count(*) into vi_count from WM_MIS_TSENDLIST where FCLS='配货通知单';
if vi_count=0 then
Insert into WM_MIS_TSENDLIST(FSENDTIME,FCLS,FNOTE,FSRCORG,FDESTORG,FDELTIME)
values(vd_Date,'配货通知单',null,'HSCMP','WMS1',null);
else
update WM_MIS_TSENDLIST set FSENDTIME=vd_Date where FCLS='配货通知单';
end if;
end if;
/*=================处理rtn单================*/
if ps_YwType='2004' then
ps_Message:='从海信系统导出单据失败:产生配送退货单('||ps_BillNo||')导出数据失败!';
delete from MIS_WM_TSTORERTNNTC where NUM=ps_BillNo;
insert into MIS_WM_TSTORERTNNTC(NUM,FSTORECODE,FRTNDATE,FSRC,FFILLER,FWRH,FCREATETIME,
FSENDTIME,FCASEBARCODE,FRTNREASON,FSRCORG,FDESTORG,FMEMO)
select H.BillNo,H.ORGCODE,H.Lrdate,'HSCMP',H.Usercode,'02',sysdate,sysdate,null,null,
'HSCMP','WMS1',null
from tDstRtnHead H
where H.BillNo=ps_BillNo and H.TjDate is null;
delete from MIS_WM_TSTORERTNNTCDTL where NUM=ps_BillNo;
insert into MIS_WM_TSTORERTNNTCDTL(Num,LINE,FARTICLE,FARTICLECODE,FQTY,FPRICE,FVENDOR,FVENDORCODE,
FSENDTIME,FRTNREASON,FSRCORG,FDESTORG,FALCNTC)
select H.BillNo,B.SerialNo,123,B.Plucode,B.Thcount,B.Thprice,0,'0',sysdate,null,'HSCMP','WMS1',null
from tDstRtnHead H,tDstRtnBody B
where H.BillNo=B.BillNo and H.BillNo=ps_BillNo
and H.TjDate is null;
select count(*) into vi_count from WM_MIS_TSENDLIST where FCLS='门店退货通知单';
if vi_count=0 then
Insert into WM_MIS_TSENDLIST(FSENDTIME,FCLS,FNOTE,FSRCORG,FDESTORG,FDELTIME)
values(vd_Date,'门店退货通知单',null,'HSCMP','WMS1',null);
else
update WM_MIS_TSENDLIST set FSENDTIME=vd_Date where FCLS='门店退货通知单';
end if;
end if;
/*=================处理退货单================*/
if ps_YwType='0914' then
ps_Message:='从海信系统导出单据失败:产生采购退货单('||ps_BillNo||')导出数据失败!';
delete from MIS_WM_TVENDORRTNNTC where NUM=ps_BillNo;
insert into MIS_WM_TVENDORRTNNTC(NUM,FVENDOR,FVDRCODE,FRTNDATE,FCLS,FSRC,FWRH,FFILLER,
FCREATETIME,FSENDTIME,FSRCORG,FDESTORG,FMEMO)
select H.BillNo,456,H.Supcode,H.Lrdate,'退供应商','HSCMP','02',H.Usercode,sysdate,sysdate,
'HSCMP','WMS1',null
from tOrdThHead H
where H.BillNo=ps_BillNo and H.TjDate is null;
delete from MIS_WM_TVENDORRTNNTCDTL where NUM=ps_BillNo;
insert into MIS_WM_TVENDORRTNNTCDTL(NUM,LINE,FARTICLE,FARTICLECODE,FQTY,FPRICE,
FSENDTIME,FSRCORG,FDESTORG)
select H.BillNo,B.Serialno,123,B.PluCode,B.Thcount,B.Hjprice,sysdate,'HSCMP','WMS1'
from tOrdThHead H,tOrdThBody B
where H.BillNo=B.BillNo and H.BillNo=ps_BillNo
and H.TjDate is null;
select count(*) into vi_count from WM_MIS_TSENDLIST where FCLS='供应商退货通知单';
if vi_count=0 then
Insert into WM_MIS_TSENDLIST(FSENDTIME,FCLS,FNOTE,FSRCORG,FDESTORG,FDELTIME)
values(vd_Date,'供应商退货通知单',null,'HSCMP','WMS1',null);
else
update WM_MIS_TSENDLIST set FSENDTIME=vd_Date where FCLS='供应商退货通知单';
end if;
end if;
/*=================处理Shop退货单================*/
if ps_YwType='0912' then
ps_Message:='从海信系统导出单据失败:产生门店退货单('||ps_BillNo||')导出数据失败!';
delete from MIS_WM_TSTORERTNNTC where NUM=ps_BillNo;
insert into MIS_WM_TSTORERTNNTC(NUM,FSTORECODE,FRTNDATE,FSRC,FFILLER,FWRH,FCREATETIME,
FSENDTIME,FCASEBARCODE,FRTNREASON,FSRCORG,FDESTORG,FMEMO)
select H.BillNo,H.ORGCODE,H.Lrdate,'HSCMP',H.Usercode,'02',sysdate,sysdate,null,null,
'HSCMP','WMS1',null
from tOrdThHead H
where H.BillNo=ps_BillNo and H.TjDate is null;
delete from MIS_WM_TSTORERTNNTCDTL where NUM=ps_BillNo;
insert into MIS_WM_TSTORERTNNTCDTL(Num,LINE,FARTICLE,FARTICLECODE,FQTY,FPRICE,FVENDOR,FVENDORCODE,
FSENDTIME,FRTNREASON,FSRCORG,FDESTORG,FALCNTC)
select H.BillNo,B.SerialNo,123,B.Plucode,B.Thcount,B.Hjprice,0,'0',sysdate,null,'HSCMP','WMS1',null
from tOrdThHead H,tOrdThBody B
where H.BillNo=B.BillNo and H.BillNo=ps_BillNo
and H.TjDate is null;
select count(*) into vi_count from WM_MIS_TSENDLIST where FCLS='门店退货通知单';
if vi_count=0 then
Insert into WM_MIS_TSENDLIST(FSENDTIME,FCLS,FNOTE,FSRCORG,FDESTORG,FDELTIME)
values(vd_Date,'门店退货通知单',null,'HSCMP','WMS1',null);
else
update WM_MIS_TSENDLIST set FSENDTIME=vd_Date where FCLS='门店退货通知单';
end if;
end if;
/*=================更新单据状态================*/
if ps_YwType in ('2003','2007','0914','2004','0912','1601') then
ps_Message:='从海信系统导出单据失败:更新业务单据('||ps_BillNo||')状态失败!';
vs_SQL:=' update '||vs_TBN||
' set TjrID=:mm_UserId,TjrCode=:mm_UserCode, '||
' TjrName=:mm_UserName,TjDate=:mm_Date, '||
' DataStatus=''9'' '||
' where BillNo=:mm_BillNo ';
execute immediate (vs_SQL)
using pi_UserId,ps_UserCode,ps_UserName,
pd_Date,ps_BillNo;
end if;
/*=================pi_Result=2end记账过程================*/
if ps_YwType in ('2003','2007','0914','2004','0912','1601') then
pi_Result:=2;
ps_Message:='从海信系统导出单据成功!';
return;
end if;
/*=================成功退出================*/
<<GetWlBillData>>
pi_Result:=1;
ps_Message:='从海信系统导出单据成功!';
Exception
When Others then
begin
pi_Result:=-1;
ps_Message:=substr(nvl(ps_Message,'从海信系统导出单据时发生未知错误:')||Sqlerrm,1,2000);
if vc_Data%isopen then close vc_Data; end if;
return;
end;
End GetWlBillData;
--功能:Jh结果接收记账
procedure Set_OrdCg
(ps_BillNo in tOrdJhHead.BillNo%type,
pr_User PHSCWMS_VAR.P_UsrUser_RecType,
pd_JzDate IN date,
pi_Result Out integer,
ps_Message Out varchar2)
Is
cursor CurHSC_GetCGBillNo is
select FSRCORDNUM as CgBillNo
from WM_MIS_TSTKNORD
where FSRCORDNUM=ps_BillNo
for update;
cursor CurHSC_GetCk(ms_OrgCode tStkStore.OrgCode%type) is
select CkCode,CkName
from tStkStore
where OrgCode=ms_OrgCode
and KcType='0'
and rownum=1;
cursor CurHSC_CheckCgCount is
select '采购验收单('||ps_BillNo||')信息接收失败:商品'||B.FARTICLECODE||'-'||C.PluName||'的实际采购数量'||
to_char(B.FQTY)||'不允许大于原单据采购数量'||to_char(C.CgCount)
from WM_MIS_TSTKNORD A,WM_MIS_TSTKNORDDTL B, tOrdCgBody C
where A.NUM=B.NUM
and A.FSRCORDNUM=ps_BillNo
and A.FSRCORDNUM=C.BillNo
and B.LINE=C.SerialNo
and B.FQTY>C.CgCount;
Cursor Cur_CgHD is
Select OrgCode,CntID,PsType,PsCntID,HOrgCode,CgType,DepId,DepCode,DepName,
Nvl((Select IsLast from tOrgDept Where DepId=A.DepId),'0') as IsLast,
Nvl((Select OrgType from tOrgManage where OrgCode=A.YsOrgCode),'*') as OrgType
From tOrdCgHead A
Where BillNo=ps_BillNo
and JzDate is not null and YwStatus in ('0','1');
Rec_CgHD Cur_CgHD%rowtype;
Cursor Cur_CgBD is
Select SerialNo,PluID,HJPrice, WJPrice
From tOrdCgBody
Where BillNo=ps_BillNo and ZsType='0';
Rec_CgBD Cur_CgBD%rowtype;
vs_YwType tOrdCgHead.YwType%type;
vs_CkCode tStkStore.Ckcode%type;
vs_CkName Tstkstore.CkName%type;
vs_InOrgCode tOrgManage.InOrgCode%type;
vs_OrgCode tOrgManage.OrgCode%type;
vs_BillNo tOrdCgHead.BillNo%type;
vs_Ord_CgJhUseCgJPrice varchar2(20);
vs_IsCntPrice varchar2(1);
vf_HJPrice tOrdCgBody.HJPrice%type;
vf_WJPrice tOrdCgBody.WJPrice%type;
vs_JTaxCalType tSkuPlu.Jtaxcaltype%type;
vs_JhDate varchar2(10);
vs_PriceType varchar2(10);
vi_JTaxRate tSkuPlu.JTaxRate%Type;
vs_CgBillNo varchar2(20);
Begin
/*==========初始化变量================*/
pi_Result:=-1;
ps_Message:='采购验收单('||ps_BillNo||')信息接收处理失败:初始化变量';
vs_YwType:='0905';
ps_Message:='采购验收单('||ps_BillNo||')信息接收处理失败:取得总部信息失败';
select OrgCode,InOrgCode into vs_OrgCode,vs_InOrgCode from tOrgManage where OrgType='1001';
/*==========取得总部的正品仓库================*/
ps_Message:='采购验收单('||ps_BillNo||')信息接收处理失败:没有取得正品仓库';
if CurHSC_GetCk%isopen then close CurHSC_GetCk; end if;
open CurHSC_GetCk(vs_InOrgCode);
fetch CurHSC_GetCk into vs_CkCode,vs_CkName;
if CurHSC_GetCk%notfound then
if CurHSC_GetCk%isopen then close CurHSC_GetCk; end if;
return;
end if;
if CurHSC_GetCk%isopen then close CurHSC_GetCk; end if;
/*==========检查合法性================*/
if PSTO.IsExistsData('select 1 as MyData from tOrdJhHead where BillNo='''||ps_BillNo||''' for update') then
ps_Message:='采购验收单('||ps_BillNo||')信息接收处理失败:此验收单已存在!';
return;
end if;
ps_Message:='采购验收单('||ps_BillNo||')信息接收处理失败:在接收表中没有数据';
if CurHSC_GetCGBillNo%isopen then close CurHSC_GetCGBillNo; end if;
open CurHSC_GetCGBillNo;
fetch CurHSC_GetCGBillNo into vs_CGBillNo;
if CurHSC_GetCGBillNo%notfound then
if CurHSC_GetCGBillNo%isopen then close CurHSC_GetCGBillNo; end if;
return;
end if;
if CurHSC_GetCGBillNo%isopen then close CurHSC_GetCGBillNo; end if;
Sys_CheckData(Ps_BillNo,'WM_MIS_TSTKNORDDTL',vs_CGBillNo,'tOrdCgBody',pi_Result,ps_Message);
if pi_Result<>1 then return; end if;
pi_Result:=-1;
ps_Message:='采购验收单('||ps_BillNo||')信息接收处理失败:商品实际采购数量不允许大于原单据采购数量';
if CurHSC_CheckCgCount%isopen then close CurHSC_CheckCgCount; end if;
open CurHSC_CheckCgCount;
fetch CurHSC_CheckCgCount into ps_Message;
if CurHSC_CheckCgCount%found then
if CurHSC_CheckCgCount%isopen then close CurHSC_CheckCgCount; end if;
return;
end if;
if CurHSC_CheckCgCount%isopen then close CurHSC_CheckCgCount; end if;
sSysGetBillNo('0904',vs_BillNo);
if nvl(vs_BillNo,'*')='*' then return; end if;
Delete from tOrdCgBody_JhPrice where billno = ps_BillNo;
Insert Into tOrdCgBody_JhPrice
(billno, serialno, pluid, plucode, pluname, explucode, expluname,
barcode, spec, unit, cargono, depid, depcode, depname, hjprice,
wjprice, psprice, lhjprice, lwjprice, discountrate, price, jtaxrate,
packunit, packqty, packcount, sglcount, cgcount, cghcost, cgwcost,
cgjtaxtotal, pscost, stotal, cjtotal, sdcount, zscount, remark,
pricetype, jdrate, qrcount, zstype, tag, tpheight, tplong,jpricetype,plutype)
select billno, rownum as serialno, pluid, plucode, pluname, explucode, expluname,
barcode, spec, unit, cargono, depid, depcode, depname, hjprice,
wjprice, psprice, lhjprice, lwjprice, discountrate, price, jtaxrate,
packunit, packqty, packcount, sglcount, cgcount, cghcost, cgwcost,
cgjtaxtotal, pscost, stotal, cjtotal, sdcount, zscount, remark,
pricetype, jdrate, qrcount, zstype, tag, tpheight, tplong,'0',plutype
from tordcgbody
where billno = ps_BillNo;
Open Cur_CgHD;
Fetch Cur_CgHD into Rec_CgHD;
Close Cur_CgHD;
--得到选项"采购验收时价格取自采购单"
vs_Ord_CgJhUseCgJPrice:=Nvl(fGetSysOptionValue('*','ORD','Ord_CgJhUseCgJPrice'),'1');
select Nvl(IsMngJPrice,'1') into vs_IsCntPrice from tcntcontract where cntid = (select cntid from tordcghead where billno = ps_BillNo);
If (vs_Ord_CgJhUseCgJPrice='0') and (vs_IsCntPrice='1') then
--更新采购单中的价格
vs_JhDate := to_char(sysdate, 'YYYY-MM-DD');
Open Cur_CgBD;
Loop
Fetch Cur_CgBD into Rec_CgBD;
Exit When Cur_CgBD%NotFound;
--取得商品进价
sCnt_GetPluJPrice(Rec_CgHD.OrgCode, Rec_CgHD.HOrgCode, Rec_CgHD.CntId, Rec_CgBD.PluId, vs_JhDate,
vf_HJPrice, vf_WJPrice, vi_JTaxRate, vs_JTaxCalType, vs_PriceType,
pi_Result, ps_Message);
if (pi_Result='1') then
Update tOrdCgBody_JhPrice
Set JPriceType=vs_PriceType
Where BillNo=ps_BillNo and SerialNo=Rec_CgBD.Serialno;
end if;
If (pi_Result='1') and ((vf_HJPrice<>Rec_CgBD.HJPrice) or (vf_WJPrice<>Rec_CgBD.WJPrice)) then
Update tOrdCgBody_JhPrice
Set HJPrice=vf_HJPrice,WJPrice=vf_WJPrice,
PsPrice=Case When (Rec_CgHD.PsType='2') and (Rec_CgHD.PsCntID=0 or PriceType in ('1','4'))
then vf_HJPrice
When (Rec_CgHD.PsType='2') and (PriceType in ('2'))
then vf_HJPrice*(1+JdRate/100.0)
Else PsPrice
End,
CgHCost=Round(vf_HJPrice*CgCount,2),
CgWCost=Case When vs_JTaxCalType='0' then
Round(Round(vf_HJPrice*CgCount,2)/(1+JTaxRate/100),2)
Else Round(Round(vf_HJPrice*CgCount,2)*(1-JTaxRate/100),2)
End,
JTaxRate=vi_JTaxRate
--JPriceType=vs_PriceType
Where BillNo=ps_BillNo and SerialNo=Rec_CgBD.Serialno;
Update tOrdCgBody_JhPrice
Set CgJTaxTotal=CgHCost-CgWCost,
CjTotal=STotal-CgHCost,
PsCost=Round(PsPrice*CgCount,2)
Where BillNo=ps_BillNo and SerialNo=Rec_CgBD.Serialno;
End If;
End Loop;
Close Cur_CgBD;
End If;
/*==========验收单生成================*/
ps_Message:='采购单('||ps_BillNo||')信息验收接收处理失败'||':生成验收单主表失败!';
insert into tOrdJhHead(BillNo,LrDate,UserID,UserCode,UserName,IsNeedTjWl,
JzType,YwType,YwIOType,YsPluType, OrgCode,OrgName,InOrgCode,
HOrgCode,HOrgName,DepId,DepCode,DepName,ZbOrgCode,ZbOrgName,
SupCode,SupName,CntID,HtCode,HtName,JyMode,JsCode,CkCode,CkName,
RefBillType,RefBillNo,YsrId,YsrCode,YsrName,IsFp,Remark,
DataStatus,IsYkYs)
select vs_BillNo,pd_JzDate,pr_User.UserId,pr_User.UserCode,pr_User.UserName,'0',
'0',vs_YwType,'1','0',
A.YsOrgCode,A.YsOrgName,A.InOrgCode,A.HOrgCode,A.HOrgName,
A.DepId,A.DepCode,A.DepName,C.OrgCode,C.OrgName,A.SupCode,A.SupName,
A.CntId,A.HtCode,A.HtName,A.JyMode,A.JsCode,vs_CkCode,vs_CkName,
'0902',ps_BillNo,pr_User.UserId,pr_User.UserCode,pr_User.UserName,
'0',A.Remark,'0',decode(A.PsType,'1','1','0') As IsYkYs
from tOrdCgHead A,tOrgManage B,tOrgManage C
where A.BillNo=ps_BillNo and A.HOrgCode=B.OrgCode
and B.ZbOrgCode=C.OrgCode;
ps_Message:='采购验收单('||ps_BillNo||')信息接收处理失败'||':生成验收单明细失败!';
insert into TORDJHBODY(BillNo,SerialNo,ToSerialNo,PluID,PluCode,PluName,
ExPluCode,ExPluName,BarCode,Spec,Unit,CargoNo,PluType,
DepId,DepCode,DepName,HJPrice,WJPrice,Price,JTaxRate,
PackUnit,PackQty,PackCount,SglCount,JhCount,
HCost,WCost,JTaxTotal,STotal,CjTotal,CjRate,ScDate,
BzDays,Remark,JTaxCalType,DqDate)
select vs_BillNo,rownum,B.SerialNo,B.PluId,B.PluCode,B.PluName,
B.ExPluCode,B.ExPluName,B.BarCode,B.Spec,B.Unit,B.CargoNo,B.PluType,
B.DepId,B.DepCode,B.DepName,B.HJPrice,B.WJPrice,B.Price,B.JTaxRate,
B.PackUnit,B.PackQty,
(case when B.PackQty<=0 or B.PackQty=1 then 0
else Floor(H.FQTY/B.PackQty) end) As PackCount,
(case when B.PackQty<=0 or B.PackQty=1 then H.FQTY
else H.FQTY-Floor(H.FQTY/B.PackQty)*B.PackQty
end) As SglCount,H.FQTY,
Round(H.FQTY*B.HJPrice,2),--Host
Case When P.JTaxCalType='0' then--WHost
Round(Round(B.HJPrice*H.FQTY,2)/(1+B.JTaxRate/100),2)
Else Round(Round(B.HJPrice*H.FQTY,2)*(1-B.JTaxRate/100),2)
End,
Round(H.FQTY*B.HJPrice,2)- Case When P.JTaxCalType='0' then --JTaxTotal
Round(Round(B.HJPrice*H.FQTY,2)/(1+B.JTaxRate/100),2)
Else Round(Round(B.HJPrice*H.FQTY,2)*(1-B.JTaxRate/100),2)
End,
Round(H.FQTY*B.Price,2),--STotal
Round(H.FQTY*B.Price,2)-Round(H.FQTY*B.HJPrice,2),--CjTotal
case when (B.Price*H.FQTY=0) or ((B.Price*H.FQTY-B.HjPrice*H.FQTY)=0) then
0
else
Round(((B.Price-B.HjPrice)/B.Price)*100,2)
end,
'',
0,null,P.JTAXCALTYPE,''
from WM_MIS_TSTKNORDDTL H,tOrdCgBody_JhPrice B,tSkuPlu P
where H.FSRCORDNUM=ps_BillNo
and H.FSRCORDNUM=B.BillNo and H.LINE=B.Serialno
and B.PluId=P.PluId;
ps_Message:='采购单('||ps_BillNo||')信息验收接收处理失败'||':更新验收单主表的合计数量失败!';
update tOrdJhHead
set (JhCount,HCost,WCost,JTaxTotal,STotal,CjTotal)=
(select sum(JhCount),sum(HCost),sum(WCost),
sum(JTaxTotal),sum(STotal),sum(CjTotal)
from tOrdJhBody
where BillNo=vs_BillNo)
where BillNo=vs_BillNo;
/*==========验收单记账================*/
/* sStk_Commit_Jh_ORA(vs_BillNo,vs_YwType,pr_User.UserId,pr_User.UserCode,pr_User.UserName,
pd_JzDate,pi_Result,ps_Message);
if pi_Result<>1 then
ps_Message:='采购单('||ps_BillNo||')信息验收接收处理失败'||':记账失败。原因:'||ps_Message;
return;
end if; */
/*==========转移数据到历史表================*/
pi_Result:=-1;
IO_MovHis(ps_BillNo,'WM_MIS_TSTKNORD',pi_Result,ps_Message);
if pi_Result<>1 then return; end if;
pi_Result:=-1;
IO_MovHis(ps_BillNo,'WM_MIS_TSTKNORDDTL',pi_Result,ps_Message);
if pi_Result<>1 then return; end if;
/*==========*成功================*/
pi_Result:=1;
ps_Message:='采购验收信息接收成功';
Exception
When Others then
begin
pi_Result:=-1;
ps_Message:=substr(nvl(ps_Message,'采购验收信息接收失败!')||'发生位置:'||Sqlerrm,1,2000);
if CurHSC_GetCk%isopen then close CurHSC_GetCk; end if;
if CurHSC_GetCGBillNo%isopen then close CurHSC_GetCGBillNo; end if;
if CurHSC_CheckCgCount%isopen then close CurHSC_CheckCgCount; end if;
return;
end;
End Set_OrdCg;
--功能:Ord退货结果接收记账
procedure Set_OrdTh
(ps_BillNo in tOrdJhHead.BillNo%type,
pr_User PHSCWMS_VAR.P_UsrUser_RecType,
pd_JzDate IN date,
pi_Result Out integer,
ps_Message Out varchar2)
Is
cursor CurHSC_GetIOData is
select A.FSRCNUM as BillNo,B.LINE as SerialNo,B.FARTICLECODE as PluCode,
'0' as PluType,B.FREALQTY as ThCount,null as Remark
from WM_MIS_TVENDORRTN A,WM_MIS_TVENDORRTNDTL B
where A.NUM=B.NUM
and A.FSRCNUM=ps_BillNo
for update;
cursor CurHSC_CheckOrdTh is
select '采购退货('||ps_BillNo||')不存在或已记账!'
from tOrdThHead
where BillNo=ps_BillNo
and TjDate is not null
and JzDate is null
for update;
cursor CurHSC_CheckThCount is
select '采购退货('||ps_BillNo||')信息接收失败:商品'||C.FARTICLECODE||'的实际退货数量'||
to_char(C.FREALQTY)||'不允许大于原单据退货数量'||to_char(B.ThCount)
from WM_MIS_TVENDORRTN A, tOrdThBody B,WM_MIS_TVENDORRTNDTL C
where A.NUM=C.NUM
and A.FSRCNUM=ps_BillNo
and A.FSRCNUM=B.BillNo
and C.LINE=B.SerialNo
and C.FREALQTY>B.ThCount;
vs_YwType tOrdJhHead.YwType%type;
vs_IoHasRec varchar2(1);
vs_IsAllZero varchar2(1);
Begin
/*==========初始化变量==================*/
pi_Result:=-1;
ps_Message:='采购退货('||ps_BillNo||')信息接收失败:初始化变量';
vs_YwType:='0914';
/*==========合法性判断==================*/
/* Sys_CheckData(Ps_BillNo,'WM_MIS_TVENDORRTNDTL',ps_BillNo,'tOrdThBody',pi_Result,ps_Message);
if pi_Result<>1 then return; end if;
pi_Result:=-1; */
ps_Message:='采购退货('||ps_BillNo||')信息接收失败:采购单不存在或已记账!';
if CurHSC_CheckOrdTh%isopen then close CurHSC_CheckOrdTh; end if;
open CurHSC_CheckOrdTh;
fetch CurHSC_CheckOrdTh into ps_Message;
if CurHSC_CheckOrdTh%notfound then
if CurHSC_CheckOrdTh%isopen then close CurHSC_CheckOrdTh; end if;
return;
end if;
if CurHSC_CheckOrdTh%isopen then close CurHSC_CheckOrdTh; end if;
ps_Message:='采购退货('||ps_BillNo||')信息接收失败:商品实际退货数量不允许大于原单据退货数量';
if CurHSC_CheckThCount%isopen then close CurHSC_CheckThCount; end if;
open CurHSC_CheckThCount;
fetch CurHSC_CheckThCount into ps_Message;
if CurHSC_CheckThCount%found then
if CurHSC_CheckThCount%isopen then close CurHSC_CheckThCount; end if;
return;
end if;
if CurHSC_CheckThCount%isopen then close CurHSC_CheckThCount; end if;
/*==========更新采购退货单明细失败==================*/
ps_Message:='采购退货('||ps_BillNo||')信息接收失败:更新采购退货单明细发生错误!';
vs_IoHasRec:='0';
vs_IsAllZero:='1';
for vr_B in CurHSC_GetIOData
Loop
if vr_B.ThCount<>0 then
vs_IsAllZero:='0';
end if;
vs_IoHasRec:='1';
update tOrdThBody B
set (PluCode,ThCount,HCost,WCost,JTaxTotal,STotal,CjTotal,CjRate,Remark,
B.PackCount,SglCount)=
(select vr_B.PluCode,vr_B.ThCount,
Round(vr_B.ThCount*B.HJPrice,2),--Host
Case When P.JTaxCalType='0' then--WHost
Round(Round(B.HJPrice*vr_B.ThCount,2)/(1+B.JTaxRate/100),2)
Else Round(Round(B.HJPrice*vr_B.ThCount,2)*(1-B.JTaxRate/100),2)
End,
Round(vr_B.ThCount*B.HJPrice,2)- Case When P.JTaxCalType='0' then --JTaxTotal
Round(Round(B.HJPrice*vr_B.ThCount,2)/(1+B.JTaxRate/100),2)
Else Round(Round(B.HJPrice*vr_B.ThCount,2)*(1-B.JTaxRate/100),2)
End,
Round(vr_B.ThCount*B.Price,2),--STotal
Round(vr_B.ThCount*B.Price,2)-Round(vr_B.ThCount*B.HJPrice,2),--CjTotal
case when (B.Price*vr_B.ThCount=0) or ((B.Price*vr_B.ThCount-B.HjPrice*vr_B.ThCount)=0) then
0
else
Round(((B.Price-B.HjPrice)/B.Price)*100,2)
end,
vr_B.Remark,
(case when B.PackQty<=0 or B.PackQty=1 then 0