Project

General

Profile

Bug #2617 » Rpt_IMFI_HR_PA_ALL_EMPLOYEE_JOB.txt

shofwan shiddiq, 02/29/2024 04:20 PM

 
1

    
2

    
3

    
4
ALTER PROCEDURE [dbo].[Rpt_IMFI_HR_PA_ALL_EMPLOYEE_JOB]
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) = '04'
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

    
27
DECLARE @now VARCHAR(12) = dbo.fn_formatdatetime(GETDATE(), 'yyyymmdd')
28
--DECLARE @now VARCHAR(12) = '20150901'
29

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

    
87

    
88

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

    
426
		DROP TABLE #tbl_3
427
		DROP TABLE #tbl_1
428
		DROP TABLE #tbl_md2_last
429

    
430
--END
(6-6/7)