Project

General

Profile

Bug #2617 » Rpt_IMFI_HR_PA_ALL_EMPLOYEE_Service.txt

shofwan shiddiq, 02/27/2024 03:11 PM

 
1

    
2

    
3
ALTER PROCEDURE [dbo].[Rpt_IMFI_HR_PA_ALL_EMPLOYEE_Service]
4
    (
5
      @landscape VARCHAR(3) ,
6
      @companycode VARCHAR(5) ,
7
      @emp_id VARCHAR(100) 
8
    )
9
AS 
10

    
11
--DECLARE @landscape VARCHAR(3) = '100'
12
--DECLARE @companycode VARCHAR(5) = '1000'
13
--DECLARE @emp_id VARCHAR(100) = '20230870'
14

    
15

    
16
DECLARE @now VARCHAR(12) = dbo.fn_formatdatetime(GETDATE(), 'yyyymmdd')
17

    
18
select * into #md1 from hr_md_emp_md0001 with (nolock) where emp_id=@emp_id
19
select * into #md2 from hr_md_emp_md0002 md2 with (nolock)  where emp_id=@emp_id AND  md2.start_date <= @now AND md2.end_date >= @now   
20

    
21

    
22

    
23
       select emp_id ,
24
                edu_level ,
25
                major ,
26
                institution ,
27
                gpa ,
28
                edu_level.description ,
29
				edu_level.description AS edu_level_desc ,
30
                start_date
31
				INTO #tbl_3
32
        FROM    dbo.hr_md_emp_md0008 AS edu
33
                LEFT JOIN base_cust_ref_edu_level AS edu_level ON edu.edu_level = edu_level.code
34
        WHERE   end_date = ( SELECT   MAX(end_date)
35
                               FROM     dbo.hr_md_emp_md0008 AS x
36
                               WHERE    x.emp_id = edu.emp_id AND x.edu_type='F'
37
                             )
38
		ORDER BY edu.seq DESC
39
    
40
    
41
        SELECT DISTINCT
42
                a.org_id_01 AS level1,
43
                a.org_name_01 AS level1_desc,
44
                a.org_id_02 AS level2,
45
                a.org_name_02 AS level2_desc,
46
                a.org_id_03 AS level3,
47
                a.org_name_03 AS level3_desc,
48
                a.org_id_04 AS level4,
49
                a.org_name_04 AS level4_desc ,
50
                a.org_id_05 AS level5,
51
                a.org_name_05 AS level5_desc ,
52
                a.org_id_06 AS level6,
53
                a.org_name_06 AS level6_desc,
54
                a.org_id_07 AS level7,
55
                a.org_name_07 AS level7_desc,
56
                a.org_id_08 AS level8,
57
                a.org_name_08 AS level8_desc,
58
                md2.emp_id AS emp_id
59
				INTO #tbl_1
60
        FROM    dbo.GetOrgInOrgWide('00000001', @now, @landscape) AS a
61
                INNER JOIN #md2 AS md2 ON a.org_id = md2.organization                                                       	 
62
	
63
DECLARE @tbl_2 TABLE
64
    (
65
      emp_id VARCHAR(8) ,
66
      movement_type VARCHAR(2) ,
67
      jumlah DECIMAL(18, 0)
68
    )	
69
INSERT  INTO @tbl_2
70
        SELECT DISTINCT
71
                emp_id ,
72
                movement_type ,
73
                COUNT(start_date)
74
        FROM    #md2
75
        WHERE   movement_type = '60'
76
        GROUP BY emp_id , movement_type
77

    
78

    
79

    
80
        SELECT  tbl2.* ,
81
               '' as datedifff
82
			   INTO #tbl_md2_last
83
        FROM    ( SELECT    landscape ,
84
                            emp_id ,
85
                            start_date ,
86
                            end_date ,
87
                            movement_type ,
88
                            reason ,
89
                            company_id ,
90
                            costcenter ,
91
                            employee_area ,
92
                            employee_office ,
93
                            employee_status ,
94
                            employee_type ,
95
                            employee_subtype ,
96
                            tax_office ,
97
                            payroll_group ,
98
                            organization ,
99
                            position ,
100
                            job ,
101
                            remark ,
102
                            CASE WHEN ISNULL(additional_1, '') = ''
103
                                 THEN start_date
104
                                 ELSE additional_1
105
                            END AS realDate,
106
							CASE WHEN ISNULL(additional_1, '') = ''
107
                                 THEN start_date
108
                                 ELSE additional_1
109
                            END AS additional_1
110
                  FROM      #md2
111
                ) AS tbl2
