Project

General

Profile

Bug #1944 » WFPMSDEFAULTKPIP3.sql

package_update - M Azid Wahyudi, 01/18/2023 06:40 PM

 
1
/*DECLARE @empid VARCHAR(8) = '00001359'; DECLARE @appType VARCHAR(8) = 'P3.3' DECLARE @now VARCHAR(8) = dbo.fn_formatdatetime(GETDATE(), 'yyyymmdd') DECLARE @AppraisalPeriod VARCHAR(8) = 'P4323';*/
2
DECLARE @startDate VARCHAR(8);
3
SET @startDate = 
4
(
5
	SELECT Startdate 
6
	FROM PCMAPPPERIOD 
7
	WHERE code =  @AppraisalPeriod
8
)
9
DECLARE @EndDate VARCHAR(8);
10
SET @EndDate = 
11
(
12
	SELECT Enddate 
13
	FROM PCMAPPPERIOD 
14
	WHERE code =  @AppraisalPeriod
15
)
16
DECLARE @job VARCHAR(8) DECLARE @classobject VARCHAR(8) DECLARE @Bobot TABLE (
17
  ObjectID VARCHAR(16), 
18
  Bobot INT
19
) DECLARE @TableTemp TABLE (
20
  Value1 VARCHAR(50), 
21
  Value2 VARCHAR(50)
22
) INSERT INTO @TableTemp 
23
SELECT distinct
24
  GEN.Value1, 
25
  GEN.Value2 
26
FROM 
27
  dbo.PCMEPGENPARAM GEN 
28
WHERE 
29
  Parameter = 'ESSPMSREVIEW4' 
30
DECLARE @Review VARCHAR(8);
31
SET @Review = 
32
(
33
	SELECT 
34
        Case when Value2 = 'Weight6' then 'Review6'
35
		when Value2 = 'Weight3' then 'Review3' 
36
		when Value2 = 'Weight9' then 'Review9'
37
		end 
38
      FROM 
39
        @TableTemp 
40
      WHERE 
41
        Value1 = @appType
42
)
43
if (@Review = 'Review3') 
44
Begin
45
  DECLARE @Query AS VARCHAR(MAX) = CONCAT(
46
    'SELECT DISTINCT KPI,', 
47
    (
48
      SELECT 
49
        Value2 
50
      FROM 
51
        @TableTemp 
52
      WHERE 
53
        Value1 = @appType
54
    ), 
55
    ' as bobot FROM PHROM0007  where Review3 = 1 '
56
  ) INSERT INTO @Bobot EXEC (@Query)
57
SELECT 
58
  DISTINCT @job = CASE WHEN (
59
    pa02.Job IS NULL 
60
    OR pa02.Job = ''
61
  ) THEN pa02.Position ELSE pa02.Job END, 
62
  @classobject = CASE WHEN (
63
    pa02.Job IS NULL 
64
    OR pa02.Job = ''
65
  ) THEN 'P' ELSE 'J' END 
66
FROM 
67
  dbo.PHRPA0002 pa02 
68
WHERE 
69
  pa02.EmployeeID = @empid 
70
  AND pa02.StartDate <= @now 
71
  AND pa02.EndDate >= @now 
72
SELECT 
73
  DISTINCT (
74
    SELECT 
75
      ISNULL(
76
        MAX(Sequence) + 1, 
77
        1
78
      ) 
79
    FROM 
80
      dbo.PHRPA0047 
81
    WHERE 
82
      EmployeeID = @empid 
83
  ) AS HeaderSequence_49_3, 
84
  om02.ObjectID KPIGroup_49_3, 
85
  @empid EmployeeID_49_3, 
86
  om07.KPI KPI_49_3, 
87
  om01.ObjectDescription ObjectDescription_49_3, 
88
  Bbt.Bobot AS Weight_49_3a, 
89
  om07.Weight3 AS Weight_49_3,
90
  1 Target_49_3, 
91
  0 ScoreC_49_3, 
92
  om25.Asumsi Asumsi_49_3, 
93
  om25.Sourcedata SourceData_49_3, 
94
  (
95
    SELECT 
96
      KeyBehavior 
97
    FROM 
98
      CRANGESCORE 
99
    WHERE 
100
      IndexScore = 1 
101
      AND ObjectID = om07.KPI
102
  ) AS Kriteria1_49_3, 
