1
|
USE [MinovaHR_ESS_Indomobil_Production]
|
2
|
GO
|
3
|
/****** Object: StoredProcedure [dbo].[Rpt_IMFI_HR_PY_SeparationDetail] Script Date: 01/27/2021 12:08:47 ******/
|
4
|
SET ANSI_NULLS ON
|
5
|
GO
|
6
|
SET QUOTED_IDENTIFIER ON
|
7
|
GO
|
8
|
ALTER PROCEDURE [dbo].[Rpt_IMFI_HR_PY_SeparationDetail]
|
9
|
(
|
10
|
@landscape VARCHAR(3) ,
|
11
|
@period_month VARCHAR(2) ,
|
12
|
@period_year VARCHAR(4) ,
|
13
|
@companycode VARCHAR(5) ,
|
14
|
@pay_group VARCHAR(5) ,
|
15
|
@emp_office VARCHAR(5) ,
|
16
|
@emp_area VARCHAR(5)
|
17
|
)
|
18
|
AS
|
19
|
BEGIN
|
20
|
|
21
|
--DECLARE @landscape VARCHAR(3) = '100'
|
22
|
--DECLARE @period_month VARCHAR(2) = '01'
|
23
|
--DECLARE @period_year VARCHAR(4) = '2021'
|
24
|
--DECLARE @companycode VARCHAR(5) = '1000'
|
25
|
--DECLARE @pay_group VARCHAR(5) = '13'
|
26
|
--DECLARE @emp_office VARCHAR(5) = ''
|
27
|
--DECLARE @emp_area VARCHAR(5) = ''
|
28
|
|
29
|
DECLARE @now VARCHAR(20)
|
30
|
SET @now = dbo.fn_formatdatetime(GETDATE(), 'yyyymmdd')
|
31
|
DECLARE @table_hiring AS TABLE
|
32
|
(
|
33
|
landscape VARCHAR(3) ,
|
34
|
emp_id VARCHAR(10) ,
|
35
|
startdate VARCHAR(8)
|
36
|
)
|
37
|
DECLARE @table_separation AS TABLE
|
38
|
(
|
39
|
emp_id VARCHAR(10) ,
|
40
|
wage_type VARCHAR(4) ,
|
41
|
amount VARCHAR(500)
|
42
|
)
|
43
|
-- INSERT TABLE HIRING --
|
44
|
INSERT INTO @table_hiring
|
45
|
SELECT landscape ,
|
46
|
emp_id ,
|
47
|
start_date
|
48
|
FROM dbo.hr_md_emp_md0002
|
49
|
WHERE movement_type = '10'
|
50
|
-- INSERT TABLE WAGETYPE ADDITIONAL SEPARATION --
|
51
|
INSERT INTO @table_separation
|
52
|
SELECT distinct employee_id ,
|
53
|
wage_type ,
|
54
|
dbo.GetPEN(@landscape, amount) amount_separation
|
55
|
FROM dbo.hr_tr0301
|
56
|
WHERE wage_type IN (
|
57
|
SELECT code
|
58
|
FROM dbo.hr_cu0300
|
59
|
WHERE is_pesangon = 'Y'
|
60
|
AND code NOT IN ( '5100', 'TP' ) )--IN( '3200', '3201' ,'3202' )
|
61
|
and pay_period_month=@period_month and pay_period_year=@period_year
|
62
|
--select * from @table_separation where emp_id='20030218'
|
63
|
SELECT md2.landscape ,
|
64
|
md2.employee_office ,
|
65
|
office.emp_subarea_description ,
|
66
|
md2.employee_area ,
|
67
|
md2.employee_subtype ,
|
68
|
sub.description employee_subtype_desc ,
|
69
|
md2.payroll_group ,
|
70
|
RANK() OVER ( PARTITION BY md2.employee_office ORDER BY md2.emp_id, md2.employee_office ) AS seq ,
|
71
|
md2.emp_id ,
|
72
|
md1.full_name ,
|
73
|
md3.pay_area ,
|
74
|
md3.pay_grade ,
|
75
|
md3.pay_class ,
|
76
|
hiring.startdate join_date ,
|
77
|
md2.start_date resign_date ,
|
78
|
md2.movement_type ,
|
79
|
md2.reason ,
|
80
|
md2.company_id ,
|
81
|
gapok.wage_type wage_type_gapok ,
|
82
|
CONVERT(DECIMAL, dbo.GetPEN(@landscape, gapok.amount)) AS amount_gapok ,
|
83
|
tj_makan.wage_type wage_type_makan ,
|
84
|
( SELECT amount
|
85
|
FROM hr_cu0304
|
86
|
WHERE start_date <= @now
|
87
|
AND end_date >= @now
|
88
|
AND wage_type = tj_makan.wage_type
|
89
|
AND pay_area = md3.pay_area
|
90
|
AND pay_grade = md3.pay_grade
|
91
|
) amount_makan ,
|
92
|
tj_ttp.wage_type wage_type_ttp ,
|
93
|
CASE WHEN ( tj_ttp.wage_type ) = '1210'
|
94
|
THEN ( SELECT amount
|
95
|
FROM hr_cu0304
|
96
|
WHERE start_date <= @now
|
97
|
AND end_date >= @now
|
98
|
AND wage_type = tj_ttp.wage_type
|
99
|
AND pay_grade = md3.pay_grade
|
100
|
AND pay_class = md3.pay_class
|
101
|
)
|
102
|
ELSE ( SELECT amount
|
103
|
FROM hr_cu0304
|
104
|
WHERE start_date <= @now
|
105
|
AND end_date >= @now
|
106
|
AND wage_type = tj_ttp.wage_type
|
107
|
AND pay_area = md3.pay_area
|
108
|
AND pay_grade = md3.pay_grade
|
109
|
AND pay_class = md3.pay_class
|
110
|
)
|
111
|
END amount_transport ,
|
112
|
tj_kend.wage_type wage_type_kend ,
|
113
|
CASE WHEN ( ISNULL(tj_kend.wage_type, '') = '' ) THEN 0
|
114
|
ELSE ( SELECT amount
|
115
|
FROM hr_cu0304
|
116
|
WHERE start_date <= @now
|
117
|
AND end_date >= @now
|
118
|
AND wage_type = tj_kend.wage_type
|
119
|
AND pay_grade = md3.pay_grade
|
120
|
AND pay_class = md3.pay_class
|
121
|
)
|
122
|
END amount_kendaraan ,
|
123
|
tj_driver.wage_type wage_type_driver ,
|
124
|
CASE WHEN ( ISNULL(tj_driver.wage_type, '') = '' ) THEN 0
|
125
|
ELSE ( SELECT amount
|
126
|
FROM hr_cu0304
|
127
|
WHERE start_date <= @now
|
128
|
AND end_date >= @now
|
129
|
AND wage_type = tj_driver.wage_type
|
130
|
AND pay_grade = md3.pay_grade
|
131
|
AND pay_class = md3.pay_class
|
132
|
)
|
133
|
END amount_driver ,
|
134
|
tj_hp.wage_type wage_type_hp ,
|
135
|
CASE WHEN ( tj_hp.wage_type ) = '1235'
|
136
|
THEN ( SELECT amount
|
137
|
FROM hr_cu0304
|
138
|
WHERE start_date <= @now
|
139
|
AND end_date >= @now
|
140
|
AND wage_type = tj_hp.wage_type
|
141
|
AND pay_grade = md3.pay_grade
|
142
|
AND pay_class = md3.pay_class
|
143
|
)
|
144
|
ELSE ( SELECT amount
|
145
|
FROM hr_cu0304
|
146
|
WHERE start_date <= @now
|
147
|
AND end_date >= @now
|
148
|
AND wage_type = tj_hp.wage_type
|
149
|
AND pay_area = md3.pay_area
|
150
|
AND pay_grade = md3.pay_grade
|
151
|
AND pay_class = md3.pay_class
|
152
|
)
|
153
|
END amount_hp ,
|
154
|
tj_jabatan.wage_type wage_type_jab ,
|
155
|
CASE WHEN ( tj_jabatan.wage_type ) = '1211'
|
156
|
THEN ( SELECT amount
|
157
|
FROM hr_cu0304
|
158
|
WHERE start_date <= @now
|
159
|
AND end_date >= @now
|
160
|
AND wage_type = tj_jabatan.wage_type
|
161
|
AND pay_grade = md3.pay_grade
|
162
|
AND pay_class = md3.pay_class
|
163
|
)
|
164
|
ELSE ( SELECT amount
|
165
|
FROM hr_cu0304
|
166
|
WHERE start_date <= @now
|
167
|
AND end_date >= @now
|
168
|
AND wage_type = tj_jabatan.wage_type
|
169
|
AND pay_area = md3.pay_area
|
170
|
AND pay_grade = md3.pay_grade
|
171
|
AND pay_class = md3.pay_class
|
172
|
)
|
173
|
END amount_jabatan ,
|
174
|
--CONVERT(DECIMAL, dbo.GetPEN(@landscape, TP.amount)) tax_separation ,
|
175
|
--CONVERT(DECIMAL, dbo.GetPEN(@landscape, TA.amount)) tax_allowance ,
|
176
|
--TP.pay_period_month ,
|
177
|
--TP.pay_period_year ,
|
178
|
CASE WHEN ISNULL(sp.amount, '') = '' THEN 0
|
179
|
ELSE CONVERT(DECIMAL, sp.amount)
|
180
|
END amount_separation ,
|
181
|
sp.wage_type wage_type_sp
|
182
|
FROM dbo.hr_md_emp_md0002 md2
|
183
|
INNER JOIN dbo.hr_md_emp_md0001 md1 ON md1.emp_id = md2.emp_id
|
184
|
AND md1.start_date <= @now
|
185
|
AND md1.end_date >= @now
|
186
|
INNER JOIN hr_md_emp_md0003 md3 ON md3.emp_id = md2.emp_id
|
187
|
AND md3.start_date <= @now
|
188
|
AND md3.end_date >= @now
|
189
|
INNER JOIN dbo.hr_md_emp_md0004 gapok ON md2.emp_id = gapok.emp_id -- GAPOK
|
190
|
AND gapok.start_date <= @now
|
191
|
AND gapok.end_date >= @now
|
192
|
AND gapok.wage_type = '1000'
|
193
|
LEFT JOIN dbo.hr_md_emp_md0004 tj_makan ON md2.emp_id = tj_makan.emp_id -- TJ MAKAN
|
194
|
AND tj_makan.start_date <= @now
|
195
|
AND tj_makan.end_date >= @now
|
196
|
AND ( tj_makan.wage_type IN (
|
197
|
'1200', '1201' )
|
198
|
OR tj_makan.wage_type IN (
|
199
|
SELECT
|
200
|
val1
|
201
|
FROM
|
202
|
base_cust_parameter
|
203
|
WHERE
|
204
|
param = 'IMFI_WAGE_TYPE_MK'
|
205
|
AND start_date <= @now
|
206
|
AND end_date >= @now )
|
207
|
)
|
208
|
LEFT JOIN dbo.hr_md_emp_md0004 tj_ttp ON md2.emp_id = tj_ttp.emp_id -- TJ TRANSPORT
|
209
|
AND tj_ttp.start_date <= @now
|
210
|
AND tj_ttp.end_date >= @now
|
211
|
AND ( tj_ttp.wage_type IN (
|
212
|
'1203', '1210' )
|
213
|
OR tj_ttp.wage_type IN (
|
214
|
SELECT
|
215
|
val1
|
216
|
FROM
|
217
|
base_cust_parameter
|
218
|
WHERE
|
219
|
param = 'IMFI_WAGE_TYPE_TP'
|
220
|
AND start_date <= @now
|
221
|
AND end_date >= @now )
|
222
|
)
|
223
|
LEFT JOIN dbo.hr_md_emp_md0004 tj_kend ON md2.emp_id = tj_kend.emp_id -- TJ KENDARAAN
|
224
|
AND tj_kend.start_date <= @now
|
225
|
AND tj_kend.end_date >= @now
|
226
|
AND ( tj_kend.wage_type = '1204'
|
227
|
OR tj_kend.wage_type IN (
|
228
|
SELECT
|
229
|
val1
|
230
|
FROM
|
231
|
base_cust_parameter
|
232
|
WHERE
|
233
|
param = 'IMFI_WAGE_TYPE_KD'
|
234
|
AND start_date <= @now
|
235
|
AND end_date >= @now )
|
236
|
)
|
237
|
LEFT JOIN dbo.hr_md_emp_md0004 tj_driver ON md2.emp_id = tj_driver.emp_id -- TJ DRIVER
|
238
|
AND tj_driver.start_date <= @now
|
239
|
AND tj_driver.end_date >= @now
|
240
|
AND ( tj_driver.wage_type = '1211'
|
241
|
OR tj_driver.wage_type IN (
|
242
|
SELECT
|
243
|
val1
|
244
|
FROM
|
245
|
base_cust_parameter
|
246
|
WHERE
|
247
|
param = 'IMFI_WAGE_TYPE_DR'
|
248
|
AND start_date <= @now
|
249
|
AND end_date >= @now )
|
250
|
)
|
251
|
LEFT JOIN dbo.hr_md_emp_md0004 tj_hp ON md2.emp_id = tj_hp.emp_id -- TJ HP
|
252
|
AND tj_hp.start_date <= @now
|
253
|
AND tj_hp.end_date >= @now
|
254
|
AND ( tj_hp.wage_type = '1205'
|
255
|
OR ( tj_hp.wage_type >= '1231'
|
256
|
AND tj_hp.wage_type <= '1235'
|
257
|
)
|
258
|
OR tj_hp.wage_type IN (
|
259
|
SELECT
|
260
|
val1
|
261
|
FROM
|
262
|
base_cust_parameter
|
263
|
WHERE
|
264
|
param = 'IMFI_WAGE_TYPE_HP'
|
265
|
AND start_date <= @now
|
266
|
AND end_date >= @now )
|
267
|
)
|
268
|
LEFT JOIN dbo.hr_md_emp_md0004 tj_jabatan ON md2.emp_id = tj_jabatan.emp_id -- TJ JABATAN
|
269
|
AND tj_jabatan.start_date <= @now
|
270
|
AND tj_jabatan.end_date >= @now
|
271
|
AND ( tj_jabatan.wage_type = '1202'
|
272
|
OR ( tj_jabatan.wage_type >= '1221'
|
273
|
AND tj_jabatan.wage_type <= '1229'
|
274
|
)
|
275
|
OR tj_jabatan.wage_type IN (
|
276
|
SELECT
|
277
|
val1
|
278
|
FROM
|
279
|
base_cust_parameter
|
280
|
WHERE
|
281
|
param = 'IMFI_WAGE_TYPE_TJ'
|
282
|
AND start_date <= @now
|
283
|
AND end_date >= @now )
|
284
|
)
|
285
|
INNER JOIN @table_hiring hiring ON hiring.emp_id = md2.emp_id
|
286
|
LEFT JOIN dbo.base_cust_ref_emp_office office ON md2.employee_office = office.emp_subarea
|
287
|
AND md2.employee_area = office.emp_area
|
288
|
LEFT JOIN dbo.base_cust_ref_emp_subtype sub ON md2.employee_subtype = sub.emp_subtype
|
289
|
INNER JOIN @table_separation sp ON md2.emp_id = sp.emp_id
|
290
|
INNER JOIN hr_tr0301 TP ON TP.employee_id = md2.emp_id
|
291
|
AND TP.wage_type = 'TP'
|
292
|
AND TP.pay_period_month = @period_month
|
293
|
AND TP.pay_period_year = @period_year
|
294
|
AND TP.run_period_month = @period_month
|
295
|
AND TP.run_period_year = @period_year
|
296
|
INNER JOIN hr_tr0301 TA ON TA.employee_id = md2.emp_id
|
297
|
AND TA.wage_type = '5100'
|
298
|
AND TA.pay_period_month = @period_month
|
299
|
AND TA.pay_period_year = @period_year
|
300
|
AND TA.run_period_month = @period_month
|
301
|
AND TA.run_period_year = @period_year
|
302
|
WHERE md2.landscape = @landscape
|
303
|
--AND md2.movement_type = '80'
|
304
|
--AND md2.emp_id='20030218'
|
305
|
AND md2.start_date <= @now
|
306
|
AND md2.end_date >= @now
|
307
|
AND md2.payroll_group = @pay_group
|
308
|
AND md2.company_id = @companycode
|
309
|
AND ( md2.employee_area = @emp_area
|
310
|
OR @emp_area = ''
|
311
|
)
|
312
|
AND ( md2.employee_office = @emp_office
|
313
|
OR @emp_office = ''
|
314
|
)
|
315
|
|
316
|
END
|