112

    
113

    
114
				INSERT INTO hr_md_emp_resign
115
SELECT DISTINCT 
116
        md01.emp_id ,
117
        md01.full_name ,
118
        md02_last.company_id ,
119
        CONVERT(DATE, md02_hiring.start_date) AS join_date ,
120
        CASE WHEN md02_last.movement_type = '20' THEN
121
                  CONVERT(DATE, md02_last.start_date)
122
             ELSE 
123
             CONVERT(DATE, md39.date)
124
             
125
             --( SELECT  CONVERT(DATE, date)
126
             --       FROM    hr_md_emp_md0039
127
             --       WHERE   date_type = '04'
128
             --               AND emp_id = md02_last.emp_id
129
             --               AND seq = ()
130
             -- )
131
        END permanent_date ,
132
        CONVERT(DATE, md39_group.date) AS join_group ,
133
        mov_type_last.description AS effective_type_status ,
134
        CONVERT(DATE, md02_last.start_date) AS effective_date ,
135
        CONVERT(DATE, md02_last.additional_1) AS real_date ,
136
        md02_last.employee_status ,
137
        emp_status_last.description AS emp_status ,
138
        CONVERT(DATE, md02_resign.start_date) AS resign_date ,
139
        emp_type_last.description AS employee_type ,
140
        --CASE WHEN ( md39_contract.date >= @now )
141
        --     THEN CONVERT(DATE, md39_contract.date)
142
        --     ELSE NULL
143
        --END expired_status ,
144
		CONVERT(DATE, md39_contract.date) as expired_status,
145
        tbl_2.jumlah AS contract_extent ,
146
        ws_type.description AS workschedule_type ,
147
        md03.tax_status ,
148
        md02_last.employee_area AS area_code ,
149
        emp_area_last.description AS area_desc ,
150
        md02_last.employee_office AS office_code ,
151
        emp_office_last.emp_subarea_description AS office_desc ,
152
        md02_last.payroll_group AS payroll_group_id ,
153
        payroll_group_last.description AS payroll_group ,
154
        emp_sub_type_desc.description AS employee_subtype ,
155
        tbl_1.level1 ,
156
        tbl_1.level1_desc ,
157
        tbl_1.level2 ,
158
        tbl_1.level2_desc ,
159
        tbl_1.level4 ,
160
        tbl_1.level4_desc ,
161
        tbl_1.level5 ,
162
        tbl_1.level5_desc ,
163
        tbl_1.level8 ,
164
        tbl_1.level8_desc ,
165
        md02_last.costcenter AS cc_code ,
166
        cc.description AS cc_desc ,
167
        md02_last.position AS pos_code ,
168
        p.description AS pos_desc ,
169
        pay_grade.description AS pay_grade ,
170
        md01.nick_name ,
171
        gender.description AS gender ,
172
        md01.birth_place ,
173
        CONVERT (DATE, md01.birth_date) AS birth_date ,
174
        md06_resident.street ,
175
        ( SELECT    description
176
          FROM      base_cust_ref_province
177
          WHERE     code = md06_resident.province
178
        ) AS province ,
179
        md06_resident.location ,
180
        md06_resident.postalcode ,
181
        md06_resident.telp_num ,
182
        md12_hp.comm_description AS cellphone ,
183
        md12_email.comm_description AS email ,
184
        religion.description AS religion ,
185
        marital_status.description AS marital_status ,
186
        md11.blood_type ,
187
        md13_ktp.id_description AS id ,
188
        CONVERT(DATE, md13_ktp.end_date) AS ktp_expired ,
189
        md06_ktp.street AS ktp_address ,
190
        ( SELECT    description
191
          FROM      base_cust_ref_province
192
          WHERE     code = md06_ktp.province
193
        ) AS ktp_province ,
194
        md06_ktp.postalcode AS ktp_postalcode ,
195
        ( SELECT    description
196
          FROM      base_cust_ref_id_type
197
          WHERE     code = md13_a.id_type
198
        ) AS id_a ,
199
        md13_a.id_description AS id_a_no ,
200
        CONVERT(DATE, md13_a.end_date) AS id_a_expired ,
201
        ( SELECT    description
202
          FROM      base_cust_ref_id_type
203
          WHERE     code = md13_b.id_type
204
        ) AS id_b ,
