Project

General

Profile

Feature #3222 » CBBGTMTOPYOVERTIMEBRACKETDUR_20241119.sql

Tri Rizqiaty, 11/19/2024 11:21 AM

 
1
??ALTER PROCEDURE [dbo].[CBBGTMTOPYOVERTIMEBRACKETDUR]
2

3
(
4

5
	@EmployeeID VARCHAR(20)
6

7
	,@StartDate VARCHAR(20)
8

9
	,@EndDate VARCHAR(20)
10

11
	,@WSType VARCHAR(20)
12

13
)
14

15
AS
16

17

18

19
--DECLARE @EmployeeID VARCHAR(20) = '00000118'
20

21
--DECLARE @StartDate VARCHAR(20) = '20241001'
22

23
--DECLARE @EndDate VARCHAR(20) = '20241031'
24

25
--DECLARE @WSType VARCHAR(20) = ''
26

27

28

29
DECLARE @TOVT TABLE
30

31
(
32

33
	EmployeeID VARCHAR(20)
34

35
	,StartDate VARCHAR(20)
36

37
	,EndDate VARCHAR(20)
38

39
	,DayType VARCHAR(20)
40

41
	,Flag VARCHAR(20)
42

43
	,Duration DECIMAL(18,2)
44

45
	,OT150 DECIMAL(18,2)
46

47
	,OT200 DECIMAL(18,2)
48

49
	,OT300 DECIMAL(18,2)
50

51
	,OT400 DECIMAL(18,2)
52

53
)
54

55

56

57
INSERT INTO @TOVT
58

59
SELECT DISTINCT CASE WHEN pa16.EmployeeID <> '' THEN pa16.EmployeeID ELSE @EmployeeID END AS EmployeeID
60

61
				,pa16.StartDate, pa16.EndDate, pa16.DayType, daytype.Flag, pa16.Duration
62

63
				,CASE WHEN daytype.Flag = 'WORK' THEN CASE WHEN pa16.Duration >= 1 THEN 1 ELSE pa16.Duration END ELSE 0 END AS OT150--0 END AS OT150
64

65
				,CASE 
66

67
					WHEN daytype.Flag = 'WORK' THEN CASE WHEN pa16.Duration > 1 AND pa16.Duration <= 24 THEN pa16.Duration - 1 END 
68

69
					WHEN daytype.Flag = 'FREE' THEN CASE WHEN pa16.Duration < 9 THEN pa16.Duration ELSE 8  END 
70

71
					ELSE 0
72

73
				 END AS OT200
74

75
				,CASE 
76

77
					WHEN daytype.Flag = 'FREE' THEN CASE WHEN pa16.Duration > 9 THEN 1 ELSE 0 END 
78

79
					ELSE 0
80

81
				 END AS OT300
82

83
				,CASE 
84

85
					WHEN daytype.Flag = 'FREE' THEN CASE WHEN pa16.Duration > 9 THEN pa16.Duration - 9 ELSE 0 END 
86

87
					ELSE 0
88

89
				 END AS OT400
90

91
FROM dbo.PHRPA0016 AS pa16
92

93
LEFT JOIN dbo.PHRTMDAYTYP AS daytype ON daytype.DayType = pa16.DayType
94

95
WHERE (pa16.StartDate BETWEEN @StartDate AND @EndDate)
96

97
AND (pa16.EmployeeID = @EmployeeID OR @EmployeeID = '') 
98

99
AND pa16.Variant = 'OVT'
100

101

102

103

104

105
SELECT a.EmployeeID, ISNULL(b.OT150,0) AS OT150, ISNULL(b.OT200,0) AS OT200, ISNULL(b.OT300,0) AS OT300, ISNULL(b.OT400,0) AS OT400
106

107
FROM ( SELECT @EmployeeID AS EmployeeID, 0 AS OT150, 0 AS OT200, 0 AS OT300, 0 AS OT400 ) AS a
108

109
LEFT JOIN
110

111
(SELECT EmployeeID, SUM(OT150) AS OT150, SUM(OT200) AS OT200, SUM(OT300) AS OT300, SUM(OT400) AS OT400
112

113
FROM @TOVT
114

115
GROUP BY EmployeeID) AS b
116

117
ON a.EmployeeID = b.EmployeeID
118

119

120

121
/*SELECT EmployeeID, SUM(OT150) AS OT150, SUM(OT200) AS OT200, SUM(OT300) AS OT300, SUM(OT400) AS OT400
122

123
FROM @TOVT
124

125
GROUP BY EmployeeID*/
126

127
	
(2-2/2)