Project

General

Profile

Bug #1952 » CBIATMTOPYPERAWATANTARIF.sql

Tri Rizqiaty, 01/24/2023 02:41 PM

 
1
??USE [MinovaES_BIA_Dev]
2

3
GO
4

5
/****** Object:  StoredProcedure [dbo].[CBIATMTOPYPERAWATANTARIF]    Script Date: 24/01/2023 11.54.31 ******/
6

7
SET ANSI_NULLS ON
8

9
GO
10

11
SET QUOTED_IDENTIFIER ON
12

13
GO
14

15
ALTER PROCEDURE [dbo].[CBIATMTOPYPERAWATANTARIF]
16

17
(
18

19
	@EmployeeID VARCHAR(20)
20

21
	,@StartDate VARCHAR(20)
22

23
	,@EndDate VARCHAR(20)
24

25
)
26

27
AS
28

29

30

31
--DECLARE @EmployeeID VARCHAR(20) = '22012383'
32

33
--DECLARE @StartDate VARCHAR(20) = '20230101'
34

35
--DECLARE @EndDate VARCHAR(20) = '20230131'
36

37

38

39
DECLARE @CTARIF TABLE
40

41
(
42

43
	EmployeeID VARCHAR(20)
44

45
    ,[KodeKegiatan] VARCHAR(20)
46

47
    ,[Tarif21] VARCHAR(20)
48

49
    ,[TargetKerjaPerHari] VARCHAR(20)
50

51
    ,[TargetKerjaHariSabtu] VARCHAR(20)
52

53
)
54

55

56

57
INSERT INTO @CTARIF
58

59
SELECT @EmployeeID
60

61
	,[KodeKegiatan]
62

63
	,[Tarif21]
64

65
	,[TargetKerjaPerHari]
66

67
	,[TargetKerjaHariSabtu] 
68

69
FROM CTARIFPERAWATAN
70

71

72

73
DECLARE @TblPerawatan Table
74

75
(
76

77
	EmployeeID VARCHAR(20)
78

79
	,StartDate VARCHAR(20)
80

81
	,HasilKerja1 DECIMAL(22,2)
82

83
	,HasilKerja2 DECIMAL(22,2)
84

85
	,HasilKerja3 DECIMAL(22,2)
86

87
	,HasilKerja4 DECIMAL(22,2)
88

89
	,HasilKerja5 DECIMAL(22,2)
90

91
	,TotalHasilKerja DECIMAL(22,2)
92

93
	,LebihTarget DECIMAL(22,2)
94

95
	,KurangTarget DECIMAL(22,2)
96

97
	,SelisihTarget DECIMAL(22,2)
98

99
	,TarifPerawatan21 DECIMAL(22,2)
100

101
	,UpahCapaiTarget DECIMAL(22,2)
102

103
	,PremiCapaiTarget DECIMAL(22,2)
104

105
	,TotalPerawatan DECIMAL(22,2) 
106

107
)
108

109

110

111
INSERT INTO @TblPerawatan
112

113
SELECT DISTINCT md.EmployeeID
114

115
				,md.StartDate
116

117
				,CASE WHEN md.HasilKerja1 <> '' THEN md.HasilKerja1 ELSE 0 END AS HasilKerja1
118

119
				,CASE WHEN md.HasilKerja2 <> '' THEN md.HasilKerja2 ELSE 0 END AS HasilKerja2
120

121
				,CASE WHEN md.HasilKerja3 <> '' THEN md.HasilKerja3 ELSE 0 END AS HasilKerja3
122

123
				,CASE WHEN md.HasilKerja4 <> '' THEN md.HasilKerja4 ELSE 0 END AS HasilKerja4
124

125
				,CASE WHEN md.HasilKerja5 <> '' THEN md.HasilKerja5 ELSE 0 END AS HasilKerja5
126

127
				,CASE WHEN md.TotalHasilKerja <> '' THEN md.TotalHasilKerja ELSE 0 END AS TotalHasilKerja
128

129
				,CASE WHEN md.LebihTarget <> '' THEN md.LebihTarget ELSE 0 END AS LebihTarget
130

131
				,CASE WHEN md.KurangTarget <> '' THEN md.KurangTarget ELSE 0 END AS KurangTarget
132

133
				,CASE WHEN CONVERT(DECIMAL(22,2),md.LebihTarget) > 0 THEN CONVERT(DECIMAL(22,2),md.LebihTarget) 
134

135
					  WHEN CONVERT(DECIMAL(22,2),md.KurangTarget) > 0 THEN CONVERT(DECIMAL(22,2),md.KurangTarget) * -1
136

137
					  ELSE 0 
138

139
				 END SelisihTarget
140

141
				,tarif.Tarif21 AS TarifPerawatan21
142

143
				,upah.UpahPokok AS UpahCapaiTarget
144

145
				,upah.PremiBasis AS PremiCapaiTarget
146

147
				,CONVERT(DECIMAL(22,0),
148

149
				 CASE WHEN CONVERT(DECIMAL(22,2),md.LebihTarget) > 0 THEN CONVERT(DECIMAL(22,2),upah.UpahPokok) + CONVERT(DECIMAL(22,2),upah.PremiBasis) + (CONVERT(DECIMAL(22,2),md.LebihTarget) * CONVERT(DECIMAL(22,2),tarif.Tarif21))
150

151
					  WHEN CONVERT(DECIMAL(22,2),md.KurangTarget) > 0 THEN CONVERT(DECIMAL(22,2),upah.UpahPokok) - (CONVERT(DECIMAL(22,2),md.KurangTarget) * CONVERT(DECIMAL(22,2),tarif.Tarif21))
152

153
					  ELSE CONVERT(DECIMAL(22,2),upah.UpahPokok) + CONVERT(DECIMAL(22,2),upah.PremiBasis)
154

155
				 END) AS TotalPerawatan
156

157
FROM dbo.CUSPYDATAPREMIPERAWATAN  AS md 
158

159
LEFT JOIN @CTARIF AS tarif
160

161
	ON md.EmployeeID = tarif.EmployeeID
162

163
LEFT JOIN CTARIFBRDPANEN AS upah
164

165
	ON upah.StartDate <= @EndDate AND upah.EndDate >= @EndDate
166

167
WHERE  md.EmployeeID = @EmployeeID
168

169
	AND (md.StartDate BETWEEN @StartDate AND @EndDate)
170

171
	AND (md.KodeKegiatan = tarif.KodeKegiatan)
172

173

174

175

176

177
SELECT DISTINCT result.EmployeeID
178

179
				,MAX(result.TarifPerawatan21) AS TarifPerawatan21
180

181
				,SUM(result.SelisihTarget) AS SelisihTarget
182

183
				,MAX(result.UpahCapaiTarget) AS UpahCapaiTarget
184

185
				,MAX(result.PremiCapaiTarget) AS PremiCapaiTarget
186

187
				,SUM(result.TotalPerawatan) AS TotalPerawatan
188

189
FROM @TblPerawatan AS result
190

191
GROUP BY EmployeeID
(4-4/5)