205
        md13_b.id_description AS id_b_no ,
206
        CONVERT(DATE, md13_b.end_date) AS id_b_expired ,
207
        ( SELECT    description
208
          FROM      base_cust_ref_id_type
209
          WHERE     code = md13_c.id_type
210
        ) AS id_c ,
211
        md13_c.id_description AS id_c_no ,
212
        CONVERT(DATE, md13_c.end_date) AS id_c_expired ,
213
        md13_passport.id_description AS id_password_no ,
214
        CONVERT(DATE, md13_passport.end_date) AS id_password_expired ,
215
        md06_cp.contact_person AS cp_name ,
216
        md06_cp.street AS cp_address ,
217
        md06_cp.telp_num AS cp_tlp ,
218
        md06_cp.cellphone_num AS cp_cell ,
219
        md03.npwp ,
220
        CASE WHEN md03.npwp_date = '' THEN ''
221
             ELSE dbo.fn_formatdatetime(md03.npwp_date, 'dd mmm yyyy')
222
        END AS npwp_date ,
223
        md03.jamsostek_type ,
224
        jams_type.description AS jams_type ,
225
        md03.jamsostek ,
226
        CASE WHEN md03.additional_1 = '' THEN ''
227
             ELSE dbo.fn_formatdatetime(md03.additional_1, 'dd mmm yyyy')
228
        END AS additional_1 ,
229
        pension_type.description AS pension_type ,
230
        md03.pension_id ,
231
        CASE WHEN md03.additional_2 = '' THEN ''
232
             ELSE dbo.fn_formatdatetime(md03.additional_2, 'dd mmm yyyy')
233
        END AS additional_2 ,
234
        cust_bank_id.description AS bank_id ,
235
        md03.bank_account ,
236
        md03.bank_account_name ,
237
        tbl_3.edu_level_desc ,
238
        tbl_3.major ,
239
        tbl_3.institution ,
240
        tbl_3.gpa ,
241
        md02_last.remark 
242
FROM    #md1 md01 --@tbl_personal AS md01
243
        LEFT JOIN base_cust_ref_gender AS gender ON md01.gender = gender.code
244
        LEFT JOIN base_cust_ref_religion AS religion ON md01.religion = religion.code
245
        LEFT JOIN base_cust_ref_marital_status AS marital_status ON md01.marital_status = marital_status.code
246
        LEFT JOIN #md2 AS md02_hiring ON md01.emp_id = md02_hiring.emp_id			-- Hiring Date
247
                                                     AND md02_hiring.movement_type = '10'
248
        LEFT JOIN #tbl_md2_last AS md02_last ON md01.emp_id = md02_last.emp_id
249
                                                AND md02_last.start_date <= @now		-- Last Assignment dirubah
250
                                                AND md02_last.end_date >= @now
251
                                                AND md02_last.payroll_group <> '99'
252
                                                AND md02_last.datedifff = ( SELECT
253
                                                              MIN(tbl_last.datedifff)
254
                                                              FROM
255
                                                              #tbl_md2_last tbl_last
256
                                                              WHERE
257
                                                              tbl_last.start_date <= @now  --dirubah
258
                                                              AND tbl_last.end_date >= @now
259
                                                              AND tbl_last.payroll_group <> '99'
260
                                                              AND md01.emp_id = tbl_last.emp_id
261
                                                              )
262
        LEFT JOIN hr_md_emp_md0039 AS md39 ON md02_last.emp_id=md39.emp_id AND md39.date_type='04'
263
        LEFT JOIN base_cust_ref_mov_type AS mov_type_last ON md02_last.movement_type = mov_type_last.code
264
        LEFT JOIN base_cust_ref_emp_type AS emp_type_last ON md02_last.employee_type = emp_type_last.emp_type
265
        LEFT JOIN base_cust_ref_emp_area AS emp_area_last ON md02_last.employee_area = emp_area_last.emp_area
266
        LEFT JOIN base_cust_ref_emp_office AS emp_office_last ON md02_last.employee_office = emp_office_last.emp_subarea
267
        LEFT JOIN base_cust_ref_payroll_group AS payroll_group_last ON md02_last.payroll_group = payroll_group_last.payroll_group
268
        LEFT JOIN base_cust_ref_emp_status AS emp_status_last ON md02_last.employee_status = emp_status_last.emp_status
