Project

General

Profile

Feature #2027 » CARITATTPKETERLAMBATAN_20230306.sql

Tri Rizqiaty, 03/06/2023 02:45 PM

 
1
??USE [MinovaES_Arita_Dev]
2

3
GO
4

5
/****** Object:  StoredProcedure [dbo].[CARITATTPKETERLAMBATAN]    Script Date: 06/03/2023 14.42.15 ******/
6

7
SET ANSI_NULLS ON
8

9
GO
10

11
SET QUOTED_IDENTIFIER ON
12

13
GO
14

15
ALTER PROCEDURE [dbo].[CARITATTPKETERLAMBATAN]
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) = '00000333'
32

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

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

37

38

39
DECLARE @WSType VARCHAR(20)
40

41
SELECT DISTINCT @WSType = WorkScheduleType FROM dbo.PHRPA0025
42

43
WHERE EmployeeID = @EmployeeID AND StartDate <= @EndDate AND EndDate >= @EndDate
44

45

46

47
DECLARE @TPA19 TABLE
48

49
(
50

51
	DateSpecified VARCHAR(20)
52

53
	,EmployeeID VARCHAR(20)
54

55
	,StartTime19 VARCHAR(20)
56

57
	,EndTime19 VARCHAR(20)
58

59
	,StartTimeDay VARCHAR(20)
60

61
	,EndTimeDay VARCHAR(20)
62

63
	,MenitTelat DECIMAL(18,0)
64

65
)
66

67

68

69
INSERT INTO @TPA19
70

71
SELECT DISTINCT wscal.DateSpecified, pa19.EmployeeID, pa19.StartTime, pa19.EndTime, daytype.StartTime AS StartTimeDay, daytype.EndTime AS EndTimeDay
72

73
				,CASE 
74

75
					WHEN pa19.StartTime <> '' AND pa19.EndTime <> '' AND pa19.StartTime > daytype.StartTime THEN ROUND((dbo.fn_diffTime(wscal.DateSpecified, wscal.DateSpecified, daytype.StartTime, pa19.StartTime) * 60),0) 
76

77
					WHEN pa19.StartTime = '' OR pa19.EndTime = '' THEN 1000
78

79
					ELSE 0
80

81
				 END AS MenitTelat
82

83
FROM dbo.PHRTMWSCAL AS wscal
84

85
INNER JOIN 
86

87
( 
88

89
SELECT DISTINCT EmployeeID, StartDate, EndDate, StartTime, EndTime
90

91
FROM dbo.PHRPA0019
92

93
WHERE EmployeeID = @EmployeeID --AND StartTime > '0700'
94

95
) AS pa19
96

97
ON wscal.DateSpecified = pa19.StartDate
98

99
LEFT JOIN dbo.PHRTMDAYTYP AS daytype
100

101
	ON wscal.DayType = daytype.DayType
102

103
WHERE wscal.WorkScheduleType = @WSType AND daytype.Flag <> 'FREE'
104

105
AND wscal.DateSpecified >= @StartDate AND wscal.DateSpecified <= @EndDate
106

107

108

109
SELECT DISTINCT reftelat.EmployeeID, reftelat.EndLate
110

111
				,COUNT(tpa19.HariTelat) AS HariTelat
112

113
				,COUNT(tpa19.HariTelat) * MIN(reftelat.Amount) AS AmountTelat
114

115
FROM 
116

117
(SELECT DISTINCT @EmployeeID AS EmployeeID, *
118

119
FROM CREFKETERLAMBATAN ) AS reftelat 
120

121
LEFT JOIN
122

123
( SELECT DISTINCT pa19.EmployeeID
124

125
			,pa19.DateSpecified
126

127
			,pa19.MenitTelat
128

129
			,CASE 
130

131
				WHEN StartTime19 <> '' AND EndTime19 <> '' AND StartTime19 > StartTimeDay THEN 1 
132

133
				WHEN StartTime19 = '' OR EndTime19 = '' THEN 1
134

135
				ELSE 0
136

137
			 END AS HariTelat
138

139
FROM @TPA19 AS pa19 ) AS tpa19
140

141
ON tpa19.EmployeeID = reftelat.EmployeeID
142

143
WHERE tpa19.MenitTelat BETWEEN reftelat.StartLate AND reftelat.EndLate
144

145
GROUP BY reftelat.EmployeeID, reftelat.EndLate
146

147

148

149
--SELECT DISTINCT reftelat.EmployeeID, reftelat.EndLate
150

151
--				,COUNT(pa19.DateSpecified) AS HariTelat
152

153
--				,COUNT(pa19.DateSpecified) * MIN(reftelat.Amount) AS AmountTelat
154

155
--FROM 
156

157
--(SELECT DISTINCT @EmployeeID AS EmployeeID, *
158

159
--FROM CREFKETERLAMBATAN ) AS reftelat 
160

161
--LEFT JOIN @TPA19 AS pa19
162

163
--	ON pa19.EmployeeID = reftelat.EmployeeID
164

165
--WHERE pa19.MenitTelat BETWEEN reftelat.StartLate AND reftelat.EndLate
166

167
--GROUP BY reftelat.EmployeeID, reftelat.EndLate
(3-3/3)