1
|
--USE [MinovaES_KJL]
|
2
|
--GO
|
3
|
--/****** Object: StoredProcedure [dbo].[PRPTTMATTENDANCE] Script Date: 5/21/2024 1:20:09 PM ******/
|
4
|
--SET ANSI_NULLS ON
|
5
|
--GO
|
6
|
--SET QUOTED_IDENTIFIER ON
|
7
|
--GO
|
8
|
|
9
|
--ALTER PROCEDURE [dbo].[PRPTTMATTENDANCE]
|
10
|
-- (
|
11
|
-- @StartDate VARCHAR(18) ,
|
12
|
-- @EndDate VARCHAR(18) ,
|
13
|
-- @EmployeeID VARCHAR(50) ,
|
14
|
-- @EmployeeArea VARCHAR(18) ,
|
15
|
-- @EmployeeOffice VARCHAR(18) ,
|
16
|
-- @Organization VARCHAR(18) ,
|
17
|
-- @CompanyID VARCHAR(20) ,
|
18
|
-- @MenuID VARCHAR(10) ,
|
19
|
-- @UserID VARCHAR(10)
|
20
|
-- )
|
21
|
--AS
|
22
|
|
23
|
-------- Rpt_Product_HR_TM_Attendace 3000008 --------
|
24
|
DECLARE @Organization VARCHAR(8) = ''
|
25
|
DECLARE @StartDate VARCHAR(8) = '20240422'
|
26
|
DECLARE @EndDate VARCHAR(8) = '20240521'
|
27
|
DECLARE @CompanyID VARCHAR(8) = '1000'
|
28
|
DECLARE @EmployeeArea VARCHAR(18) = ''
|
29
|
DECLARE @EmployeeOffice VARCHAR(18) = ''
|
30
|
DECLARE @EmployeeID VARCHAR(18) = '17030021'
|
31
|
DECLARE @MenuID VARCHAR(10) = 'TMR0002'
|
32
|
DECLARE @UserID VARCHAR(10) = 'shofwan'
|
33
|
|
34
|
|
35
|
DECLARE @date_min VARCHAR(12) = '18000101'
|
36
|
DECLARE @date_max VARCHAR(12) = '99991231'
|
37
|
|
38
|
------------------ // Get Otorisasi //---------------
|
39
|
DECLARE @TableResult TABLE ( EmployeeID VARCHAR(20) )
|
40
|
|
41
|
INSERT INTO @TableResult
|
42
|
EXEC dbo.GETEMPIDAUTHBYMENU @MenuID = @MenuID, -- varchar(max)
|
43
|
@UserID = @UserID
|
44
|
-- varchar(max)
|
45
|
|
46
|
------------------ // End Get Otorisasi //---------------
|
47
|
|
48
|
IF ( LTRIM(RTRIM(@StartDate)) <> '' )
|
49
|
BEGIN
|
50
|
SET @date_min = @StartDate
|
51
|
IF ( LTRIM(RTRIM(@EndDate)) <> '' )
|
52
|
SET @date_max = @EndDate
|
53
|
ELSE
|
54
|
SET @date_max = @StartDate
|
55
|
END
|
56
|
|
57
|
DECLARE @now VARCHAR(8)
|
58
|
SET @now = dbo.fn_formatdatetime(GETDATE(), 'yyyymmdd')
|
59
|
|
60
|
------------get organisasi-----------
|
61
|
|
62
|
|
63
|
DECLARE @cal AS TABLE
|
64
|
(
|
65
|
EmployeeID VARCHAR(50) ,
|
66
|
DateSpecified VARCHAR(8)
|
67
|
--,DayType VARCHAR(8)
|
68
|
)
|
69
|
INSERT INTO @cal
|
70
|
SELECT md25.EmployeeID ,
|
71
|
cal.DateSpecified
|
72
|
--,cal.DayType
|
73
|
FROM dbo.PHRPA0025 md25
|
74
|
LEFT JOIN dbo.PHRTMWSCAL cal ON cal.WorkScheduleType = md25.WorkScheduleType
|
75
|
AND cal.DateSpecified >= @StartDate
|
76
|
AND cal.DateSpecified <= @EndDate
|
77
|
WHERE md25.StartDate <= SUBSTRING(@StartDate, 1, 6) + '31'
|
78
|
AND md25.EndDate >= SUBSTRING(@StartDate, 1, 6) + '31'
|
79
|
AND ( md25.EmployeeID = @EmployeeID
|
80
|
OR @EmployeeID = ''
|
81
|
)
|
82
|
|
83
|
|
84
|
---------------------------------------------// Declare Time //--------------------------------------------------------
|
85
|
|
86
|
select distinct
|
87
|
EmployeeID,StartDate,EndDate,CreateDate
|
88
|
,CAST((Left(StartTime,2)*60+RIGHT(StartTime,2)) AS FLOAT) AS MinuteStart
|
89
|
,CAST((Left(EndTime,2)*60+RIGHT(EndTime,2)) AS FLOAT) AS MinuteEnd
|
90
|
into #MinutesTable
|
91
|
from PHRPA0019
|
92
|
where
|
93
|
( EmployeeID = @EmployeeID OR @EmployeeID = '')
|
94
|
and
|
95
|
(@StartDate<=StartDate or @StartDate='')
|
96
|
and
|
97
|
(@EndDate>=EndDate-1 or @EndDate='')
|
98
|
|
99
|
|
100
|
select
|
101
|
mnt.EmployeeID,mnt.StartDate,mnt.EndDate,mnt.MinuteStart,mnt.MinuteEnd,mnt.CreateDate,
|
102
|
case
|
103
|
when mnt.MinuteEnd =0 then 0
|
104
|
when mnt.MinuteStart=0 then 0
|
105
|
when mnt.MinuteEnd>mnt.MinuteStart then MinuteEnd-MinuteStart
|
106
|
when mnt.MinuteEnd<mnt.MinuteStart then MinuteEnd+(1440-MinuteStart)
|
107
|
end as MinuteDuration
|
108
|
into #MinutesTable2
|
109
|
from #MinutesTable mnt
|
110
|
|
111
|
|
112
|
select
|
113
|
mnt2.EmployeeID,mnt2.StartDate,mnt2.EndDate,mnt2.CreateDate
|
114
|
,FLOOR(mnt2.MinuteDuration/60) AS HourDuration
|
115
|
,ROUND((mnt2.MinuteDuration/60-FLOOR(mnt2.MinuteDuration/60))*60,0) AS MinuteDuration
|
116
|
into #MinutesTable3
|
117
|
from #MinutesTable2 mnt2
|
118
|
|
119
|
|
120
|
select
|
121
|
EmployeeID,StartDate,EndDate,CreateDate
|
122
|
,CAST(HourDuration AS VARCHAR) AS HourDuration
|
123
|
,RIGHT('00' + CAST(MinuteDuration AS VARCHAR(2)), 2) AS MinuteDuration
|
124
|
into #MinutesTable4
|
125
|
from #MinutesTable3
|
126
|
|
127
|
|
128
|
|
129
|
---------------------------------------------// Declare Time //--------------------------------------------------------
|
130
|
|
131
|
SELECT DISTINCT
|
132
|
DENSE_RANK() OVER ( ORDER BY cal.EmployeeID ) AS GroupSeq ,
|
133
|
cal.DateSpecified ,
|
134
|
cal.EmployeeID ,
|
135
|
dbo.fn_formatdatetime_indonesia(@StartDate, 'DD MMMM YYYY') as letterDate1,
|
136
|
dbo.fn_formatdatetime_indonesia(@EndDate, 'DD MMMM YYYY') as letterDate2,
|
137
|
--ROW_NUMBER() OVER ( PARTITION BY cal.EmployeeID ORDER BY cal.EmployeeID ASC ) AS seq ,
|
138
|
'' AS seq,
|
139
|
dbo.fn_formatdatetime(CASE WHEN md19.StartDate = ''
|
140
|
OR md19.StartDate IS NULL
|
141
|
THEN cal.DateSpecified
|
142
|
ELSE md19.StartDate
|
143
|
END, 'dd/mm/yyyy') AS stdt ,
|
144
|
dbo.fn_formatdatetime(CASE WHEN md19.EndDate = ''
|
145
|
OR md19.StartDate IS NULL
|
146
|
THEN cal.DateSpecified
|
147
|
ELSE md19.EndDate
|
148
|
END, 'dd/mm/yyyy') AS endt ,
|
149
|
CASE WHEN md19.StartDate = ''
|
150
|
OR md19.StartDate IS NULL THEN cal.DateSpecified
|
151
|
ELSE md19.StartDate
|
152
|
END AS StartDate ,
|
153
|
CASE WHEN md19.EndDate = ''
|
154
|
OR md19.StartDate IS NULL THEN cal.DateSpecified
|
155
|
ELSE md19.EndDate
|
156
|
END AS EndDate ,
|
157
|
--, cal.DayType,
|
158
|
SUBSTRING(md19.StartTime,1,2) + '.' + SUBSTRING(md19.StartTime,3,2) AS StartTime,
|
159
|
SUBSTRING(md19.EndTime,1,2) + '.' + SUBSTRING(md19.EndTime,3,2) AS EndTime,
|
160
|
md19.AttendanceType ,
|
161
|
md19.CreateDate,
|
162
|
md2.EmployeeArea ,
|
163
|
md2.EmployeeOffice ,
|
164
|
md2.CompanyID ,
|
165
|
md1.FullName ,
|
166
|
att.AttendanceTypeDesc AS att_desc ,
|
167
|
mnt4.HourDuration*60 + mnt4.MinuteDuration as MinuteDuration,
|
168
|
CASE WHEN mnt4.HourDuration is null and mnt4.MinuteDuration is null then '0.00'
|
169
|
ELSE CONCAT(mnt4.HourDuration,'.', mnt4.MinuteDuration) END AS Duration,
|
170
|
md19.CreateBy ,
|
171
|
md19.ChangeBy
|
172
|
FROM @cal AS cal
|
173
|
LEFT JOIN dbo.PHRPA0019 md19 ON md19.EmployeeID = cal.EmployeeID
|
174
|
AND cal.DateSpecified = md19.StartDate
|
175
|
LEFT JOIN dbo.PHRPA0002 md2 ON md2.EmployeeID = cal.EmployeeID
|
176
|
AND md2.StartDate <= @now
|
177
|
AND md2.EndDate ='99991231'
|
178
|
and md2.EmployeeStatus='01'
|
179
|
LEFT JOIN dbo.PHRPA0001 md1 ON md1.EmployeeID = cal.EmployeeID
|
180
|
AND md1.StartDate <= @now
|
181
|
AND md1.EndDate >= @now
|
182
|
LEFT JOIN dbo.PHRTMATTTYP att ON md19.AttendanceType = att.AttendanceType
|
183
|
LEFT JOIN @TableResult AS lt ON lt.EmployeeID = md2.EmployeeID
|
184
|
LEFT JOIN #MinutesTable4 AS mnt4 ON cal.EmployeeID = mnt4.EmployeeID and md19.StartDate = mnt4.StartDate and md19.EndDate = mnt4.EndDate and md19.CreateDate=mnt4.CreateDate
|
185
|
WHERE
|
186
|
( md2.CompanyID = @CompanyID
|
187
|
OR @CompanyID = '')
|
188
|
AND ( md2.EmployeeArea = @EmployeeArea
|
189
|
OR @EmployeeArea = ''
|
190
|
)
|
191
|
AND ( md2.EmployeeOffice = @EmployeeOffice
|
192
|
OR @EmployeeOffice = ''
|
193
|
)
|
194
|
AND ( cal.DateSpecified >= @date_min
|
195
|
AND cal.DateSpecified <= @date_max
|
196
|
)
|
197
|
|
198
|
ORDER BY cal.EmployeeID ,
|
199
|
cal.DateSpecified ASC
|
200
|
|
201
|
--select * from PHRPA0019
|
202
|
drop table #MinutesTable
|
203
|
drop table #MinutesTable2
|
204
|
drop table #MinutesTable3
|
205
|
drop table #MinutesTable4
|