Project

General

Profile

Support #728 » PDSPYWAGETYPEAUTH.sql

Tri Rizqiaty, 01/07/2022 10:58 AM

 
1
??USE [MinovaES_BankFama_Dev]
2

3
GO
4

5
/****** Object:  StoredProcedure [dbo].[PDSPYWAGETYPEAUTH]    Script Date: 07/01/2022 10.57.51 ******/
6

7
SET ANSI_NULLS ON
8

9
GO
10

11
SET QUOTED_IDENTIFIER ON
12

13
GO
14

15
ALTER PROCEDURE [dbo].[PDSPYWAGETYPEAUTH]
16

17
(
18

19
	 @UserID VARCHAR(50)
20

21
	 ,@PayrollType VARCHAR(50)
22

23
	 ,@PayrollArea VARCHAR(50)
24

25
	 ,@PayrollClass VARCHAR(50)
26

27
	 ,@PayrollGrade VARCHAR(50)
28

29
)
30

31
AS
32

33

34

35
--DECLARE @UserID VARCHAR(50) = 'ilvia'
36

37
--DECLARE @PayrollType VARCHAR(50) = '*'
38

39
--DECLARE @PayrollArea VARCHAR(50) = '*'
40

41
--DECLARE @PayrollClass VARCHAR(50) = '*'
42

43
--DECLARE @PayrollGrade VARCHAR(50) = '*'
44

45

46

47
DECLARE @CompanyIDAuth VARCHAR(50) 
48

49
SELECT DISTINCT @CompanyIDAuth = b.Value 
50

51
FROM SUSERPROFILE AS a
52

53
LEFT JOIN PCUSTPROFILE AS b
54

55
	ON a.ProfileId = b.ProfileID
56

57
where a.UserName = @UserID AND b.FieldName = 'CompanyID'
58

59

60

61

62

63
DECLARE @TResult TABLE
64

65
(
66

67
	TableName VARCHAR(200)
68

69
	,WageType VARCHAR(200)
70

71
	,WageTypeDesc VARCHAR(200)
72

73
	,Valuation VARCHAR(20)
74

75
	,Overwrite VARCHAR(20)
76

77
	,Flag VARCHAR(20)
78

79
	,IsActive VARCHAR(20)
80

81
	,WTAuthorizationGroup VARCHAR(200)
82

83
	,Amount DECIMAL(22,0)
84

85
	,Currency VARCHAR(30)
86

87
)
88

89

90

91
INSERT INTO @TResult
92

93
SELECT  *  
94

95
FROM    ( SELECT  cs.TableName , 
96

97
                   c300.WageTypeDefinition as WageType ,  
98

99
                   c300.WTDefinitionDesc as WageTypeDesc ,  
100

101
                   c300.Valuation,  
102

103
                   c300.Valuation as Flag, 
104

105
                   c300.Overwrite, 
106

107
                   c300.IsActive,  
108

109
                   c300.WTAuthorizationGroup,  
110

111
                   CASE WHEN ( c300.Valuation = 'I1' )  
112

113
                         THEN ( SELECT  Amount FROM PHRPYCU0303 WITH ( NOLOCK ) WHERE WageType = c300.WageTypeDefinition AND StartDate <= '20210101' AND EndDate >= '20210101' )  
114

115
                         WHEN ( c300.Valuation = 'I2' )  
116

117
                         THEN ( SELECT  Amount FROM PHRPYCU0304 WITH ( NOLOCK ) WHERE WageType = c300.WageTypeDefinition AND StartDate <= '20210101' AND EndDate >= '20210101'  
118

119
                               AND (PayrollType = @PayrollType OR PayrollType = '*')  
120

121
	                            AND (PayrollArea = @PayrollArea OR PayrollArea = '*')  
122

123
	                            AND (PayrollClass = @PayrollClass OR PayrollClass = '*')  
124

125
	                            AND (PayrollGrade = @PayrollGrade OR PayrollGrade = '*') )  
126

127
                         WHEN ( c300.Valuation = 'I3' )  
128

129
                         THEN 0  
130

131
                   END AS Amount,  
132

133
                   CASE WHEN ( c300.Valuation = 'I1' )  
134

135
                         THEN ( SELECT  Currency FROM PHRPYCU0303 WITH ( NOLOCK ) WHERE WageType = c300.WageTypeDefinition AND StartDate <= '20210101' AND EndDate >= '20210101' )  
136

137
                         WHEN ( c300.Valuation = 'I2' )  
138

139
                         THEN ( SELECT  Currency FROM PHRPYCU0304 WITH ( NOLOCK ) WHERE WageType = c300.WageTypeDefinition AND StartDate <= '20210101' AND EndDate >= '20210101'   
140

141
                               AND (PayrollType = @PayrollType OR PayrollType = '*')  
142

143
	                            AND (PayrollArea = @PayrollArea OR PayrollArea = '*')  
144

145
	                            AND (PayrollClass = @PayrollClass OR PayrollClass = '*')  
146

147
	                            AND (PayrollGrade = @PayrollGrade OR PayrollGrade = '*') )  
148

149
                         WHEN ( c300.Valuation = 'D' )  
150

151
                         THEN ( SELECT 'IDR' )  
152

153
                    END AS Currency  
154

155
            FROM    PCMEPMDCONSUB AS cs WITH ( NOLOCK )  
156

157
                    INNER JOIN PHRPYCU0300 AS c300 WITH ( NOLOCK ) ON cs.MdSub = c300.WageTypeDefinition  
158

159
                    AND cs.TableName = 'PHRPA0004'  
160

161
                    AND c300.StartDate <= '20210101' AND c300.EndDate >= '20210101'  
162

163
       AND c300.IsActive='1'AND c300.WTAuthorizationGroup = @CompanyIDAuth) AS tbl 