269
        LEFT JOIN base_cust_ref_emp_subtype AS emp_sub_type_desc ON md02_last.employee_subtype = emp_sub_type_desc.emp_subtype
270
        LEFT OUTER JOIN hr_md_orm_object cc ON cc.landscape = @landscape
271
                                               AND cc.start_date <= @now
272
                                               AND cc.end_date >= @now
273
                                               AND md02_last.costcenter = cc.object
274
                                               AND cc.class = 'CC'
275
        LEFT OUTER JOIN hr_md_orm_object o ON o.landscape = @landscape
276
                                              AND o.start_date <= @now
277
                                              AND o.end_date >= @now
278
                                              AND md02_last.organization = o.object
279
                                              AND o.class = 'O'
280
        LEFT OUTER JOIN hr_md_orm_object p ON p.landscape = @landscape
281
                                              AND p.start_date <= @now
282
                                              AND p.end_date >= @now
283
                                              AND md02_last.position = p.object
284
                                     --AND md02_last.payroll_group <> '99'
285
                                              AND p.class = 'P'
286
        LEFT OUTER JOIN hr_md_orm_object j ON j.landscape = @landscape
287
                                              AND j.start_date <= @now
288
                                              AND j.end_date >= @now
289
                                              AND md02_last.job = j.object
290
                                              AND j.class = 'J'
291
        LEFT JOIN hr_md_emp_md0039 AS md39_group ON md01.emp_id = md39_group.emp_id				-- Date Spesification, Join Date Group
292
                                                    AND md39_group.date_type = '10'
293
                                                    AND md39_group.start_date <= @now
294
                                                    AND md39_group.end_date >= @now
295
        LEFT JOIN #md2 AS md02_resign ON md01.emp_id = md02_resign.emp_id			-- Resign
296
                                                     AND md02_resign.movement_type = '80'
297
                                                    --AND md02_resign.end_date = '99991231'
298
        LEFT JOIN #md2 AS md02_contract ON md01.emp_id = md02_contract.emp_id
299
                                                       AND md02_contract.movement_type = '60'
300
        LEFT JOIN hr_md_emp_md0039 AS md39_contract ON md01.emp_id = md39_contract.emp_id		-- Date Spesification, expired contract dengan code 02
301
                                                       AND md39_contract.date_type = '02'
302
                                                       AND md39_contract.date = ( SELECT
303
                                                              MAX(md39_contracte.date)
304
                                                              FROM
305
                                                              hr_md_emp_md0039 md39_contracte
306
                                                              WHERE
307
                                                              md39_contracte.emp_id = md39_contract.emp_id
308
                                                              AND md39_contracte.date_type = '02'
309
                                                              )
310
        LEFT JOIN hr_md_emp_md0025 AS md25 ON md01.emp_id = md25.emp_id							-- Working Schedule
311
                                              AND md25.start_date <= @now
312
                                              AND md25.end_date >= @now
313
        LEFT JOIN hr_tm_workschedule_type AS ws_type ON md25.ws_type = ws_type.workschedule_type
314
        LEFT JOIN hr_md_emp_md0003 AS md03 ON md01.emp_id = md03.emp_id						--Payroll Basic
315
                                              AND md03.start_date <= @now
316
                                              AND md03.end_date >= @now
317
        LEFT JOIN base_cust_ref_jamsostek_type AS jams_type ON md03.jamsostek_type = jams_type.code
318
        LEFT JOIN base_cust_ref_pension_type AS pension_type ON md03.pension_type = pension_type.code
319
        LEFT JOIN base_cust_ref_bankid AS cust_bank_id ON md03.bank_id = cust_bank_id.code
320
        LEFT JOIN base_cust_ref_pay_grade AS pay_grade ON md03.pay_grade = pay_grade.pay_grade
321
        LEFT JOIN hr_md_emp_md0006 AS md06_resident ON md01.emp_id = md06_resident.emp_id
322
                                                       AND md06_resident.address_type = '02'
323
                                                       AND md06_resident.start_date <= @now
324
                                                       AND md06_resident.end_date >= @now
325
                                                       AND md06_resident.seq = ( SELECT
326
                                                              MAX(md06_st.seq)
327
                                                              FROM
328
                                                              hr_md_emp_md0006 md06_st
329
                                                              WHERE
330
                                                              md06_st.address_type = '02'
331
                                                              AND md06_st.emp_id = md06_resident.emp_id
332
                                                              )