103
  (
104
    SELECT 
105
      KeyBehavior 
106
    FROM 
107
      CRANGESCORE 
108
    WHERE 
109
      IndexScore = 2 
110
      AND ObjectID = om07.KPI
111
  ) AS Kriteria2_49_3, 
112
  0 App1Value_49_3, 
113
  (
114
    SELECT 
115
      KeyBehavior 
116
    FROM 
117
      CRANGESCORE 
118
    WHERE 
119
      IndexScore = 3 
120
      AND ObjectID = om07.KPI
121
  ) AS Kriteria3_49_3, 
122
  0 Unit_49_3, 
123
  0 ScoreNHA1_49_3, 
124
  0 NotesApr2_49_3, 
125
  '' NotesApr3_49_3, 
126
  0 WeightedScore_49_3, 
127
  (
128
    SELECT 
129
      KeyBehavior 
130
    FROM 
131
      CRANGESCORE 
132
    WHERE 
133
      IndexScore = 4 
134
      AND ObjectID = om07.KPI
135
  ) AS Kriteria4_49_3, 
136
  0 App10Percentage_49_3, 
137
  0 App2Value_49_3, 
138
  0 App10Projected_49_3, 
139
  (
140
    SELECT 
141
      KeyBehavior 
142
    FROM 
143
      CRANGESCORE 
144
    WHERE 
145
      IndexScore = 5 
146
      AND ObjectID = om07.KPI
147
  ) AS Kriteria5_49_3, 
148
  0 IsCalculate_49_3, 
149
  0 ScoreNHA2_49_3, 
150
  0 ScoreNHA3_49_3, 
151
  0 SelfValue_49_3, 
152
  0 IsSubKPI_49_3, 
153
  0 App10Value_49_3, 
154
  0 App1Percentage_49_3, 
155
  0 KPAchievementDesc_49_3, 
156
  0 App1Projected_49_3, 
157
  0 AppraiserScore_49_3, 
158
  0 NotesNHA_49_3, 
159
  0 SelfPercentage_49_3, 
160
  0 HasilKriteria_49_3, 
161
  0 SelfProjected_49_3, 
162
  0 App2Percentage_49_3, 
163
  0 App2Projected_49_3, 
164
  ROW_NUMBER() OVER (
165
    ORDER BY 
166
      om07.KPI
167
  ) AS Sequence_49_3, 
168
  0 SequenceSubKPI_49_3, 
169
  0 SubKPI_49_3, 
170
  0 App3Percentage_49_3, 
171
  0 App3Projected_49_3, 
172
  0 SubKPIDescription_49_3, 
173
  0 NotesApr1_49_3, 
174
  0 App3Value_49_3, 
175
  0 App4Percentage_49_3, 
176
  0 App4Projected_49_3, 
177
  0 App4Value_49_3, 
178
  0 App5Percentage_49_3, 
179
  0 App5Projected_49_3, 
180
  0 App5Value_49_3, 
181
  0 App6Percentage_49_3, 
182
  0 App6Projected_49_3, 
183
  0 App6Value_49_3, 
184
  0 App7Percentage_49_3, 
185
  0 App7Projected_49_3, 
186
  0 App7Value_49_3, 
187
  0 App8Percentage_49_3, 
188
  0 App8Projected_49_3, 
189
  0 App8Value_49_3, 
190
  0 App9Percentage_49_3, 
191
  0 App9Projected_49_3, 
192
  0 App9Value_49_3, 
193
  0 Notes_49_3, 
194
  om25.Responsible AS Respondesc_3, 
195
  @appType AS AppraisalType_49_3, 
196
  (
197
    SELECT 
198
      ISNULL(
199
        MAX(Sequence) + 1, 
200
        1
201
      ) 
202
    FROM 
203
      dbo.PHRPA0047 
204
    WHERE 
205
      EmployeeID = @empid
206
  ) AS HeaderSequence_49_3, 
207
  ROW_NUMBER() OVER (
208
    ORDER BY 
209
      om07.KPI
210
  ) AS Sequence_49_3, 
211
  @appType AS AppraisalType_3, 
