Project

General

Profile

Bug #3796 » ERPRPTSALESDOCDETAILINDUK_20251020.sql

Tri Rizqiaty, 10/20/2025 03:05 PM

 
1
??USE [MinovaES_DEMO_GolfCourse]
2

3
GO
4

5
/****** Object:  StoredProcedure [dbo].[ERPRPTSALESDOCDETAILINDUK]    Script Date: 20/10/2025 14.36.09 ******/
6

7
SET ANSI_NULLS ON
8

9
GO
10

11
SET QUOTED_IDENTIFIER ON
12

13
GO
14

15
ALTER PROCEDURE [dbo].[ERPRPTSALESDOCDETAILINDUK]
16

17

18

19
@DocDateFrom varchar (10),
20

21
 @DocDateTo varchar (10),
22

23
 @DocNoFrom varchar (8),
24

25
 @DocNoTo varchar (8),
26

27
 @DocType varchar (8),
28

29
  @DocStatus varchar(8)
30

31

32

33
  AS
34

35

36

37
--declare @DocDateFrom varchar (10) =''
38

39
--declare @DocDateTo varchar (10) =''
40

41
--declare @DocNoFrom varchar (8) =''
42

43
--declare @DocNoTo varchar (8) =''
44

45
--declare @DocType varchar (8) =''
46

47
--declare @DocStatus varchar (10) =''
48

49

50

51

52

53
SELECT * 
54

55
FROM (
56

57
select  DocNo, DocDate, DocType, DocStatus from PTRSALESHEADER header
58

59
where (header.DocNo >= @DocNoFrom or @DocNoFrom='')
60

61
	and
62

63
	 (header.DocNo <= @DocNoTo or @DocNoTo='')
64

65
	and 
66

67
	(header.DocDate >= @DocDateFrom or @DocDateFrom='')
68

69
	and
70

71
	 (header.DocDate <= @DocDateTo or @DocDateTo='')
72

73
	and 
74

75
	(header.DocType = @DocType or @DocType ='')
76

77
	and
78

79
	(header.DocStatus = @DocStatus or @DocStatus='')
80

81
union 
82

83
select salesitems.DocNo,  header.DocDate, header.DocType, header.DocStatus from PTRSALESITEMS salesitems
84

85
left join PTRSALESHEADER header on salesitems.DocNo = header.DocNo
86

87
where (salesitems.DocNo >= @DocNoFrom or @DocNoFrom='')
88

89
	and
90

91
	 (salesitems.DocNo <= @DocNoTo or @DocNoTo='')
92

93
	 and 
94

95
	(header.DocDate >= @DocDateFrom or @DocDateFrom='')
96

97
	and
98

99
	 (header.DocDate <= @DocDateTo or @DocDateTo='')
100

101
	 and 
102

103
	(header.DocType = @DocType or @DocType ='')
104

105
	and
106

107
	(header.DocStatus = @DocStatus or @DocStatus='')
108

109
union 
110

111
select salescost.DocNo, header.DocDate, header.DocType, header.DocStatus from PTRSALESOTHRCOST salescost
112

113
left join PTRSALESHEADER header on salescost.DocNo = header.DocNo
114

115
where (salescost.DocNo >= @DocNoFrom or @DocNoFrom='')
116

117
	and
118

119
	 (salescost.DocNo <= @DocNoTo or @DocNoTo='')
120

121
	 and 
122

123
	(header.DocDate >= @DocDateFrom or @DocDateFrom='')
124

125
	and
126

127
	 (header.DocDate <= @DocDateTo or @DocDateTo='')
128

129
	 and 
130

131
	(header.DocType = @DocType or @DocType ='')
132

133
	and
134

135
	(header.DocStatus = @DocStatus or @DocStatus='')
136

137
union 
138

139
select salespayterm.DocNo, header.DocDate, header.DocType, header.DocStatus from PTRSALESPAYTERM salespayterm
140

141
left join PTRSALESHEADER header on salespayterm.DocNo = header.DocNo
142

143
where (salespayterm.DocNo >= @DocNoFrom or @DocNoFrom='')
144

145
	and
146

147
	 (salespayterm.DocNo <= @DocNoTo or @DocNoTo='')
148

149
	 and 
150

151
	(header.DocDate >= @DocDateFrom or @DocDateFrom='')
152

153
	and
154

155
	 (header.DocDate <= @DocDateTo or @DocDateTo='')
156

157
	 and 
158

159
	(header.DocType = @DocType or @DocType ='')
160

161
	and
162

163
		(header.DocStatus = @DocStatus or @DocStatus='')
164

165
) AS a
166

167
where a.DocStatus <> ''
(6-6/9)