Project

General

Profile

Bug #2617 » Rpt_IMFI_HR_PA_ALL_EMPLOYEE.txt

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

 
1

    
2

    
3

    
4
ALTER PROCEDURE [dbo].[Rpt_IMFI_HR_PA_ALL_EMPLOYEE]
5
    (
6
      @landscape VARCHAR(3) ,
7
      @companycode VARCHAR(5) ,
8
      @emp_status VARCHAR(5) ,
9
      @emp_type VARCHAR(5) ,
10
      @emp_area VARCHAR(5) ,
11
      @emp_office VARCHAR(5) ,
12
      @pay_group VARCHAR(2),
13
	  @emp_staten VARCHAR (20)
14
    )
15
AS 
16

    
17
--DECLARE @landscape VARCHAR(3) = '100'
18
--DECLARE @companycode VARCHAR(5) = '1000'
19
--DECLARE @emp_status VARCHAR(5) = '01'
20
--DECLARE @emp_staten VARCHAR(5) = ''
21
--DECLARE @emp_type VARCHAR(5)= ''
22
--DECLARE @emp_area VARCHAR(5)= ''
23
--DECLARE @emp_office VARCHAR(5) = ''
24
--DECLARE @pay_group VARCHAR(2) = ''
25

    
26
IF @emp_status ='04'
27
BEGIN
28
select * from hr_md_emp_resign
29
END
30

    
31
IF @emp_status ='01' or @emp_status ='02' or @emp_status ='03'
32

    
33
BEGIN
34

    
35
DECLARE @now VARCHAR(12) = dbo.fn_formatdatetime(GETDATE(), 'yyyymmdd')
36
--DECLARE @now VARCHAR(12) = '20150901'
37

    
38
       select emp_id ,
39
                edu_level ,
40
                major ,
41
                institution ,
42
                gpa ,
43
                edu_level.description ,
44
				edu_level.description AS edu_level_desc ,
45
                start_date
46
				INTO #tbl_3
47
        FROM    dbo.hr_md_emp_md0008 AS edu
48
                LEFT JOIN base_cust_ref_edu_level AS edu_level ON edu.edu_level = edu_level.code
49
        WHERE   end_date = ( SELECT   MAX(end_date)
50
                               FROM     dbo.hr_md_emp_md0008 AS x
51
                               WHERE    x.emp_id = edu.emp_id AND x.edu_type='F'
52
                             )
53
		ORDER BY edu.seq DESC
54
    
55
    
56
        SELECT DISTINCT
57
                a.org_id_01 AS level1,
58
                a.org_name_01 AS level1_desc,
59
                a.org_id_02 AS level2,
60
                a.org_name_02 AS level2_desc,
61
                a.org_id_03 AS level3,
62
                a.org_name_03 AS level3_desc,
63
                a.org_id_04 AS level4,
64
                a.org_name_04 AS level4_desc ,
65
                a.org_id_05 AS level5,
66
                a.org_name_05 AS level5_desc ,
67
                a.org_id_06 AS level6,
68
                a.org_name_06 AS level6_desc,
69
                a.org_id_07 AS level7,
70
                a.org_name_07 AS level7_desc,
71
                a.org_id_08 AS level8,
72
                a.org_name_08 AS level8_desc,
73
                md2.emp_id AS emp_id
74
				INTO #tbl_1
75
        FROM    dbo.GetOrgInOrgWide('00000001', @now, @landscape) AS a
76
                INNER JOIN dbo.hr_md_emp_md0002 AS md2 ON a.org_id = md2.organization
77
                                                          AND md2.start_date <= @now
78
                                                          AND md2.end_date >= @now                                                          	 
79
	
80
DECLARE @tbl_2 TABLE
81
    (
82
      emp_id VARCHAR(8) ,
83
      movement_type VARCHAR(2) ,
84
      jumlah DECIMAL(18, 0)
85
    )	
86
INSERT  INTO @tbl_2
87
        SELECT DISTINCT
88
                emp_id ,
89
                movement_type ,
90
                COUNT(start_date)
91
        FROM    dbo.hr_md_emp_md0002 WITH ( NOLOCK )
92
        WHERE   movement_type = '60'
93
        GROUP BY emp_id , movement_type
94

    
95

    
96

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

    
434
		DROP TABLE #tbl_3
435
		DROP TABLE #tbl_1
436
		DROP TABLE #tbl_md2_last
437

    
438
END
(4-4/7)