Project

General

Profile

Bug #165 » NEWQUERYIMFI.txt

Saswanto Tampan, 05/19/2021 11:17 AM

 
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
        DECLARE @now VARCHAR(20)
29
        SET @now = dbo.fn_formatdatetime(GETDATE(), 'yyyymmdd')
30

    
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

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