forked from hechenqingyuan/gitwms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitwms.sql
3086 lines (2862 loc) · 339 KB
/
gitwms.sql
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
USE [JooWMS]
GO
/****** Object: Table [dbo].[TNum] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[TNum]
GO
/****** Object: Table [dbo].[SysRole] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[SysRole]
GO
/****** Object: Table [dbo].[SysResource] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[SysResource]
GO
/****** Object: Table [dbo].[SysRelation] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[SysRelation]
GO
/****** Object: Table [dbo].[SysDepart] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[SysDepart]
GO
/****** Object: Table [dbo].[Supplier] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[Supplier]
GO
/****** Object: Table [dbo].[Storage] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[Storage]
GO
/****** Object: Table [dbo].[Sequence] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[Sequence]
GO
/****** Object: Table [dbo].[ReturnOrder] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[ReturnOrder]
GO
/****** Object: Table [dbo].[ReturnDetail] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[ReturnDetail]
GO
/****** Object: Table [dbo].[Reports] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[Reports]
GO
/****** Object: Table [dbo].[ReportParams] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[ReportParams]
GO
/****** Object: Table [dbo].[ProductCategory] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[ProductCategory]
GO
/****** Object: Table [dbo].[Product] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[Product]
GO
/****** Object: Table [dbo].[OutStorage] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[OutStorage]
GO
/****** Object: Table [dbo].[OutStoDetail] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[OutStoDetail]
GO
/****** Object: Table [dbo].[MoveOrderDetail] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[MoveOrderDetail]
GO
/****** Object: Table [dbo].[MoveOrder] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[MoveOrder]
GO
/****** Object: Table [dbo].[MeasureRel] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[MeasureRel]
GO
/****** Object: Table [dbo].[Measure] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[Measure]
GO
/****** Object: Table [dbo].[Location] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[Location]
GO
/****** Object: Table [dbo].[LocalProduct] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[LocalProduct]
GO
/****** Object: Table [dbo].[InventoryBook] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[InventoryBook]
GO
/****** Object: Table [dbo].[InStorDetail] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[InStorDetail]
GO
/****** Object: Table [dbo].[InStorage] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[InStorage]
GO
/****** Object: Table [dbo].[Equipment] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[Equipment]
GO
/****** Object: Table [dbo].[Customer] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[Customer]
GO
/****** Object: Table [dbo].[CusAddress] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[CusAddress]
GO
/****** Object: Table [dbo].[CloneTemp] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[CloneTemp]
GO
/****** Object: Table [dbo].[CloneHistory] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[CloneHistory]
GO
/****** Object: Table [dbo].[CheckStockInfo] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[CheckStockInfo]
GO
/****** Object: Table [dbo].[CheckStock] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[CheckStock]
GO
/****** Object: Table [dbo].[CheckData] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[CheckData]
GO
/****** Object: Table [dbo].[BadReportDetail] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[BadReportDetail]
GO
/****** Object: Table [dbo].[BadReport] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[BadReport]
GO
/****** Object: Table [dbo].[Admin] Script Date: 2016-05-19 9:50:22 ******/
DROP TABLE [dbo].[Admin]
GO
/****** Object: StoredProcedure [dbo].[Proc_SwiftNum] Script Date: 2016-05-19 9:50:22 ******/
DROP PROCEDURE [dbo].[Proc_SwiftNum]
GO
/****** Object: StoredProcedure [dbo].[Proc_ReturnTOP10Num] Script Date: 2016-05-19 9:50:22 ******/
DROP PROCEDURE [dbo].[Proc_ReturnTOP10Num]
GO
/****** Object: StoredProcedure [dbo].[Proc_ProductReport] Script Date: 2016-05-19 9:50:22 ******/
DROP PROCEDURE [dbo].[Proc_ProductReport]
GO
/****** Object: StoredProcedure [dbo].[Proc_OutStorageReport] Script Date: 2016-05-19 9:50:22 ******/
DROP PROCEDURE [dbo].[Proc_OutStorageReport]
GO
/****** Object: StoredProcedure [dbo].[Proc_InStorageReport] Script Date: 2016-05-19 9:50:22 ******/
DROP PROCEDURE [dbo].[Proc_InStorageReport]
GO
/****** Object: StoredProcedure [dbo].[Proc_InOutStorageTOP10Num] Script Date: 2016-05-19 9:50:22 ******/
DROP PROCEDURE [dbo].[Proc_InOutStorageTOP10Num]
GO
/****** Object: StoredProcedure [dbo].[Proc_CreateCheck] Script Date: 2016-05-19 9:50:22 ******/
DROP PROCEDURE [dbo].[Proc_CreateCheck]
GO
/****** Object: StoredProcedure [dbo].[Proc_BadTOP10Num] Script Date: 2016-05-19 9:50:22 ******/
DROP PROCEDURE [dbo].[Proc_BadTOP10Num]
GO
/****** Object: StoredProcedure [dbo].[Proc_AuditeReturn] Script Date: 2016-05-19 9:50:22 ******/
DROP PROCEDURE [dbo].[Proc_AuditeReturn]
GO
/****** Object: StoredProcedure [dbo].[Proc_AuditeOutStorage] Script Date: 2016-05-19 9:50:22 ******/
DROP PROCEDURE [dbo].[Proc_AuditeOutStorage]
GO
/****** Object: StoredProcedure [dbo].[Proc_AuditeMove] Script Date: 2016-05-19 9:50:22 ******/
DROP PROCEDURE [dbo].[Proc_AuditeMove]
GO
/****** Object: StoredProcedure [dbo].[Proc_AuditeInStorage] Script Date: 2016-05-19 9:50:22 ******/
DROP PROCEDURE [dbo].[Proc_AuditeInStorage]
GO
/****** Object: StoredProcedure [dbo].[Proc_AuditeCheck] Script Date: 2016-05-19 9:50:22 ******/
DROP PROCEDURE [dbo].[Proc_AuditeCheck]
GO
/****** Object: StoredProcedure [dbo].[Proc_AuditeBadReport] Script Date: 2016-05-19 9:50:22 ******/
DROP PROCEDURE [dbo].[Proc_AuditeBadReport]
GO
/****** Object: StoredProcedure [dbo].[Proc_AuditeBadReport] Script Date: 2016-05-19 9:50:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Proc_AuditeBadReport]
(
@OrderNum VARCHAR(20),--入库单号
@Status int,--审核状态
@AuditUser nvarchar(20),--审核人编号
@Reason nvarchar(400), --审核成功或者失败的原因
@OperateType int, --操作方式 1 电脑 2 PDA
@EquipmentNum varchar(20), --设备编号[所使用的设备编号]
@EquipmentCode varchar(20), --设备条码[如果没有就直接设备编号]
@ReturnValue varchar(50) OUTPUT
)
AS
BEGIN
--判断报损单是否存在
IF NOT EXISTS ( SELECT COUNT(*) FROM BadReport WHERE OrderNum=@OrderNum AND IsDelete=0)
BEGIN
SET @ReturnValue='1001'
RETURN
END
--判断报损单是否已经被审核
IF NOT EXISTS ( SELECT COUNT(*) FROM BadReport WHERE OrderNum=@OrderNum AND Status=1 AND IsDelete=0)
BEGIN
SET @ReturnValue='1002'
RETURN
END
--开始事务
BEGIN TRANSACTION
--使用错误计数器
DECLARE @ERRORSUM INT
SET @ERRORSUM=0
DECLARE @ProductName nvarchar(100)
DECLARE @BarCode varchar(50)
DECLARE @ProductNum varchar(50)
DECLARE @BatchNum nvarchar(20)
DECLARE @Num float
DECLARE @FromLocalNum varchar(20)
DECLARE @StorageNum varchar(20)
DECLARE @ToLocalNum varchar(20)
DECLARE MyCursor CURSOR FOR SELECT [ProductName],[BarCode],[ProductNum],[BatchNum],[Num],[FromLocalNum],[StorageNum],[ToLocalNum] FROM BadReportDetail WHERE OrderNum=@OrderNum
OPEN MyCursor FETCH NEXT FROM MyCursor INTO @ProductName, @BarCode,@ProductNum,@BatchNum,@Num,@FromLocalNum,@StorageNum,@ToLocalNum
WHILE @@FETCH_STATUS = 0
BEGIN
--减少原库位的数量 -4 报损(移出)
IF(SELECT Num-@Num FROM LocalProduct WHERE ProductNum=@ProductNum AND BarCode=@BarCode AND StorageNum=@StorageNum AND LocalNum=@FromLocalNum AND BatchNum=@BatchNum)>=0
BEGIN
UPDATE LocalProduct SET Num=Num-@Num WHERE ProductNum=@ProductNum AND BarCode=@BarCode AND StorageNum=@StorageNum AND LocalNum=@FromLocalNum AND BatchNum=@BatchNum
SET @ERRORSUM=@ERRORSUM+@@ERROR
DELETE FROM LocalProduct WHERE ProductNum=@ProductNum AND BarCode=@BarCode AND StorageNum=@StorageNum AND LocalNum=@FromLocalNum AND BatchNum=@BatchNum AND Num=0
SET @ERRORSUM=@ERRORSUM+@@ERROR
--生成台账记录 -4 报损(移出)
INSERT INTO [dbo].[InventoryBook]([ProductNum],[BarCode],[ProductName],[BatchNum],[Num],[Type],[ContactOrder],[FromLocalNum],[ToLocalNum],[StoreNum],[CreateTime],[CreateUser])
VALUES(@ProductNum,@BarCode,@ProductName,@BatchNum,@Num,-4,@OrderNum,@FromLocalNum,@ToLocalNum,@StorageNum,GETDATE(),@AuditUser)
SET @ERRORSUM=@ERRORSUM+@@ERROR
END
ELSE
BEGIN
SET @ERRORSUM=@ERRORSUM+1
SET @ReturnValue='1004'
END
--目标库位是否存在该产品,如果存在则直接修改,不存在则增加 4 报损(移入)
IF(SELECT COUNT(*) FROM LocalProduct WHERE ProductNum=@ProductNum AND BarCode=@BarCode AND StorageNum=@StorageNum AND LocalNum=@ToLocalNum AND BatchNum=@BatchNum)>0
BEGIN
UPDATE LocalProduct SET Num=Num+@Num WHERE ProductNum=@ProductNum AND BarCode=@BarCode AND StorageNum=@StorageNum AND LocalNum=@ToLocalNum AND BatchNum=@BatchNum
SET @ERRORSUM=@ERRORSUM+@@ERROR
--生成台账记录
INSERT INTO [dbo].[InventoryBook]([ProductNum],[BarCode],[ProductName],[BatchNum],[Num],[Type],[ContactOrder],[FromLocalNum],[ToLocalNum],[StoreNum],[CreateTime],[CreateUser])
VALUES(@ProductNum,@BarCode,@ProductName,@BatchNum,@Num,4,@OrderNum,@FromLocalNum,@ToLocalNum,@StorageNum,GETDATE(),@AuditUser)
SET @ERRORSUM=@ERRORSUM+@@ERROR
END
ELSE
BEGIN
--获得SN流水号
DECLARE @SN varchar(50)
EXEC Proc_SwiftNum '','LocalProduct',@SN OUTPUT
DECLARE @StorageName nvarchar(50)
DECLARE @LocalName nvarchar(50)
DECLARE @LocalType int
DECLARE @UserName nvarchar(50)
SELECT TOP 1 @StorageName=StorageName FROM Storage WHERE StorageNum=@StorageNum
SELECT TOP 1 @LocalName=LocalName,@LocalType=LocalType FROM Location WHERE LocalNum=@ToLocalNum AND StorageNum=@StorageNum
SELECT TOP 1 @UserName=UserName FROM Admin WHERE UserCode=@AuditUser
SET @ERRORSUM=@ERRORSUM+@@ERROR
--新增一行记录
INSERT INTO [dbo].[LocalProduct]([Sn],[StorageNum],[StorageName],[LocalNum],[LocalName],[LocalType],[ProductNum],[BarCode],[ProductName],[BatchNum],[Num],[CreateTime],[CreateUser],[CreateName],[Remark])
VALUES(@SN,@StorageNum,@StorageName,@ToLocalNum,@LocalName,@LocalType,@ProductNum,@BarCode,@ProductName,@BatchNum,@Num,GETDATE(),@AuditUser,@UserName,'')
SET @ERRORSUM=@ERRORSUM+@@ERROR
--生成台账记录
INSERT INTO [dbo].[InventoryBook]([ProductNum],[BarCode],[ProductName],[BatchNum],[Num],[Type],[ContactOrder],[FromLocalNum],[ToLocalNum],[StoreNum],[CreateTime],[CreateUser])
VALUES(@ProductNum,@BarCode,@ProductName,@BatchNum,@Num,4,@OrderNum,@FromLocalNum,@ToLocalNum,@StorageNum,GETDATE(),@AuditUser)
SET @ERRORSUM=@ERRORSUM+@@ERROR
END
--进行下一个游标循环
FETCH NEXT FROM MyCursor INTO @ProductName, @BarCode,@ProductNum,@BatchNum,@Num,@FromLocalNum,@StorageNum,@ToLocalNum
END
CLOSE MyCursor
DEALLOCATE MyCursor--释放游标
--修改报损单状态
UPDATE BadReport SET Status=@Status,AuditUser=@AuditUser,AuditeTime=GETDATE(),Reason=@Reason,OperateType=@OperateType,
EquipmentNum=@EquipmentNum,EquipmentCode=@EquipmentCode
WHERE OrderNum=@OrderNum
SET @ERRORSUM=@ERRORSUM+@@ERROR
IF @ERRORSUM<>0
BEGIN
--回滚事务
ROLLBACK TRANSACTION
END
ELSE
BEGIN
SET @ReturnValue='1000'
--提交事务
COMMIT TRANSACTION
END
END
GO
/****** Object: StoredProcedure [dbo].[Proc_AuditeCheck] Script Date: 2016-05-19 9:50:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Proc_AuditeCheck]
(
@OrderNum VARCHAR(20),--入库单号
@Status int,--审核状态
@AuditUser nvarchar(20),--审核人编号
@Reason nvarchar(400), --审核成功或者失败的原因
@OperateType int, --操作方式 1 电脑 2 PDA
@EquipmentNum varchar(20), --设备编号[所使用的设备编号]
@EquipmentCode varchar(20), --设备条码[如果没有就直接设备编号]
@ReturnValue varchar(50) OUTPUT
)
AS
BEGIN
--开始事务
BEGIN TRANSACTION
--使用错误计数器
DECLARE @ERRORSUM INT
SET @ERRORSUM=0
--判断盘点单是否存在
IF NOT EXISTS ( SELECT COUNT(*) FROM CheckStock WHERE OrderNum=@OrderNum AND IsDelete=0)
BEGIN
SET @ReturnValue='1002'
RETURN
END
--判断盘点单是否已经审核
IF NOT EXISTS (SELECT COUNT(*) FROM CheckStock WHERE OrderNum=@OrderNum AND Status=1 AND IsDelete=0)
BEGIN
SET @ReturnValue='1003'
RETURN
END
--库存数据复核
DECLARE @ID INT
DECLARE @LocalNum VARCHAR(50)
DECLARE @LocalName NVARCHAR(50)
DECLARE @StorageNum VARCHAR(50)
DECLARE @ProductNum VARCHAR(50)
DECLARE @BarCode VARCHAR(50)
DECLARE @ProductName VARCHAR(50)
DECLARE @BatchNum VARCHAR(50)
DECLARE @LocalQty float
DECLARE @FirstQty float
DECLARE MyCursor CURSOR FOR SELECT [ID],[LocalNum],[LocalName],[StorageNum],[ProductNum],[BarCode],[ProductName],[BatchNum],[LocalQty],[FirstQty] FROM [dbo].[CheckData] WHERE OrderNum=@OrderNum
OPEN MyCursor FETCH NEXT FROM MyCursor INTO @ID,@LocalNum,@LocalName,@StorageNum,@ProductNum,@BarCode,@ProductName,@BatchNum,@LocalQty,@FirstQty
WHILE @@FETCH_STATUS = 0
BEGIN
--计算盘差量
DECLARE @DifQty float
SET @DifQty = @FirstQty-@LocalQty
UPDATE CheckData SET DifQty=@DifQty WHERE ID=@ID AND OrderNum=@OrderNum AND LocalNum=@LocalNum AND StorageNum=@StorageNum AND ProductNum=@ProductNum AND BarCode=@BarCode AND BatchNum=@BatchNum
SET @ERRORSUM=@ERRORSUM+@@ERROR
--判断是盘盈盘亏
DECLARE @CheckType INT
IF @DifQty >0
BEGIN
SET @CheckType=5
END
ELSE IF @DifQty <0
BEGIN
SET @CheckType=6
SET @DifQty=0-@DifQty
END
ELSE
BEGIN
SET @CheckType=0
END
-----复核数据
IF @CheckType>0
BEGIN
DELETE FROM LocalProduct WHERE LocalNum=@LocalNum AND StorageNum=@StorageNum AND ProductNum=@ProductNum AND BarCode=@BarCode
DECLARE @SN varchar(50)
EXEC Proc_SwiftNum '','LocalProduct',@SN OUTPUT
SET @ERRORSUM=@ERRORSUM+@@ERROR
DECLARE @StorageName nvarchar(50)
DECLARE @LocalType int
DECLARE @UserName nvarchar(50)
SELECT TOP 1 @StorageName=StorageName FROM Storage WHERE StorageNum=@StorageNum
SELECT TOP 1 @LocalName=LocalName,@LocalType=LocalType FROM Location WHERE LocalNum=@LocalNum AND StorageNum=@StorageNum
SELECT TOP 1 @UserName=UserName FROM Admin WHERE UserCode=@AuditUser
SET @ERRORSUM=@ERRORSUM+@@ERROR
INSERT INTO [dbo].[LocalProduct]([Sn],[StorageNum],[StorageName],[LocalNum],[LocalName],[LocalType],[ProductNum],[BarCode],[ProductName],[BatchNum],[Num],[CreateTime],[CreateUser],[CreateName],[Remark])
VALUES(@SN,@StorageNum,@StorageName,@LocalNum,@LocalName,@LocalType,@ProductNum,@BarCode,@ProductName,@BatchNum,@FirstQty,GETDATE(),@AuditUser,@UserName,'')
SET @ERRORSUM=@ERRORSUM+@@ERROR
---生成台账记录
INSERT INTO [dbo].[InventoryBook]([ProductNum],[BarCode],[ProductName],[BatchNum],[Num],[Type],[ContactOrder],[FromLocalNum],[ToLocalNum],[StoreNum],[CreateTime],[CreateUser])
VALUES(@ProductNum,@BarCode,@ProductName,@BatchNum,@DifQty,@CheckType,@OrderNum,@LocalNum,'',@StorageNum,GETDATE(),@AuditUser)
SET @ERRORSUM=@ERRORSUM+@@ERROR
END
--进行下一个游标循环
FETCH NEXT FROM MyCursor INTO @ID,@LocalNum,@LocalName,@StorageNum,@ProductNum,@BarCode,@ProductName,@BatchNum,@LocalQty,@FirstQty
END
CLOSE MyCursor
DEALLOCATE MyCursor--释放游标
--删除库存为零的数据
DELETE FROM [dbo].[LocalProduct] WHERE StorageNum=@StorageNum AND Num=0
SET @ERRORSUM=@ERRORSUM+@@ERROR
--修改库存状态
UPDATE CheckStock SET [Status]=@Status WHERE OrderNum=@OrderNum
SET @ERRORSUM=@ERRORSUM+@@ERROR
---结束事务
SET @ReturnValue='1000'
IF @ERRORSUM<>0
BEGIN
--回滚事务
ROLLBACK TRANSACTION
END
ELSE
BEGIN
--提交事务
COMMIT TRANSACTION
END
END
GO
/****** Object: StoredProcedure [dbo].[Proc_AuditeInStorage] Script Date: 2016-05-19 9:50:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Proc_AuditeInStorage]
(
@OrderNum VARCHAR(20),--入库单号
@Status int,--审核状态
@AuditUser nvarchar(20),--审核人编号
@Reason nvarchar(400), --审核成功或者失败的原因
@OperateType int, --操作方式 1 电脑 2 PDA
@EquipmentNum varchar(20), --设备编号[所使用的设备编号]
@EquipmentCode varchar(20), --设备条码[如果没有就直接设备编号]
@Remark nvarchar(400),--入库单描述
@ReturnValue varchar(50) OUTPUT
)
AS
BEGIN
--判断入库单是否存在
IF NOT EXISTS ( SELECT COUNT(*) FROM InStorage WHERE OrderNum=@OrderNum AND IsDelete=0)
BEGIN
SET @ReturnValue='1001'
RETURN
END
--判断入库单是否已经被审核 查询入库单等待审核是否存在
IF NOT EXISTS ( SELECT COUNT(*) FROM InStorage WHERE OrderNum=@OrderNum AND Status=1 AND IsDelete=0)
BEGIN
SET @ReturnValue='1002'
RETURN
END
--开始事务
BEGIN TRANSACTION
--使用错误计数器
DECLARE @ERRORSUM INT
SET @ERRORSUM=0
DECLARE @ProductName nvarchar(100)
DECLARE @BarCode varchar(50)
DECLARE @ProductNum varchar(50)
DECLARE @BatchNum nvarchar(20)
DECLARE @Num float
DECLARE @LocalNum varchar(20)
DECLARE @StorageNum varchar(20)
DECLARE MyCursor CURSOR FOR SELECT [ProductName],[BarCode],[ProductNum],[BatchNum],[Num],[LocalNum],[StorageNum] FROM InStorDetail WHERE OrderNum=@OrderNum
OPEN MyCursor FETCH NEXT FROM MyCursor INTO @ProductName, @BarCode,@ProductNum,@BatchNum,@Num,@LocalNum,@StorageNum
WHILE @@FETCH_STATUS = 0
BEGIN
--盘点库存是否存在
IF (SELECT COUNT(*) FROM LocalProduct WHERE ProductNum=@ProductNum AND StorageNum=@StorageNum AND LocalNum=@LocalNum AND BatchNum=@BatchNum)>0
BEGIN
--如果存在则修改相应的库存数量
UPDATE LocalProduct SET Num=Num+@Num WHERE ProductNum=@ProductNum AND StorageNum=@StorageNum AND LocalNum=@LocalNum AND BatchNum=@BatchNum
SET @ERRORSUM=@ERRORSUM+@@ERROR
END
ELSE
BEGIN
--如果不存在则添加
--获得SN流水号
DECLARE @SN varchar(50)
EXEC Proc_SwiftNum '','LocalProduct',@SN OUTPUT
DECLARE @StorageName nvarchar(50)
DECLARE @LocalName nvarchar(50)
DECLARE @LocalType int
DECLARE @UserName nvarchar(50)
SELECT TOP 1 @StorageName=StorageName FROM Storage WHERE StorageNum=@StorageNum
SELECT TOP 1 @LocalName=LocalName,@LocalType=LocalType FROM Location WHERE LocalNum=@LocalNum AND StorageNum=@StorageNum
SELECT TOP 1 @UserName=UserName FROM Admin WHERE UserCode=@AuditUser
SET @ERRORSUM=@ERRORSUM+@@ERROR
INSERT INTO [dbo].[LocalProduct]([Sn],[StorageNum],[StorageName],[LocalNum],[LocalName],[LocalType],[ProductNum],[BarCode],[ProductName],[BatchNum],[Num],[CreateTime],[CreateUser],[CreateName],[Remark])
VALUES(@SN,@StorageNum,@StorageName,@LocalNum,@LocalName,@LocalType,@ProductNum,@BarCode,@ProductName,@BatchNum,@Num,GETDATE(),@AuditUser,@UserName,'')
SET @ERRORSUM=@ERRORSUM+@@ERROR
END
--入库台账记录生成
INSERT INTO [dbo].[InventoryBook]([ProductNum],[BarCode],[ProductName],[BatchNum],[Num],[Type],[ContactOrder],[FromLocalNum],[ToLocalNum],[StoreNum],[CreateTime],[CreateUser])
VALUES(@ProductNum,@BarCode,@ProductName,@BatchNum,@Num,1,@OrderNum,'',@LocalNum,@StorageNum,GETDATE(),@AuditUser)
SET @ERRORSUM=@ERRORSUM+@@ERROR
--进行下一个游标循环
FETCH NEXT FROM MyCursor INTO @ProductName,@BarCode,@ProductNum,@BatchNum,@Num,@LocalNum,@StorageNum
END
CLOSE MyCursor
DEALLOCATE MyCursor--释放游标
--修改订单状态
UPDATE InStorage SET Status=@Status,AuditUser=@AuditUser,AuditeTime=GETDATE(),Reason=@Reason,OperateType=@OperateType,
EquipmentNum=@EquipmentNum,EquipmentCode=@EquipmentCode,Remark=@Remark
WHERE OrderNum=@OrderNum
SET @ERRORSUM=@ERRORSUM+@@ERROR
---结束事务
SET @ReturnValue='1000'
IF @ERRORSUM<>0
BEGIN
--回滚事务
ROLLBACK TRANSACTION
END
ELSE
BEGIN
--提交事务
COMMIT TRANSACTION
END
END
GO
/****** Object: StoredProcedure [dbo].[Proc_AuditeMove] Script Date: 2016-05-19 9:50:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Proc_AuditeMove]
(
@OrderNum VARCHAR(20),--入库单号
@Status int,--审核状态
@AuditUser nvarchar(20),--审核人编号
@Reason nvarchar(400), --审核成功或者失败的原因
@OperateType int, --操作方式 1 电脑 2 PDA
@EquipmentNum varchar(20), --设备编号[所使用的设备编号]
@EquipmentCode varchar(20), --设备条码[如果没有就直接设备编号]
@Remark nvarchar(400),--入库单描述
@ReturnValue varchar(50) OUTPUT
)
AS
BEGIN
--判断移库单是否存在
IF NOT EXISTS ( SELECT COUNT(*) FROM MoveOrder WHERE OrderNum=@OrderNum AND IsDelete=0)
BEGIN
SET @ReturnValue='1001'
RETURN
END
--判断移库单是否已经审核
IF NOT EXISTS ( SELECT COUNT(*) FROM MoveOrder WHERE OrderNum=@OrderNum AND Status=1 AND IsDelete=0)
BEGIN
SET @ReturnValue='1002'
RETURN
END
--开始事务
BEGIN TRANSACTION
--使用错误计数器
DECLARE @ERRORSUM INT
SET @ERRORSUM=0
DECLARE @ProductName nvarchar(100)
DECLARE @BarCode varchar(50)
DECLARE @ProductNum varchar(50)
DECLARE @BatchNum nvarchar(20)
DECLARE @Num float
DECLARE @FromLocalNum varchar(20)
DECLARE @ToLocalNum varchar(20)
DECLARE @StorageNum varchar(20)
DECLARE MyCursor CURSOR FOR
SELECT [ProductName],[BarCode],[ProductNum],[BatchNum],[Num],[StorageNum],[FromLocalNum],[ToLocalNum] FROM MoveOrderDetail WHERE OrderNum=@OrderNum
OPEN MyCursor FETCH NEXT FROM MyCursor INTO @ProductName,@BarCode,@ProductNum,@BatchNum,@Num,@StorageNum,@FromLocalNum,@ToLocalNum
WHILE @@FETCH_STATUS = 0
BEGIN
--减少原库位的数量
IF (SELECT Num-@Num FROM LocalProduct WHERE ProductNum=@ProductNum AND BarCode=@BarCode AND StorageNum=@StorageNum AND LocalNum=@FromLocalNum AND BatchNum=@BatchNum)>=0
BEGIN
UPDATE LocalProduct SET Num=Num-@Num WHERE ProductNum=@ProductNum AND BarCode=@BarCode AND StorageNum=@StorageNum AND LocalNum=@FromLocalNum AND BatchNum=@BatchNum
SET @ERRORSUM=@ERRORSUM+@@ERROR
--生成台账记录 -3 移库(移除)
INSERT INTO [dbo].[InventoryBook]([ProductNum],[BarCode],[ProductName],[BatchNum],[Num],[Type],[ContactOrder],[FromLocalNum],[ToLocalNum],[StoreNum],[CreateTime],[CreateUser])
VALUES(@ProductNum,@BarCode,@ProductName,@BatchNum,@Num,-3,@OrderNum,@FromLocalNum,@ToLocalNum,@StorageNum,GETDATE(),@AuditUser)
SET @ERRORSUM=@ERRORSUM+@@ERROR
END
ELSE
BEGIN
SET @ERRORSUM=@ERRORSUM+1
SET @ReturnValue='1004'
END
--盘点目标库位是否存在该产品,如果存在则直接修改,不存在则增加 3 移库(移入)
IF(SELECT COUNT(*) FROM LocalProduct WHERE ProductNum=@ProductNum AND BarCode=@BarCode AND StorageNum=@StorageNum AND LocalNum=@ToLocalNum AND BatchNum=@BatchNum)>0
BEGIN
UPDATE LocalProduct SET Num=Num+@Num WHERE ProductNum=@ProductNum AND BarCode=@BarCode AND StorageNum=@StorageNum AND LocalNum=@ToLocalNum AND BatchNum=@BatchNum
SET @ERRORSUM=@ERRORSUM+@@ERROR
--生成台账记录
INSERT INTO [dbo].[InventoryBook]([ProductNum],[BarCode],[ProductName],[BatchNum],[Num],[Type],[ContactOrder],[FromLocalNum],[ToLocalNum],[StoreNum],[CreateTime],[CreateUser])
VALUES(@ProductNum,@BarCode,@ProductName,@BatchNum,@Num,3,@OrderNum,@FromLocalNum,@ToLocalNum,@StorageNum,GETDATE(),@AuditUser)
SET @ERRORSUM=@ERRORSUM+@@ERROR
END
ELSE
BEGIN
--获得SN流水号
DECLARE @SN varchar(50)
EXEC Proc_SwiftNum '','LocalProduct',@SN OUTPUT
DECLARE @StorageName nvarchar(50)
DECLARE @LocalName nvarchar(50)
DECLARE @LocalType int
DECLARE @UserName nvarchar(50)
SELECT TOP 1 @StorageName=StorageName FROM Storage WHERE StorageNum=@StorageNum
SELECT TOP 1 @LocalName=LocalName,@LocalType=LocalType FROM Location WHERE LocalNum=@ToLocalNum AND StorageNum=@StorageNum
SELECT TOP 1 @UserName=UserName FROM Admin WHERE UserCode=@AuditUser
SET @ERRORSUM=@ERRORSUM+@@ERROR
--新增一行记录
INSERT INTO [dbo].[LocalProduct]([Sn],[StorageNum],[StorageName],[LocalNum],[LocalName],[LocalType],[ProductNum],[BarCode],[ProductName],[BatchNum],[Num],[CreateTime],[CreateUser],[CreateName],[Remark])
VALUES(@SN,@StorageNum,@StorageName,@ToLocalNum,@LocalName,@LocalType,@ProductNum,@BarCode,@ProductName,@BatchNum,@Num,GETDATE(),@AuditUser,@UserName,'')
SET @ERRORSUM=@ERRORSUM+@@ERROR
--生成台账记录
INSERT INTO [dbo].[InventoryBook]([ProductNum],[BarCode],[ProductName],[BatchNum],[Num],[Type],[ContactOrder],[FromLocalNum],[ToLocalNum],[StoreNum],[CreateTime],[CreateUser])
VALUES(@ProductNum,@BarCode,@ProductName,@BatchNum,@Num,3,@OrderNum,@FromLocalNum,@ToLocalNum,@StorageNum,GETDATE(),@AuditUser)
SET @ERRORSUM=@ERRORSUM+@@ERROR
END
--循环下一次游标
FETCH NEXT FROM MyCursor INTO @ProductName, @BarCode,@ProductNum,@BatchNum,@Num,@StorageNum,@FromLocalNum,@ToLocalNum
END
CLOSE MyCursor
DEALLOCATE MyCursor--释放游标
--修改订单状态
UPDATE MoveOrder SET Status=@Status,AuditUser=@AuditUser,AuditeTime=GETDATE(),Reason=@Reason,OperateType=@OperateType,
EquipmentNum=@EquipmentNum,EquipmentCode=@EquipmentCode
WHERE OrderNum=@OrderNum
SET @ERRORSUM=@ERRORSUM+@@ERROR
IF @ERRORSUM<>0
BEGIN
--回滚事务
ROLLBACK TRANSACTION
END
ELSE
BEGIN
SET @ReturnValue='1000'
--提交事务
COMMIT TRANSACTION
END
END
GO
/****** Object: StoredProcedure [dbo].[Proc_AuditeOutStorage] Script Date: 2016-05-19 9:50:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Proc_AuditeOutStorage]
(
@OrderNum VARCHAR(50),--入库单号
@Status int,--审核状态
@AuditUser nvarchar(50),--审核人编号
@Reason nvarchar(400), --审核成功或者失败的原因
@OperateType int, --操作方式 1 电脑 2 PDA
@EquipmentNum varchar(50), --设备编号[所使用的设备编号]
@EquipmentCode varchar(50), --设备条码[如果没有就直接设备编号]
@Remark nvarchar(400),--入库单描述
@ReturnValue varchar(50) OUTPUT
)
AS
BEGIN
--判断出库单是否存在
IF (SELECT COUNT(*) FROM OutStorage WHERE OrderNum=@OrderNum AND IsDelete=0 )=0
BEGIN
SET @ReturnValue='1001'
RETURN
END
--判断出库单是否已经被审核
IF NOT EXISTS ( SELECT COUNT(*) FROM OutStorage WHERE OrderNum=@OrderNum AND Status=1 AND IsDelete=0)
BEGIN
SET @ReturnValue='1002'
RETURN
END
--开始事务
BEGIN TRANSACTION
--使用错误计数器
DECLARE @ERRORSUM INT
SET @ERRORSUM=0
DECLARE @ProductName nvarchar(100)
DECLARE @BarCode varchar(50)
DECLARE @ProductNum varchar(50)
DECLARE @BatchNum nvarchar(50)
DECLARE @Num float
DECLARE @LocalNum varchar(50)
DECLARE @StorageNum varchar(50)
DECLARE MyCursor CURSOR FOR SELECT [ProductName],[BarCode],[ProductNum],[BatchNum],[Num],[LocalNum],[StorageNum] FROM OutStoDetail WHERE OrderNum= @OrderNum
OPEN MyCursor FETCH NEXT FROM MyCursor INTO @ProductName,@BarCode,@ProductNum,@BatchNum,@Num,@LocalNum,@StorageNum
WHILE @@FETCH_STATUS = 0
BEGIN
--盘点库存是否存在该产品
IF EXISTS (SELECT COUNT(*) FROM LocalProduct WHERE ProductNum=@ProductNum AND StorageNum=@StorageNum AND LocalNum=@LocalNum AND BatchNum=@BatchNum)
BEGIN
IF (SELECT Num-@Num FROM LocalProduct WHERE ProductNum=@ProductNum AND StorageNum=@StorageNum AND LocalNum=@LocalNum AND BatchNum=@BatchNum)>=0
BEGIN
--如果存在则修改相应的库存数量
UPDATE LocalProduct SET Num=Num-@Num WHERE ProductNum=@ProductNum AND StorageNum=@StorageNum AND LocalNum=@LocalNum AND BatchNum=@BatchNum
SET @ERRORSUM=@ERRORSUM+@@ERROR
DELETE FROM LocalProduct WHERE ProductNum=@ProductNum AND StorageNum=@StorageNum AND LocalNum=@LocalNum AND BatchNum=@BatchNum AND Num=0
SET @ERRORSUM=@ERRORSUM+@@ERROR
END
ELSE
BEGIN
SET @ERRORSUM=@ERRORSUM+1
SET @ReturnValue='1004'
END
END
ELSE
BEGIN
SET @ReturnValue='1003'
RETURN
END
--入库台账记录生成
INSERT INTO [dbo].[InventoryBook]([ProductNum],[BarCode],[ProductName],[BatchNum],[Num],[Type],[ContactOrder],[FromLocalNum],[ToLocalNum],[StoreNum],[CreateTime],[CreateUser])
VALUES(@ProductNum,@BarCode,@ProductName,@BatchNum,@Num,2,@OrderNum,@LocalNum,'',@StorageNum,GETDATE(),@AuditUser)
SET @ERRORSUM=@ERRORSUM+@@ERROR
--进行下一个游标循环
FETCH NEXT FROM MyCursor INTO @ProductName,@BarCode,@ProductNum,@BatchNum,@Num,@LocalNum,@StorageNum
END
CLOSE MyCursor
DEALLOCATE MyCursor--释放游标
--修改订单状态
UPDATE OutStorage SET Status=@Status,AuditUser=@AuditUser,AuditeTime=GETDATE(),Reason=@Reason,OperateType=@OperateType,
EquipmentNum=@EquipmentNum,EquipmentCode=@EquipmentCode,Remark=@Remark
WHERE OrderNum=@OrderNum
SET @ERRORSUM=@ERRORSUM+@@ERROR
---结束事务
IF @ERRORSUM<>0
BEGIN
--回滚事务
ROLLBACK TRANSACTION
END
ELSE
BEGIN
SET @ReturnValue='1000'
--提交事务
COMMIT TRANSACTION
END
END
GO
/****** Object: StoredProcedure [dbo].[Proc_AuditeReturn] Script Date: 2016-05-19 9:50:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Proc_AuditeReturn]
(
@OrderNum VARCHAR(50),--退货单
@Status int,--审核状态
@AuditUser nvarchar(50),--审核人编号
@Reason nvarchar(400), --审核成功或者失败的原因
@OperateType int, --操作方式 1 电脑 2 PDA
@EquipmentNum varchar(50), --设备编号[所使用的设备编号]
@EquipmentCode varchar(50), --设备条码[如果没有就直接设备编号]
@Remark nvarchar(400),--入库单描述
@ReturnValue varchar(50) OUTPUT
)
AS
BEGIN
--判断退货单是否存在
IF NOT EXISTS ( SELECT COUNT(*) FROM ReturnOrder WHERE OrderNum=@OrderNum AND IsDelete=0)
BEGIN
SET @ReturnValue='1001'
RETURN
END
--判断退货单是否已经被审核 查询退货单等待审核是否存在
IF NOT EXISTS ( SELECT COUNT(*) FROM ReturnOrder WHERE OrderNum=@OrderNum AND Status=1 AND IsDelete=0)
BEGIN
SET @ReturnValue='1002'
RETURN
END
--开始事务
BEGIN TRANSACTION
--使用错误计数器
DECLARE @ERRORSUM INT
SET @ERRORSUM=0
DECLARE @ProductName nvarchar(100)
DECLARE @BarCode varchar(50)
DECLARE @ProductNum varchar(50)
DECLARE @BatchNum nvarchar(20)
DECLARE @Num float
DECLARE @BackNum float
DECLARE @LocalNum varchar(20)
DECLARE @StorageNum varchar(20)
DECLARE MyCursor CURSOR FOR SELECT [ProductName],[BarCode],[ProductNum],[BatchNum],[Num],[BackNum],[LocalNum],[StorageNum] FROM ReturnDetail WHERE OrderNum= @OrderNum
OPEN MyCursor FETCH NEXT FROM MyCursor INTO @ProductName, @BarCode,@ProductNum,@BatchNum,@Num,@BackNum,@LocalNum,@StorageNum
WHILE @@FETCH_STATUS = 0
BEGIN
--盘点库存是否存在
IF (SELECT COUNT(*) FROM LocalProduct WHERE ProductNum=@ProductNum AND StorageNum=@StorageNum AND LocalNum=@LocalNum AND BatchNum=@BatchNum)>0
BEGIN
--如果存在则修改相应的库存数量
UPDATE LocalProduct SET Num=Num+@BackNum WHERE ProductNum=@ProductNum AND StorageNum=@StorageNum AND LocalNum=@LocalNum AND BatchNum=@BatchNum
END
ELSE
BEGIN
--如果不存在则添加
--获得SN流水号
DECLARE @SN varchar(50)
EXEC Proc_SwiftNum '','LocalProduct',@SN OUTPUT
DECLARE @StorageName nvarchar(50)
DECLARE @LocalName nvarchar(50)
DECLARE @LocalType int
DECLARE @UserName nvarchar(50)
SELECT TOP 1 @StorageName=StorageName FROM Storage WHERE StorageNum=@StorageNum
SELECT TOP 1 @LocalName=LocalName,@LocalType=LocalType FROM Location WHERE LocalNum=@LocalNum AND StorageNum=@StorageNum
SELECT TOP 1 @UserName=UserName FROM Admin WHERE UserCode=@AuditUser
INSERT INTO [dbo].[LocalProduct]([Sn],[StorageNum],[StorageName],[LocalNum],[LocalName],[LocalType],[ProductNum],[BarCode],[ProductName],[BatchNum],[Num],[CreateTime],[CreateUser],[CreateName],[Remark])
VALUES(@SN,@StorageNum,@StorageName,@LocalNum,@LocalName,@LocalType,@ProductNum,@BarCode,@ProductName,@BatchNum,@BackNum,GETDATE(),@AuditUser,@UserName,'')
END
--退货台账记录生成
INSERT INTO [dbo].[InventoryBook]([ProductNum],[BarCode],[ProductName],[BatchNum],[Num],[Type],[ContactOrder],[FromLocalNum],[ToLocalNum],[StoreNum],[CreateTime],[CreateUser])
VALUES(@ProductNum,@BarCode,@ProductName,@BatchNum,@BackNum,7,@OrderNum,'',@LocalNum,@StorageNum,GETDATE(),@AuditUser)
--进行下一个游标循环
FETCH NEXT FROM MyCursor INTO @ProductName, @BarCode,@ProductNum,@BatchNum,@Num,@BackNum,@LocalNum,@StorageNum
END
CLOSE MyCursor
DEALLOCATE MyCursor--释放游标
--修改订单状态
UPDATE ReturnOrder SET Status=@Status,AuditUser=@AuditUser,AuditeTime=GETDATE(),Reason=@Reason,OperateType=@OperateType,
EquipmentNum=@EquipmentNum,EquipmentCode=@EquipmentCode,Remark=@Remark
WHERE OrderNum=@OrderNum
---结束事务
IF @ERRORSUM<>0
BEGIN
--回滚事务
ROLLBACK TRANSACTION
END
ELSE
BEGIN
SET @ReturnValue='1000'
--提交事务
COMMIT TRANSACTION
END
END
GO
/****** Object: StoredProcedure [dbo].[Proc_BadTOP10Num] Script Date: 2016-05-19 9:50:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Proc_BadTOP10Num]
(
@ProductNum VARCHAR(50) , --产品编号
@StorageNum VARCHAR(50) , --仓库编号
@ProductName VARCHAR(100) OUTPUT , --产品名称
@TotalNum float OUTPUT , --总计出库数量
@BeginTime datetime , --开始时间
@EndTime datetime , --结束时间
@Status int , --审核状态
@IsDelete int
)
AS
BEGIN
create table #Temp --创建临时表#Temp
(
ProductName varchar(100), --产品名称
TotalNum int --总计数量
)
--开始事务
BEGIN TRANSACTION
--使用错误计数器
DECLARE @ERRORSUM INT
SET @ERRORSUM=0
DECLARE MyCursor CURSOR FOR SELECT SnNum ,ProductName FROM [Product] WHERE [IsDelete]=@IsDelete AND StorageNum=@StorageNum
OPEN MyCursor FETCH NEXT FROM MyCursor INTO @ProductNum,@ProductName
WHILE @@FETCH_STATUS = 0
BEGIN
BEGIN
SELECT @TotalNum=SUM(Temp.Num) FROM (SELECT BadReportDetail.[Num],BadReportDetail.CreateTime,BadReportDetail.ProductNum FROM BadReport
LEFT JOIN BadReportDetail ON BadReport.OrderNum=BadReportDetail.OrderNum WHERE BadReportDetail.StorageNum=@StorageNum AND BadReportDetail.ProductNum=@ProductNum AND BadReport.Status=@Status AND BadReport.IsDelete=@IsDelete AND BadReportDetail.CreateTime BETWEEN @BeginTime AND @EndTime)
AS Temp WHERE Temp.ProductNum=@ProductNum AND Temp.CreateTime BETWEEN @BeginTime AND @EndTime
END
SET @ERRORSUM=@ERRORSUM+@@ERROR
IF @TotalNum IS NULL
BEGIN
SET @TotalNum=0
END
IF @ProductName IS NULL
BEGIN
SET @ProductName=' '
END
IF @ProductName IS NOT NULL
BEGIN
INSERT INTO #Temp (ProductName,TotalNum)VALUES(@ProductName,@TotalNum)
END
--进行下一个游标循环
FETCH NEXT FROM MyCursor INTO @ProductNum,@ProductName
END
CLOSE MyCursor
DEALLOCATE MyCursor--释放游标
DECLARE @AllNum int,@Top9Num int,@Count int
SELECT @Count=COUNT(*) FROM #Temp WHERE TotalNum>0
SET @TotalNum=0
IF @Count>9
BEGIN
SELECT @AllNum=SUM(TotalNum) FROM #Temp
SELECT @Top9Num=SUM(T0.TotalNum) FROM (SELECT TOP 9 TotalNum FROM #Temp ORDER BY TotalNum DESC) AS T0
SET @TotalNum=@AllNum-@Top9Num
END
;
WITH TempTable AS( SELECT TOP 9 [ProductName],[TotalNum] FROM #Temp ORDER BY [TotalNum] DESC )
SELECT [ProductName],[TotalNum] FROM TempTable
IF @ERRORSUM<>0
BEGIN
--回滚事务
ROLLBACK TRANSACTION
END
ELSE
BEGIN
--提交事务
COMMIT TRANSACTION
END
END
GO
/****** Object: StoredProcedure [dbo].[Proc_CreateCheck] Script Date: 2016-05-19 9:50:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Proc_CreateCheck]
(
@OrderNum VARCHAR(20),--入库单号
@CreateUser VARCHAR(50),--创建人
@CreateName NVARCHAR(50),--创建人名称
@ReturnValue varchar(50) OUTPUT
)
AS
BEGIN