Project

General

Profile

Feature #438 » SQL_ASBI_PKWT.sql

SP - M Azid Wahyudi, 10/13/2021 11:10 AM

 
1
??USE [Bintang_Prod]
2

3
GO
4

5
/****** Object:  StoredProcedure [dbo].[Rpt_Bintang_HR_PA_OffLet_PKWT_New_Amount]    Script Date: 10/11/2021 4:52:11 PM ******/
6

7
SET ANSI_NULLS ON
8

9
GO
10

11
SET QUOTED_IDENTIFIER ON
12

13
GO
14

15
ALTER PROCEDURE [dbo].[Rpt_Bintang_HR_PA_OffLet_PKWT_New_Amount]
16

17
    (
18

19

20

21
      @emp_id VARCHAR(10)
22

23
    )
24

25
AS 
26

27

28

29
--DECLARE @emp_id VARCHAR(10) = '90001763';
30

31

32

33
DECLARE @now VARCHAR(20) = dbo.fn_formatdatetime(GETDATE(), 'yyyymmdd');
34

35
DECLARE @landscape VARCHAR(100);
36

37
SET @landscape = '100';
38

39

40

41
DECLARE @temp_off VARCHAR (100)
42

43
SET @temp_off=( SELECT template_offering
44

45
FROM hr_md_app_md0028			
46

47
WHERE emp_id = @emp_id 
48

49
and start_date <= @now
50

51
and end_date >= @now)
52

53

54

55

56

57

58

59
DECLARE @Tbl_Amount TABLE
60

61
(
62

63
    emp_id VARCHAR(8),
64

65
    ptkp DECIMAL(18, 0),
66

67
    _1000 DECIMAL(18, 0),
68

69
    _1001 DECIMAL(18, 0),
70

71
    _1002 DECIMAL(18, 0),
72

73
    _1005 DECIMAL(18, 0),
74

75
    _1006 DECIMAL(18, 0),
76

77
    _1026 DECIMAL(18, 0),
78

79
    _1030 DECIMAL(18, 0),
80

81
    _1031 DECIMAL(18, 0),
82

83
	_1035 DECIMAL(18, 0)
84

85
);
86

87

88

89

90

91

92

93
DECLARE @Tbl_Amount_1 TABLE
94

95
(
96

97
    emp_id VARCHAR(8),
98

99
    ptkp DECIMAL(18, 0),
100

101
    _1000 DECIMAL(18, 0),
102

103
    _1001 DECIMAL(18, 0),
104

105
    _1002 DECIMAL(18, 0),
106

107
    _1005 DECIMAL(18, 0),
108

109
    _1006 DECIMAL(18, 0),
110

111
    _1026 DECIMAL(18, 0),
112

113
    _1030 DECIMAL(18, 0),
114

115
    _1031 DECIMAL(18, 0),
116

117
	_1035 DECIMAL(18, 0),
118

119
    insentif_kinerja DECIMAL(18, 0),
120

121
    JHT DECIMAL(18, 0),
122

123
    JKK DECIMAL(18, 0),
124

125
    JKM DECIMAL(18, 0),
126

127
    Pensiun DECIMAL(18, 0),
128

129
    Kesehatan DECIMAL(18, 0)
130

131
);
132

133

134

135

136

137
DECLARE @Tbl_Amount_2 TABLE
138

139
(
140

141
    emp_id VARCHAR(8),
142

143
    ptkp DECIMAL(18, 0),
144

145
    _1000 DECIMAL(18, 0),
146

147
    _1001 DECIMAL(18, 0),
148

149
    _1002 DECIMAL(18, 0),
150

151
    _1005 DECIMAL(18, 0),
152

153
    _1006 DECIMAL(18, 0),
154

155
    _1026 DECIMAL(18, 0),
156

157
    _1030 DECIMAL(18, 0),
158

159
    _1031 DECIMAL(18, 0),
160

161
	_1035 DECIMAL(18, 0),
162

163
    insentif_kinerja DECIMAL(18, 0),
164

165
    JHT DECIMAL(18, 0),
166

167
    JKK DECIMAL(18, 0),
168

169
    JKM DECIMAL(18, 0),
170

171
    Pensiun DECIMAL(18, 0),
172

173
    Kesehatan DECIMAL(18, 0),
174

175
    TotalPendapatan DECIMAL(18, 0),
176

177
    GajiNettoSetahun DECIMAL(18, 0),
178

179
    PphTerutang DECIMAL(18, 0),
180

181
    JHT_pot DECIMAL(18, 0),
182

183
    Pensiun_pot DECIMAL(18, 0),
184

185
    Kesehatan_pot DECIMAL(18, 0)
186

187
);
188

189

190

191
DECLARE @Tbl_Amount_3 TABLE
192

