Project

General

Profile

Bug #3796 » SPERPRPTSALESRECA_20251020.sql

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

 
1
??USE [MinovaES_DEMO_GolfCourse]
2

3
GO
4

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

7
SET ANSI_NULLS ON
8

9
GO
10

11
SET QUOTED_IDENTIFIER ON
12

13
GO
14

15

16

17

18

19
ALTER procedure [dbo].[SPERPRPTSALESRECAP] 
20

21

22

23
@DocNoFrom varchar (8),
24

25
@DocNoTo varchar (8),
26

27
@DocDateFrom varchar (10),
28

29
@DocDateTo varchar (10),
30

31
@DocType varchar (10) ,
32

33
@DocStatus varchar (10)
34

35

36

37
as 
38

39

40

41

42

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

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

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

49
--declare @DocDateTo varchar (10) =''
50

51
--declare @DocType varchar (10) =''
52

53
--declare @DocStatus varchar (10) =''
54

55

56

57
select distinct
58

59
item.DocNo
60

61
,header.CustomerID
62

63
,'' AS CustomerIDDesc --customer01.[Description] as CustomerIDDesc
64

65
,'' AS CustomerIDDescFix
66

67
--,case 
68

69
--when customer01.[Description] is null then header.CustomerID else customer01.[Description] end as
70

71
-- CustomerIDDescFix
72

73
,header.CompanyID
74

75
,header.CustPONumber
76

77
,header.DocType
78

79
,doctype.DocTypeDesc as DocTypeDesc
80

81
,header.DocStatus
82

83
,docstatus.[Description] as DocStatusDesc
84

85
,header.[Description] AS headerDesc
86

87
,header.ExtDocRef
88

89
,header.BusinessUnit
90

91
,header.DocDate
92

93
,case when header.DocDate =null then '' when header.DocDate ='' then '' 
94

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

97
,item.ItemType
98

99
,itemtype.[Description] as ServiceType
100

101
,item.Material
102

103
,case
104

105
	when item.ItemType =0 then mat01.ExternalID
106

107
	when item.ItemType =1 then v01.ExternalID
108

109
	when item.ItemType =2 then ast01.AssetType end as ServiceID
110

111
,v01.ExternalID as ServiceIDtest
112

113
,case 
114

115
	when item.ItemType =0 then mat01.[Description]
116

117
	--when item.ItemType =1 then v01.[Description]
118

119
	when item.ItemType =2 then ast01.AssetName
120

121
	end as ServiceDesc
122

123
,item.Currency
124

125
,item.PriceAmount
126

127
,item.QuantityMaterial
128

129
,item.QuantityTransaction
130

131
,item.DiscountPercentage
132

133
,item.Discount
134

135
--,((item.PriceAmount*item.QuantityTransaction)-item.Discount) as NetAmount
136

137
,item.NetAmount
138

139
--,((item.PriceAmount*item.QuantityTransaction)-item.Discount)*0.11 as TaxAmount
140

141
,item.NetAmount*0.11 as TaxAmount
142

143
--,((item.PriceAmount*item.QuantityTransaction)-item.Discount) + ((item.PriceAmount*item.QuantityTransaction)-item.Discount)*0.11 as TotalAmount
144

145
,item.TotAmount
146

147
,term.PaymentTermID
148

149
,'SALES RECAP' as Title
150

151
,(select CompanyDescription from PCMEPCOMPID where CompanyID='1000' and EndDate='99991231') as CompanyDescription
152

153
 from PTRSALESHEADER header 
154

155
Inner join PTRSALESITEMS item ON header.DocNo = item.DocNo
156

157
Left join PTRSALESPAYTERM term ON item.DocNo = term.DocNo
158

159
AND item.DocItemID = term.DocItemID
160

161
left join PMDCUS0001 customer01 on header.CustomerID = customer01.CustomerID
162

163
left join PCMBSDOCTYPE doctype on header.DocType = doctype.DocType
164

165
left join PCMBSSALESDOCSTATUS docstatus on header.DocStatus = docstatus.DocStatus
166

167
left join PCMLOGITEMTYPE itemtype on item.ItemType = itemtype.ItemType
168

169
left join PMDSRV0001 v01 on item.Material = v01.ServiceID
170

171
left join PMDMAT0001 mat01 
172

173
	on item.Material = mat01.MaterialID
174

175
left join PMDSRV0001 srv01 
176

177
	on item.Material = srv01.ServiceID
178

179
left join PMDAST0001 ast01 
180

181
	on item.Material = ast01.AssetCode
182

183
	
184

185
where  
186

187
	(item.DocNo >= @DocNoFrom or @DocNoFrom='')
188

189
	and 
190

191
	(item.DocNo <= @DocNoTo or @DocNoTo='')
192

193
	and
194

195
	 (header.DocDate >= @DocDateFrom or @DocDateFrom='')
196

197
	and
198

199
	 (header.DocDate <= @DocDateTo or @DocDateTo='')
200

201
	 and
202

203
	 (header.DocType = @DocType or @DocType ='')
204

205
	 and
206

207
	 (header.DocStatus = @DocStatus or @DocStatus='')
208

209

210

211

212

213

(8-8/9)