Project

General

Profile

Bug #3796 » SPERPRPTSALESSTATUS_20251020.sql

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

 
1
??USE [MinovaES_DEMO_GolfCourse]
2

3
GO
4

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

7
SET ANSI_NULLS ON
8

9
GO
10

11
SET QUOTED_IDENTIFIER ON
12

13
GO
14

15
ALTER procedure [dbo].[SPERPRPTSALESSTATUS]
16

17

18

19
@DocNoFrom varchar (8),
20

21
@DocNoTo varchar (8),
22

23
@DocDateFrom varchar (10),
24

25
@DocDateTo varchar (10),
26

27
@DocType varchar (10)
28

29

30

31
as
32

33

34

35
begin
36

37

38

39
--declare @DocNoFrom varchar (8) =''
40

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

43
--declare @DocDateFrom varchar (10) =''
44

45
--declare @DocDateTo varchar (10) =''
46

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

49

50

51
select header.DocNo
52

53
,header.CustomerID
54

55
,'' AS [Description]--customer.[Description]
56

57
,'' AS CustomerIDDesc
58

59
--,Case
60

61
--	when customer.[Description] is null then header.CustomerID
62

63
--	else customer.[Description] end as CustomerIDDesc
64

65
,header.CompanyID
66

67
,header.CustPONumber
68

69
,header.DocType
70

71
,doctype.DocTypeDesc as DocTypeDesc
72

73
,header.DocStatus
74

75
,docstatus.[Description] as DocStatusDesc
76

77
,header.[Description] AS headerDesc
78

79
,header.ExtDocRef
80

81
,header.BusinessUnit
82

83
,header.DocDate
84

85
,case
86

87
	when header.DocDate =null then '' 
88

89
	when header.DocDate ='' then '' 
90

91
		else dbo.fn_formatdatetime_indonesia(header.DocDate, 'DD MMMM YYYY') end as DocDateDesc
92

93
,term.PaymentTermID
94

95
,payterm.PaymentTermDescription
96

97
,term.[Sequence]
98

99
,term.[Description] AS Destrem
100

101
,term.Percentage
102

103
,term.Amount
104

105
,term.Currency
106

107
,term.AccountingDoc
108

109
,case 
110

111
	when term.AccountingDoc is null then 'AR' 
112

113
	when term.AccountingDoc ='' then 'AR' 
114

115
	else term.AccountingDoc end as AccountingDocDesc
116

117
,term.[Status]
118

119
,case 
120

121
	when term.[Status] =0 then 'Plan' 
122

123
	when term.[Status] =1 then 'BIlled'
124

125
	when term.[Status] =2 then 'Paid'
126

127
	else '' end as StatusDesc
128

129
,term.PostingDate
130

131
,case
132

133
	when term.PostingDate =null then '' 
134

135
	when term.PostingDate ='' then ''
136

137
	when term.PostingDate like '________' then dbo.fn_formatdatetime_indonesia(term.PostingDate, 'DD MMMM YYYY') end as PostingDateDesc
138

139
from PTRSALESHEADER header 
140

141
left join PTRSALESPAYTERM term ON header.DocNo = term.DocNo
142

143
left join PCMBSDOCTYPE doctype on header.DocType = doctype.DocType
144

145
left join PCMBSLOGDOCSTATUS docstatus on header.DocStatus = docstatus.DocStatus
146

147
left join PCMFILOPAYTERM payterm on term.PaymentTermID = payterm.PaymentTermCode
148

149
left join PMDCUS0001 customer on header.CustomerID = customer.CustomerID
150

151
where 
152

153

154

155
	(header.DocNo >= @DocNoFrom or @DocNoFrom='')
156

157
	and 
158

159
	(header.DocNo <= @DocNoTo or @DocNoTo='')
160

161
	and
162

163
	 (header.DocDate >= @DocDateFrom or @DocDateFrom='')
164

165
	and
166

167
	 (header.DocDate <= @DocDateTo or @DocDateTo='')
168

169
	 and
170

171
	 (header.DocType = @DocType or @DocType ='')
172

173
end
174

175

(9-9/9)