193
(
194

195
    emp_id VARCHAR(8),
196

197
    ptkp DECIMAL(18, 0),
198

199
    _1000 DECIMAL(18, 0),
200

201
    _1001 DECIMAL(18, 0),
202

203
    _1002 DECIMAL(18, 0),
204

205
    _1005 DECIMAL(18, 0),
206

207
    _1006 DECIMAL(18, 0),
208

209
    _1026 DECIMAL(18, 0),
210

211
    _1030 DECIMAL(18, 0),
212

213
    _1031 DECIMAL(18, 0),
214

215
	_1035 DECIMAL(18, 0),
216

217
    insentif_kinerja DECIMAL(18, 0),
218

219
    JHT DECIMAL(18, 0),
220

221
    JKK DECIMAL(18, 0),
222

223
    JKM DECIMAL(18, 0),
224

225
    Pensiun DECIMAL(18, 0),
226

227
    Kesehatan DECIMAL(18, 0),
228

229
    TotalPendapatan DECIMAL(18, 0),
230

231
    GajiNettoSetahun DECIMAL(18, 0),
232

233
    PphTerutang DECIMAL(18, 0),
234

235
    pphbulanan DECIMAL(18, 0),
236

237
    JHT_pot DECIMAL(18, 0),
238

239
    Pensiun_pot DECIMAL(18, 0),
240

241
    Kesehatan_pot DECIMAL(18, 0),
242

243
    TotalPotongan DECIMAL(18, 0),
244

245
    Thp DECIMAL(18, 0)
246

247
);
248

249

250

251
INSERT INTO @Tbl_Amount
252

253
SELECT *
254

255
FROM
256

257
(
258

259
    SELECT DISTINCT
260

261
           md4.emp_id,
262

263
           md4.wage_type,
264

265
           CONVERT(DECIMAL(18, 0), dbo.SDE(md4.amount, N'M!N0V@2010')) AS amount,
266

267
           ptkp.ptkp
268

269
    FROM hr_md_app_md0004 md4
270

271
        LEFT JOIN dbo.hr_md_app_md0003 md3
272

273
            ON md4.emp_id = md3.emp_id
274

275
        LEFT JOIN dbo.hr_cu0302 ptkp
276

277
            ON md3.tax_status = ptkp.status
278

279
    WHERE md4.emp_id = @emp_id
280

281
) AS SourceTable
282

283
PIVOT
284

285
(
286

287
    MIN(amount)
288

289
    FOR wage_type IN ([1000], [1001], [1002], [1005], [1006], [1026], [1030], [1031],[1035])
290

291
) AS pvt;
292

293

294

295

296

297

298

299
INSERT INTO @Tbl_Amount_1
300

301
SELECT emp_id,
302

303
       ptkp,
304

305
       CONVERT(DECIMAL(18,2),ISNULL(_1000,0)) AS gapok,
306

307
       CONVERT(DECIMAL(18,2),ISNULL(_1001,0)) AS tunj_tetap,
308

309
       CONVERT(DECIMAL(18,2),ISNULL(_1002,0)) AS tunj_kehadiran,
310

311
       CONVERT(DECIMAL(18,2),ISNULL(_1005,0)) AS tunj_operasional,
312

313
       CONVERT(DECIMAL(18,2),ISNULL(_1006,0)) AS tunj_transport,
314

315
       CONVERT(DECIMAL(18,2),ISNULL(_1026,0)) AS tunj_kemahalan,
316

317
       CONVERT(DECIMAL(18,2),_1000) +  CONVERT(DECIMAL(18,2),ISNULL(_1001,0)) AS honorarium,
318

319
        CONVERT(DECIMAL(18,2),ISNULL(_1031,0)) AS tunjangan_lain2,
320

321
	    CONVERT(DECIMAL(18,2),ISNULL(_1035,0)) AS _0135,
322

323
       ( CONVERT(DECIMAL(18,2),_1000) + CONVERT(DECIMAL(18,2),ISNULL(_1001,0))) * 15 / 100 AS insentif_kinerja,
324

325
         ( CONVERT(DECIMAL(18,2),_1000) + CONVERT(DECIMAL(18,2),ISNULL(_1001,0))) * 3.7 / 100 AS JHT,
326

327
      ( CONVERT(DECIMAL(18,2),_1000) + CONVERT(DECIMAL(18,2),ISNULL(_1001,0))) * 0.24 / 100 AS JKK,
328

329
        ( CONVERT(DECIMAL(18,2),_1000) + CONVERT(DECIMAL(18,2),ISNULL(_1001,0))) * 0.3 / 100 AS JKM,
330

331
         ( CONVERT(DECIMAL(18,2),_1000) + CONVERT(DECIMAL(18,2),ISNULL(_1001,0))) * 2 / 100 AS Pensiun,