212
  (
213
    SELECT 
214
      ISNULL(
215
        MAX(Sequence) + 1, 
216
        1
217
      ) 
218
    FROM 
219
      dbo.PHRPA0047 
220
    WHERE 
221
      EmployeeID = @empid 
222
  ) AS HeaderSequence_3, 
223
  ROW_NUMBER() OVER (
224
    ORDER BY 
225
      om07.KPI
226
  ) AS Sequence_3
227
FROM 
228
  PHROM0007 om07 
229
  INNER JOIN dbo.PHROM0001 om01 ON om07.KPI = om01.ObjectID 
230
  AND om01.ObjectClass = 'K' 
231
  INNER JOIN PHROM0002 om02 ON om07.ObjectID = om02.ObjectID 
232
  AND om02.ObjectClass = 'K' 
233
  AND om02.RelationshipClass = 'KG' 
234
  LEFT JOIN dbo.PHROM0025 om25 ON om25.ObjectID = om07.KPI 
235
  AND om25.ObjectClass = 'K' 
236
  AND om25.StartDate <= @now 
237
  AND om25.EndDate >= @now 
238
  INNER JOIN @Bobot Bbt ON om07.KPI = Bbt.ObjectID
239
WHERE 
240
  om07.ObjectClass = @classobject 
241
  AND om07.Review3 = 1 
242
  AND om07.ObjectID = @job
243
  AND om07.StartDate  <= @EndDate
244
  AND om07.EndDate >= @EndDate;
245
END 
246
if (@Review = 'Review6')
247
BEGIN
248
 DECLARE @Query1 AS VARCHAR(MAX) = CONCAT(
249
    'SELECT DISTINCT KPI,', 
250
    (
251
      SELECT 
252
        Value2 
253
      FROM 
254
        @TableTemp 
255
      WHERE 
256
        Value1 = @appType
257
    ), 
258
    ' as bobot FROM PHROM0007  where Review6 = 1 '
259
  ) INSERT INTO @Bobot EXEC (@Query1)
260
SELECT 
261
  DISTINCT @job = CASE WHEN (
262
    pa02.Job IS NULL 
263
    OR pa02.Job = ''
264
  ) THEN pa02.Position ELSE pa02.Job END, 
265
  @classobject = CASE WHEN (
266
    pa02.Job IS NULL 
267
    OR pa02.Job = ''
268
  ) THEN 'P' ELSE 'J' END 
269
FROM 
270
  dbo.PHRPA0002 pa02 
271
WHERE 
272
  pa02.EmployeeID = @empid 
273
  AND pa02.StartDate <= @now 
274
  AND pa02.EndDate >= @now 
275
SELECT 
276
  DISTINCT (
277
    SELECT 
278
      ISNULL(
279
        MAX(Sequence) + 1, 
280
        1
281
      ) 
282
    FROM 
283
      dbo.PHRPA0047 
284
    WHERE 
285
      EmployeeID = @empid 
286
  ) AS HeaderSequence_49_3, 
287
  om02.ObjectID KPIGroup_49_3, 
288
  @empid EmployeeID_49_3, 
289
  om07.KPI KPI_49_3, 
290
  om01.ObjectDescription ObjectDescription_49_3, 
291
  Bbt.Bobot AS Weight_49_3a, 
292
  om07.Weight3 AS Weight_49_3,
293
  1 Target_49_3, 
294
  0 ScoreC_49_3, 
295
  om25.Asumsi Asumsi_49_3, 
296
  om25.Sourcedata SourceData_49_3, 
297
  (
298
    SELECT 
299
      KeyBehavior 
300
    FROM 
301
      CRANGESCORE 
302
    WHERE 
303
      IndexScore = 1 
304
      AND ObjectID = om07.KPI
305
  ) AS Kriteria1_49_3, 
306
  (
307
    SELECT 
308
      KeyBehavior 
309
    FROM 
310
      CRANGESCORE 
311
    WHERE 
312
      IndexScore = 2 
313
      AND ObjectID = om07.KPI
314
  ) AS Kriteria2_49_3, 
315
  0 App1Value_49_3, 
316
  (
317
    SELECT 
318
      KeyBehavior 
319
    FROM 
320
      CRANGESCORE 
321
    WHERE 
322
      IndexScore = 3 
323
      AND ObjectID = om07.KPI
324
  ) AS Kriteria3_49_3, 
325
  0 Unit_49_3, 