333
        LEFT JOIN hr_md_emp_md0012 AS md12_hp ON md01.emp_id = md12_hp.emp_id
334
                                                 AND md12_hp.comm_type = '02'
335
                                                 AND md12_hp.seq = ( SELECT
336
                                                              MAX(md12_st.seq)
337
                                                              FROM
338
                                                              hr_md_emp_md0012 md12_st
339
                                                              WHERE
340
                                                              md12_st.emp_id = md12_hp.emp_id
341
                                                              AND md12_st.comm_type = '02'
342
                                                              )
343
        LEFT JOIN hr_md_emp_md0012 AS md12_email ON md01.emp_id = md12_email.emp_id
344
                                                    AND md12_email.comm_type = '04'
345
                                                    AND md12_email.seq = ( SELECT
346
                                                              MAX(md12e_st.seq)
347
                                                              FROM
348
                                                              hr_md_emp_md0012 md12e_st
349
                                                              WHERE
350
                                                              md12e_st.emp_id = md12_email.emp_id
351
                                                              AND md12e_st.comm_type = '04'
352
                                                              )
353
        LEFT JOIN hr_md_emp_md0011 AS md11 ON md01.emp_id = md11.emp_id
354
        LEFT JOIN hr_md_emp_md0013 AS md13_ktp ON md01.emp_id = md13_ktp.emp_id
355
                                                  AND md13_ktp.id_type = '01'
356
                                                  AND md13_ktp.seq = ( SELECT
357
                                                              MAX(md13_ktpe.seq)
358
                                                              FROM
359
                                                              hr_md_emp_md0013 md13_ktpe
360
                                                              WHERE
361
                                                              md13_ktpe.emp_id = md13_ktp.emp_id
362
                                                              AND md13_ktpe.id_type = '01'
363
                                                              )
364
        LEFT JOIN hr_md_emp_md0013 AS md13_a ON md01.emp_id = md13_a.emp_id
365
                                                AND md13_a.id_type = '03'
366
        LEFT JOIN hr_md_emp_md0013 AS md13_b ON md01.emp_id = md13_b.emp_id
367
                                                AND md13_b.id_type = '04'
368
        LEFT JOIN hr_md_emp_md0013 AS md13_c ON md01.emp_id = md13_c.emp_id
369
                                                AND md13_c.id_type = '05'
370
        LEFT JOIN hr_md_emp_md0013 AS md13_passport ON md01.emp_id = md13_passport.emp_id
371
                                                       AND md13_passport.id_type = '02'
372
        LEFT JOIN hr_md_emp_md0006 AS md06_ktp ON md01.emp_id = md06_ktp.emp_id
373
                                                  AND md06_ktp.address_type = '01'
374
                                                  AND md06_ktp.start_date <= @now
375
                                                  AND md06_ktp.end_date >= @now
376
        LEFT JOIN hr_md_emp_md0006 AS md06_cp ON md01.emp_id = md06_cp.emp_id
377
                                                 AND md06_cp.address_type = '04'
378
                                                 AND md06_cp.start_date <= @now
379
                                                 AND md06_cp.end_date >= @now
380
                                                 AND md06_cp.seq = ( SELECT
381
                                                              MAX(md6_st.seq)
382
                                                              FROM
383
                                                              hr_md_emp_md0006 md6_st
384
                                                              WHERE
385
                                                              md6_st.address_type = '04'
386
                                                              AND md6_st.emp_id = md06_cp.emp_id
387
                                                              )
388
        INNER JOIN hr_md_emp_md0015 AS md15 ON md01.emp_id = md15.emp_id
389
        LEFT JOIN #tbl_1 AS tbl_1 ON md01.emp_id = tbl_1.emp_id
390
        LEFT JOIN @tbl_2 AS tbl_2 ON md01.emp_id = tbl_2.emp_id
391
        LEFT JOIN #tbl_3 AS tbl_3 ON md01.emp_id = tbl_3.emp_id
392
       
393
WHERE   md02_last.company_id = @companycode
394
		AND md01.start_date <= @now
395
		AND md01.end_date >= @now
396
		--AND md02_last.movement_type='80'
397
ORDER BY md02_last.employee_office ,
398
        md01.emp_id
399

    
400
		DROP TABLE #md1
401
		DROP TABLE #md2
402
		DROP TABLE #tbl_3
403
		DROP TABLE #tbl_1
404
		DROP TABLE #tbl_md2_last
(2-2/7)