332

333
         ( CONVERT(DECIMAL(18,2),_1000) + CONVERT(DECIMAL(18,2),ISNULL(_1001,0))) * 4 / 100 AS Kesehatan
334

335
FROM @Tbl_Amount;
336

337

338

339

340

341
INSERT INTO @Tbl_Amount_2
342

343
SELECT a.emp_id,
344

345
       a.ptkp,
346

347
       a._1000 AS gapok,
348

349
       a._1001 AS tunj_tetap,
350

351
       a._1002 AS tunj_kehadiran,
352

353
       a._1005 AS tunj_operasional,
354

355
       a._1006 AS tunj_transport,
356

357
       a._1026 AS tunj_kemahalan,
358

359
       CONVERT(DECIMAL(18,2),_1000) +  CONVERT(DECIMAL(18,2),_1001)  AS honorarium,
360

361
       a._1031 AS tunjangan_lain2,
362

363
	   a._1035,
364

365
       a.insentif_kinerja,
366

367
       a.JHT,
368

369
       a.JKK,
370

371
       a.JKM,
372

373
       a.Pensiun,
374

375
       a.Kesehatan,
376

377
       a._1000 + a._1001 + 630000 + a._1005 + a._1006 + a._1026  + a._1031 + a.insentif_kinerja + a.JHT
378

379
       + a.JKK + a.JKM + a.Pensiun + a.Kesehatan AS TotalPendapatan,
380

381

382

383
       ((a._1000 + a._1001 + a._1002 + a._1005 + a._1006 + a._1026  + a._1031 + a.insentif_kinerja + a.JHT
384

385
         + a.JKK + a.JKM + a.Pensiun + a.Kesehatan
386

387
        ) - (124000)
388

389
       ) * 12 AS GajiNettoSetahun,
390

391
       (((a._1000 + a._1001 + a._1002 + a._1005 + a._1006 + a._1026  + a._1031 + a.insentif_kinerja + a.JHT
392

393
          + a.JKK + a.JKM + a.Pensiun + a.Kesehatan
394

395
         ) - (124000)
396

397
        ) * 12
398

399
       ) - a.ptkp AS pph_terutang,
400

401
       ( a._1000 + a._1001 ) * 2 / 100 AS JHT_pot,
402

403
         ( a._1000 + a._1001 ) * 1 / 100 AS Penisun_pot,
404

405
         ( a._1000 + a._1001 ) * 1 / 100 AS Kesehatan_pot
406

407
FROM @Tbl_Amount_1 a;
408

409

410

411
INSERT INTO @Tbl_Amount_3
412

413
SELECT emp_id,
414

415
       ptkp,
416

417
       _1000 AS gapok,
418

419
       _1001 AS tunj_tetap,
420

421
       _1002 AS tunj_kehadiran,
422

423
       _1005 AS tunj_operasional,
424

425
       _1006 AS tunj_transport,
426

427
       _1026 AS tunj_kemahalan,
428

429
       CONVERT(DECIMAL(18,2),_1000) +  CONVERT(DECIMAL(18,2),_1001) AS honorarium,
430

431
       _1031 AS tunjangan_lain2,
432

433
	   _1035,
434

435
       insentif_kinerja,
436

437
       JHT,
438

439
       JKK,
440

441
       JKM,
442

443
       Pensiun,
444

445
       Kesehatan,
446

447
       TotalPendapatan,
448

449
       GajiNettoSetahun,
450

451
       PphTerutang,
452

453
       [dbo].[BracketAmount](PphTerutang) / 12 AS pphbulanan,
454

455
       JHT_pot,
456

457
       Pensiun_pot,
458

459
       Kesehatan_pot,
460

461
       (([dbo].[BracketAmount](PphTerutang) / 12) + JHT + JKK + JKM + Pensiun + Kesehatan + JHT_pot + Pensiun_pot
462

463
        + Kesehatan_pot
464

465
       ) AS TotalPotongan,
466

467

468

469
       TotalPendapatan
470

471
       - (([dbo].[BracketAmount](PphTerutang) / 12) + JHT + JKK + JKM + Pensiun + Kesehatan + JHT_pot + Pensiun_pot
472

473
          + Kesehatan_pot
474

475
         ) AS Thp
476

477
FROM @Tbl_Amount_2;
478

479

480

481
DECLARE @Tbl_Amount_4 TABLE
482