164

165

166

167
INSERT INTO @TResult
168

169
SELECT  *  
170

171
FROM    ( SELECT  cs.TableName , 
172

173
                   c300.WageTypeDefinition as WageType ,  
174

175
                   c300.WTDefinitionDesc as WageTypeDesc ,  
176

177
                   c300.Valuation,  
178

179
                   c300.Valuation as Flag, 
180

181
                   c300.Overwrite, 
182

183
                   c300.IsActive,  
184

185
                   c300.WTAuthorizationGroup,  
186

187
                   CASE WHEN ( c300.Valuation = 'I1' )  
188

189
                         THEN ( SELECT  Amount FROM PHRPYCU0303 WITH ( NOLOCK ) WHERE WageType = c300.WageTypeDefinition AND StartDate <= '20210101' AND EndDate >= '20210101' )  
190

191
                         WHEN ( c300.Valuation = 'I2' )  
192

193
                         THEN ( SELECT  Amount FROM PHRPYCU0304 WITH ( NOLOCK ) WHERE WageType = c300.WageTypeDefinition AND StartDate <= '20210101' AND EndDate >= '20210101'  
194

195
                              AND (PayrollType = @PayrollType OR PayrollType = '*')  
196

197
	                            AND (PayrollArea = @PayrollArea OR PayrollArea = '*')  
198

199
	                            AND (PayrollClass = @PayrollClass OR PayrollClass = '*')  
200

201
	                            AND (PayrollGrade = @PayrollGrade OR PayrollGrade = '*') )  
202

203
                         WHEN ( c300.Valuation = 'I3' )  
204

205
                         THEN 0  
206

207
                   END AS Amount,  
208

209
                   CASE WHEN ( c300.Valuation = 'I1' )  
210

211
                         THEN ( SELECT  Currency FROM PHRPYCU0303 WITH ( NOLOCK ) WHERE WageType = c300.WageTypeDefinition AND StartDate <= '20210101' AND EndDate >= '20210101' )  
212

213
                         WHEN ( c300.Valuation = 'I2' )  
214

215
                         THEN ( SELECT  Currency FROM PHRPYCU0304 WITH ( NOLOCK ) WHERE WageType = c300.WageTypeDefinition AND StartDate <= '20210101' AND EndDate >= '20210101'   
216

217
                               AND (PayrollType = @PayrollType OR PayrollType = '*')  
218

219
	                            AND (PayrollArea = @PayrollArea OR PayrollArea = '*')  
220

221
	                            AND (PayrollClass = @PayrollClass OR PayrollClass = '*')  
222

223
	                            AND (PayrollGrade = @PayrollGrade OR PayrollGrade = '*') )  
224

225
                         WHEN ( c300.Valuation = 'D' )  
226

227
                         THEN ( SELECT 'IDR' )  
228

229
                    END AS Currency  
230

231
            FROM    PCMEPMDCONSUB AS cs WITH ( NOLOCK )  
232

233
                    INNER JOIN PHRPYCU0300 AS c300 WITH ( NOLOCK ) ON cs.MdSub = c300.WageTypeDefinition  
234

235
                    AND cs.TableName = 'PHRPA0004'  
236

237
                    AND c300.StartDate <= '20210101' AND c300.EndDate >= '20210101'  
238

239
       AND c300.IsActive='1'AND ISNULL(c300.WTAuthorizationGroup,'') = '') AS tbl 
240

241
SELECT * FROM @TResult
(2-2/8)