326
  0 ScoreNHA1_49_3, 
327
  0 NotesApr2_49_3, 
328
  '' NotesApr3_49_3, 
329
  0 WeightedScore_49_3, 
330
  (
331
    SELECT 
332
      KeyBehavior 
333
    FROM 
334
      CRANGESCORE 
335
    WHERE 
336
      IndexScore = 4 
337
      AND ObjectID = om07.KPI
338
  ) AS Kriteria4_49_3, 
339
  0 App10Percentage_49_3, 
340
  0 App2Value_49_3, 
341
  0 App10Projected_49_3, 
342
  (
343
    SELECT 
344
      KeyBehavior 
345
    FROM 
346
      CRANGESCORE 
347
    WHERE 
348
      IndexScore = 5 
349
      AND ObjectID = om07.KPI
350
  ) AS Kriteria5_49_3, 
351
  0 IsCalculate_49_3, 
352
  0 ScoreNHA2_49_3, 
353
  0 ScoreNHA3_49_3, 
354
  0 SelfValue_49_3, 
355
  0 IsSubKPI_49_3, 
356
  0 App10Value_49_3, 
357
  0 App1Percentage_49_3, 
358
  0 KPAchievementDesc_49_3, 
359
  0 App1Projected_49_3, 
360
  0 AppraiserScore_49_3, 
361
  0 NotesNHA_49_3, 
362
  0 SelfPercentage_49_3, 
363
  0 HasilKriteria_49_3, 
364
  0 SelfProjected_49_3, 
365
  0 App2Percentage_49_3, 
366
  0 App2Projected_49_3, 
367
  ROW_NUMBER() OVER (
368
    ORDER BY 
369
      om07.KPI
370
  ) AS Sequence_49_3, 
371
  0 SequenceSubKPI_49_3, 
372
  0 SubKPI_49_3, 
373
  0 App3Percentage_49_3, 
374
  0 App3Projected_49_3, 
375
  0 SubKPIDescription_49_3, 
376
  0 NotesApr1_49_3, 
377
  0 App3Value_49_3, 
378
  0 App4Percentage_49_3, 
379
  0 App4Projected_49_3, 
380
  0 App4Value_49_3, 
381
  0 App5Percentage_49_3, 
382
  0 App5Projected_49_3, 
383
  0 App5Value_49_3, 
384
  0 App6Percentage_49_3, 
385
  0 App6Projected_49_3, 
386
  0 App6Value_49_3, 
387
  0 App7Percentage_49_3, 
388
  0 App7Projected_49_3, 
389
  0 App7Value_49_3, 
390
  0 App8Percentage_49_3, 
391
  0 App8Projected_49_3, 
392
  0 App8Value_49_3, 
393
  0 App9Percentage_49_3, 
394
  0 App9Projected_49_3, 
395
  0 App9Value_49_3, 
396
  0 Notes_49_3, 
397
  om25.Responsible AS Respondesc_3, 
398
  @appType AS AppraisalType_49_3, 
399
  (
400
    SELECT 
401
      ISNULL(
402
        MAX(Sequence) + 1, 
403
        1
404
      ) 
405
    FROM 
406
      dbo.PHRPA0047 
407
    WHERE 
408
      EmployeeID = @empid
409
  ) AS HeaderSequence_49_3, 
410
  ROW_NUMBER() OVER (
411
    ORDER BY 
412
      om07.KPI
413
  ) AS Sequence_49_3, 
414
  @appType AS AppraisalType_3, 
415
  (
416
    SELECT 
417
      ISNULL(
418
        MAX(Sequence) + 1, 
419
        1
420
      ) 
421
    FROM 
422
      dbo.PHRPA0047 
423
    WHERE 
424
      EmployeeID = @empid 
425
  ) AS HeaderSequence_3, 
426
  ROW_NUMBER() OVER (
427
    ORDER BY 
428
      om07.KPI
429
  ) AS Sequence_3
430
FROM 
431
  PHROM0007 om07 
432
  INNER JOIN dbo.PHROM0001 om01 ON om07.KPI = om01.ObjectID 
433
  AND om01.ObjectClass = 'K' 
434
  INNER JOIN PHROM0002 om02 ON om07.ObjectID = om02.ObjectID 
435
  AND om02.ObjectClass = 'K' 