483
(
484

485
    emp_id VARCHAR(8),
486

487
    ptkp DECIMAL(18, 0),
488

489
    _1000 DECIMAL(18, 0),
490

491
    _1001 DECIMAL(18, 0),
492

493
    _1002 DECIMAL(18, 0),
494

495
    _1005 DECIMAL(18, 0),
496

497
    _1006 DECIMAL(18, 0),
498

499
    _1026 DECIMAL(18, 0),
500

501
    _1030 DECIMAL(18, 0),
502

503
    _1031 DECIMAL(18, 0),
504

505
	_1035 DECIMAL(18, 0),
506

507
    insentif_kinerja DECIMAL(18, 0),
508

509
    JHT DECIMAL(18, 0),
510

511
    JKK DECIMAL(18, 0),
512

513
    JKM DECIMAL(18, 0),
514

515
    Pensiun DECIMAL(18, 0),
516

517
    Kesehatan DECIMAL(18, 0),
518

519
    TotalPendapatan DECIMAL(18, 0),
520

521
    GajiNettoSetahun DECIMAL(18, 0),
522

523
    PphTerutang DECIMAL(18, 0),
524

525
    pphbulanan DECIMAL(18, 0),
526

527
    JHT_pot DECIMAL(18, 0),
528

529
    Pensiun_pot DECIMAL(18, 0),
530

531
    Kesehatan_pot DECIMAL(18, 0),
532

533
    TotalPotongan DECIMAL(18, 0),
534

535
    Thp DECIMAL(18, 0)
536

537
);
538

539
INSERT INTO @Tbl_Amount_4
540

541
SELECT emp_id,
542

543
       ptkp,
544

545
       _1000 AS gapok,
546

547
       _1001 AS tunj_tetap,
548

549
       _1002 AS tunj_kehadiran,
550

551
       _1005 AS tunj_operasional,
552

553
       _1006 AS tunj_transport,
554

555
       _1026 AS tunj_kemahalan,
556

557
       CONVERT(DECIMAL(18,2),_1000) +  CONVERT(DECIMAL(18,2),_1001) AS honorarium,
558

559
       _1031 AS tunjangan_lain2,
560

561
	   _1035 ,
562

563
       insentif_kinerja,
564

565
       JHT,
566

567
       JKK,
568

569
       JKM,
570

571
       Pensiun,
572

573
       Kesehatan,
574

575
       TotalPendapatan +pphbulanan  AS TotalPendapatan,
576

577
    (((  TotalPendapatan +pphbulanan)-pphbulanan)-124000)*12  AS  GajiNettoSetahun,
578

579
      ( (((  TotalPendapatan +pphbulanan)-pphbulanan)-124000)*12 )-ptkp AS PphTerutang,
580

581
       pphbulanan,
582

583
       JHT_pot,
584

585
       Pensiun_pot,
586

587
       Kesehatan_pot,
588

589
       TotalPotongan,
590

591
       ( TotalPendapatan +pphbulanan)-TotalPotongan AS Thp
592

593
FROM @Tbl_Amount_3;
594

595

596

597
SELECT 
598

599

600

601
emp_id,
602

603
    ptkp ,
604

605
          _1000 AS gapok,
606

607
       _1001 AS tunj_tetap,
608

609
       _1002 AS tunj_kehadiran,
610

611
       _1005 AS tunj_operasional,
612

613
       _1006 AS tunj_transport,
614

615
       _1026 AS tunj_kemahalan,
616

617
       CONVERT(DECIMAL(18,2),ISNULL(_1000,0)) +  CONVERT(DECIMAL(18,2),ISNULL(_1001,0)) AS honorarium,
618

619
       _1031 AS tunjangan_lain2,
620

621
	   @temp_off,
622

623
	   CASE WHEN @temp_off = '002' THEN ISNULL( _1035,0) 
624

625
	ELSE 1 END AS tunjangan_Komunikasi,
626

627
    insentif_kinerja ,
628

629
    JHT ,
630

631
    JKK ,
632

633
    JKM ,
634

635
    Pensiun ,
636

637
    Kesehatan,
638

639
    TotalPendapatan ,
640

641
    GajiNettoSetahun ,
642

643
    CASE WHEN PphTerutang > 0 THEN PphTerutang ELSE 0 END AS PphTerutang ,
644

645
	CASE WHEN ([dbo].[BracketAmount](PphTerutang) / 12 ) > 0 THEN ([dbo].[BracketAmount](PphTerutang) / 12 ) ELSE 0 END AS pphbulanan,
646

647
	CASE WHEN  @temp_off > 1 THEN 'Tunjangan Komunikasi (reimbursment)'
648

649
	ELSE '' END AS point_11,
650

651
    --pphbulanan,
652

653
    JHT_pot ,
654

655
    Pensiun_pot ,
656

657
    Kesehatan_pot,
658

659
    TotalPotongan ,
660

661
    Thp 
662

663
	
664

665
	from
666

667
	@Tbl_Amount_4
668

669

670

671

672

673

(5-5/5)