436
  AND om02.RelationshipClass = 'KG' 
437
  LEFT JOIN dbo.PHROM0025 om25 ON om25.ObjectID = om07.KPI 
438
  AND om25.ObjectClass = 'K' 
439
  AND om25.StartDate <= @now 
440
  AND om25.EndDate >= @now 
441
  INNER JOIN @Bobot Bbt ON om07.KPI = Bbt.ObjectID
442
WHERE 
443
  om07.ObjectClass = @classobject 
444
  AND om07.Review6 = 1 
445
  AND om07.ObjectID = @job
446
  AND om07.StartDate  <= @EndDate
447
  AND om07.EndDate >= @EndDate;
448
END
449

    
450
if (@Review = 'Review9')
451
BEGIN
452
 DECLARE @Query2 AS VARCHAR(MAX) = CONCAT(
453
    'SELECT DISTINCT KPI,', 
454
    (
455
      SELECT 
456
        Value2 
457
      FROM 
458
        @TableTemp 
459
      WHERE 
460
        Value1 = @appType
461
    ), 
462
    ' as bobot FROM PHROM0007  where Review9 = 1 '
463
  ) INSERT INTO @Bobot EXEC (@Query2)
464
SELECT 
465
  DISTINCT @job = CASE WHEN (
466
    pa02.Job IS NULL 
467
    OR pa02.Job = ''
468
  ) THEN pa02.Position ELSE pa02.Job END, 
469
  @classobject = CASE WHEN (
470
    pa02.Job IS NULL 
471
    OR pa02.Job = ''
472
  ) THEN 'P' ELSE 'J' END 
473
FROM 
474
  dbo.PHRPA0002 pa02 
475
WHERE 
476
  pa02.EmployeeID = @empid 
477
  AND pa02.StartDate <= @now 
478
  AND pa02.EndDate >= @now 
479
SELECT 
480
  DISTINCT (
481
    SELECT 
482
      ISNULL(
483
        MAX(Sequence) + 1, 
484
        1
485
      ) 
486
    FROM 
487
      dbo.PHRPA0047 
488
    WHERE 
489
      EmployeeID = @empid 
490
  ) AS HeaderSequence_49_3, 
491
  om02.ObjectID KPIGroup_49_3, 
492
  @empid EmployeeID_49_3, 
493
  om07.KPI KPI_49_3, 
494
  om01.ObjectDescription ObjectDescription_49_3, 
495
  Bbt.Bobot AS Weight_49_3a, 
496
  om07.Weight3 AS Weight_49_3,
497
  1 Target_49_3, 
498
  0 ScoreC_49_3, 
499
  om25.Asumsi Asumsi_49_3, 
500
  om25.Sourcedata SourceData_49_3, 
501
  (
502
    SELECT 
503
      KeyBehavior 
504
    FROM 
505
      CRANGESCORE 
506
    WHERE 
507
      IndexScore = 1 
508
      AND ObjectID = om07.KPI
509
  ) AS Kriteria1_49_3, 
510
  (
511
    SELECT 
512
      KeyBehavior 
513
    FROM 
514
      CRANGESCORE 
515
    WHERE 
516
      IndexScore = 2 
517
      AND ObjectID = om07.KPI
518
  ) AS Kriteria2_49_3, 
519
  0 App1Value_49_3, 
520
  (
521
    SELECT 
522
      KeyBehavior 
523
    FROM 
524
      CRANGESCORE 
525
    WHERE 
526
      IndexScore = 3 
527
      AND ObjectID = om07.KPI
528
  ) AS Kriteria3_49_3, 
529
  0 Unit_49_3, 
530
  0 ScoreNHA1_49_3, 
531
  0 NotesApr2_49_3, 
532
  '' NotesApr3_49_3, 
533
  0 WeightedScore_49_3, 
534
  (
535
    SELECT 
536
      KeyBehavior 
537
    FROM 
538
      CRANGESCORE 
539
    WHERE 
540
      IndexScore = 4 
541
      AND ObjectID = om07.KPI
542
  ) AS Kriteria4_49_3, 
543
  0 App10Percentage_49_3, 
544
  0 App2Value_49_3, 
545
  0 App10Projected_49_3, 
546
  (
547
    SELECT 
548
      KeyBehavior 
549
    FROM 
550
      CRANGESCORE 
551
    WHERE 
552
      IndexScore = 5 
553
      AND ObjectID = om07.KPI
554
  ) AS Kriteria5_49_3, 
555
  0 IsCalculate_49_3, 
556
  0 ScoreNHA2_49_3, 
557
  0 ScoreNHA3_49_3, 
558
  0 SelfValue_49_3, 
559
  0 IsSubKPI_49_3, 
560
  0 App10Value_49_3, 
561
  0 App1Percentage_49_3, 
562
  0 KPAchievementDesc_49_3, 
563
  0 App1Projected_49_3, 
564
  0 AppraiserScore_49_3, 
565
  0 NotesNHA_49_3, 
566
  0 SelfPercentage_49_3, 
567
  0 HasilKriteria_49_3, 
568
  0 SelfProjected_49_3, 
569
  0 App2Percentage_49_3, 
570
  0 App2Projected_49_3, 
571
  ROW_NUMBER() OVER (
572
    ORDER BY 
573
      om07.KPI
574
  ) AS Sequence_49_3, 
575
  0 SequenceSubKPI_49_3, 
576
  0 SubKPI_49_3, 
577
  0 App3Percentage_49_3, 
578
  0 App3Projected_49_3, 
579
  0 SubKPIDescription_49_3, 
580
  0 NotesApr1_49_3, 
581
  0 App3Value_49_3, 
582
  0 App4Percentage_49_3, 
583
  0 App4Projected_49_3, 
584
  0 App4Value_49_3, 
585
  0 App5Percentage_49_3, 
586
  0 App5Projected_49_3, 
587
  0 App5Value_49_3, 
588
  0 App6Percentage_49_3, 
589
  0 App6Projected_49_3, 
590
  0 App6Value_49_3, 
591
  0 App7Percentage_49_3, 
592
  0 App7Projected_49_3, 
593
  0 App7Value_49_3, 
594
  0 App8Percentage_49_3, 
595
  0 App8Projected_49_3, 
596
  0 App8Value_49_3, 
597
  0 App9Percentage_49_3, 
598
  0 App9Projected_49_3, 
599
  0 App9Value_49_3, 
600
  0 Notes_49_3, 
601
  om25.Responsible AS Respondesc_3, 
602
  @appType AS AppraisalType_49_3, 
603
  (
604
    SELECT 
605
      ISNULL(
606
        MAX(Sequence) + 1, 
607
        1
608
      ) 
609
    FROM 
610
      dbo.PHRPA0047 
611
    WHERE 
612
      EmployeeID = @empid
613
  ) AS HeaderSequence_49_3, 
614
  ROW_NUMBER() OVER (
615
    ORDER BY 
616
      om07.KPI
617
  ) AS Sequence_49_3, 
618
  @appType AS AppraisalType_3, 
619
  (
620
    SELECT 
621
      ISNULL(
622
        MAX(Sequence) + 1, 
623
        1
624
      ) 
625
    FROM 
626
      dbo.PHRPA0047 
627
    WHERE 
628
      EmployeeID = @empid 
629
  ) AS HeaderSequence_3, 
630
  ROW_NUMBER() OVER (
631
    ORDER BY 
632
      om07.KPI
633
  ) AS Sequence_3
634
FROM 
635
  PHROM0007 om07 
636
  INNER JOIN dbo.PHROM0001 om01 ON om07.KPI = om01.ObjectID 
637
  AND om01.ObjectClass = 'K' 
638
  INNER JOIN PHROM0002 om02 ON om07.ObjectID = om02.ObjectID 
639
  AND om02.ObjectClass = 'K' 
640
  AND om02.RelationshipClass = 'KG' 
641
  LEFT JOIN dbo.PHROM0025 om25 ON om25.ObjectID = om07.KPI 
642
  AND om25.ObjectClass = 'K' 
643
  AND om25.StartDate <= @now 
644
  AND om25.EndDate >= @now 
645
  INNER JOIN @Bobot Bbt ON om07.KPI = Bbt.ObjectID
646
WHERE 
647
  om07.ObjectClass = @classobject 
648
  AND om07.Review9 = 1 
649
  AND om07.ObjectID = @job
650
  AND om07.StartDate  <= @EndDate
651
  AND om07.EndDate >= @EndDate;
652
END
(2-2/2)