Project

General

Profile

Bug #3660 » CRPTLPPOMESSPAYSLIP_20250613.sql

Tri Rizqiaty, 06/13/2025 11:11 AM

 
1
??ALTER PROCEDURE [dbo].[CRPTLPPOMESSPAYSLIP]
2

3
    (
4

5
      @PayPeriod VARCHAR(6) ,
6

7
      @EmpID VARCHAR(20) ,
8

9
      @Running VARCHAR(2) ,
10

11
      @PayType VARCHAR(2) 
12

13
    )
14

15
AS
16

17

18

19
    --DECLARE @PayPeriod VARCHAR(6) = '202501'
20

21
    --DECLARE @EmpID VARCHAR(8) = '00000002'
22

23
    --DECLARE @Running VARCHAR(2) = '1'
24

25
    --DECLARE @PayType VARCHAR(2) = ''
26

27
    
28

29

30

31
    DECLARE @CompanyCode AS VARCHAR(50) 
32

33
    DECLARE @CompanyName AS VARCHAR(250) 
34

35
    DECLARE @CompanyLogo AS VARBINARY(MAX)
36

37
    DECLARE @PayMonth AS NVARCHAR(2)
38

39
    DECLARE @PayYear AS NVARCHAR(4)
40

41
    DECLARE @Begda AS NVARCHAR(8)
42

43
    DECLARE @Endda AS NVARCHAR(8)
44

45

46

47
    SET @PayMonth = RIGHT(@PayPeriod, 2)
48

49
    SET @PayYear = LEFT(@PayPeriod, 4)
50

51
    SET @Begda = @PayPeriod + '01'
52

53
    SET @Endda = CONVERT(NVARCHAR(8), DATEADD(d, -1, DATEADD(m, 1, @Begda)), 112)
54

55
    
56

57
   
58

59

60

61
    DECLARE @PaySlipSigned AS NVARCHAR(50)
62

63

64

65
    SELECT TOP ( 1 )
66

67
            @PaySlipSigned = Value
68

69
    FROM    dbo.PHRPYCU0307
70

71
    WHERE   ( PayrollParameter = 'PAYSLIPSIGNED' )
72

73
            AND ( StartDate <= @Endda
74

75
                  AND EndDate >= @Endda
76

77
                )
78

79

80

81
    IF ( @Running = '1' )
82

83
        BEGIN
84

85
            SELECT TOP ( 1 )
86

87
                    @CompanyCode = CompanyID
88

89
            FROM    dbo.PHRPYTR0300 
90

91
             WHERE   ( EmployeeID = @EmpID )
92

93
                    AND ( PayPeriodMonth = @PayMonth )
94

95
                    AND ( PayPeriodYear = @PayYear )
96

97
                    AND ( RunPeriodMonth = @PayMonth )
98

99
                    AND ( RunPeriodYear = @PayYear )
100

101
        END
102

103
    ELSE
104

105
        BEGIN
106

107
            SELECT TOP ( 1 )
108

109
                    @CompanyCode = CompanyID
110

111
            FROM    dbo.PHRPYTR0300SIM
112

113
            WHERE   ( EmployeeID = @EmpID )
114

115
                    AND ( PayPeriodMonth = @PayMonth )
116

117
                    AND ( PayPeriodMonth = @PayYear )
118

119
                    AND ( RunPeriodMonth = @PayMonth )
120

121
                    AND ( RunPeriodYear = @PayYear )
122

123
        END
124

125

126

127
       
128

129

130

131
    SELECT  @CompanyName = COM.CompanyDescription ,
132

133
            @CompanyLogo = CAT.FileData
134

135
    FROM    dbo.PCMEPCOMPID AS COM
136

137
	LEFT JOIN dbo.SFILECATALOG CAT ON COM.Logo = CAT.FileName
138

139
    WHERE   ( CompanyID = @CompanyCode )
140

141
            AND StartDate <= @Endda
142

143
            AND EndDate >= @Endda
144

145

146

147
	DECLARE @Disclaimer VARCHAR(250)
148

149
	SELECT @Disclaimer = Value1 FROM dbo.PCMEPGENPARAM WHERE Parameter = 'DISCLAIMEREPAYSLIP'
150

151

152

153

154

155
	IF @CompanyCode = '3000'
156

157
	BEGIN 
158

159
	SELECT @Disclaimer = Value1 FROM dbo.PCMEPGENPARAM WHERE Parameter = 'DISCLAIMEREPAYSLIPIHATEC'
160

161
	END
162

163

164

165
	----//---- get hari kerja start
166

167
	DECLARE @TotHK DECIMAL(18,0)
168

169
	SELECT @TotHK = COUNT(pa125.StartDate)
170

171
	FROM PHRPA0025 AS pa25
172

173
	LEFT JOIN PHRPA0125 AS pa125
174

175
		ON pa25.EmployeeID = pa125.EmployeeID
176

177
	WHERE pa25.EmployeeID = @EmpID
178

179
		AND pa25.StartDate <= @Endda AND pa25.EndDate >= @Endda
180

181
		AND pa125.StartDate >= @Begda AND pa125.StartDate <= @Endda
182

183
		AND pa125.DayType IN (SELECT DayType FROM dbo.PHRTMDAYTYP WHERE Flag = 'WORK')
184

185
	----//---- get hari kerja end
186

187

188

189
    IF ( @Running = '1' )
190

191
        BEGIN   
192

193
		
194

195
            SELECT  @PaySlipSigned PaySlipSigned ,
196

197
                    @CompanyName CompanyName ,
198

199
                    @CompanyLogo logo ,
200

201
                    c308.ReportID ,
202

203
                    c308.GroupBy ,
204

205
                    c308P.PayslipDescription ParentDescription ,
206

207
                    c308.Sequence ,
208

209
                    c308.PayslipDescription ,
210

211
                    c308.PayrollType ,
212

213
                    c308.WageType ,
214

215
                    c308.IsDisplayWageType ,
216

217
                    c308.IsDisplayNumber ,
218

219
                    c308.IsDisplayRate ,
220

221
                    c308.IsDisplayAmount ,
222

223
                    c308.StartDate ,
224

225
                    c308.EndDate ,
226

227
                    c308.IsActive ,
228

229
                    c308.ChangeBy ,
230

231
                    c308.ChangeDate ,
232

233
                    c308.CreateBy ,
234

235
                    c308.CreateDate ,
236

237
                    tr301.EmployeeID ,
238

239
                    tr301.PayPeriodMonth ,
240

241
                    tr301.PayPeriodYear ,
242

243
                    tr301.RunPeriodMonth ,
244

245
                    tr301.RunPeriodYear ,
246

247
                    tr301.SplitIndicator ,
248

249
					CAST(REPLACE(ISNULL(dbo.GetPEN(tr301.Rate), '0'), ',', '.') AS DECIMAL) 'rate' ,
250

251
                    CAST(REPLACE(ISNULL(dbo.GetPEN(tr301.Amount), '0'), ',','.') AS DECIMAL) 'amount' ,
252

253
                    tr301.Number ,
254

255
                    tr301.Currency ,
256

257
                    tr301.Flag ,
258

259
                    md001.FullName ,
260

261
					md001.ExternalID ,
262

263
                    md003.TaxStatus ,
264

265
                    taxstat.TaxStatusDescription TaxStatusDesc ,
266

267
                    md001.MaritalStatus ,
268

269
                    ms.MaritalStatusDescription MaritalDesc ,
270

271
                    md003.PayrollType AS PayIndustry ,
272

273
                    md003.PayrollArea ,
274

275
                    md003.PayrollClass ,
276

277
                    md003.PayrollGrade ,
278

279
                    md003.NPWP ,
280

281
                    grd.PayrollGradeDescription AS PayGradeDesc ,
282

283
                    md002.Job ,
284

285
                    md002.EmployeeArea ,
286

287
                    area.EmployeeAreaDescription AreaDesc ,
288

289
                    md002.Organization ,
290

291
                    md002.OrgEasy AS OrgDesc, --org.ObjectDescription OrgDesc , ----// comment for ekno
292

293
                    md002.Position ,
294

295
                    md002.PositionEasy AS PosDesc --pos.ObjectDescription PosDesc ----// comment for ekno
296

297
					,@Disclaimer AS Disclaimer
298

299
					,pa22.BenefitNo AS NoKPJ
300

301
					,@TotHK AS TotHK
302

303
            FROM    dbo.PHRPYCU0308 AS c308
304

305
                    LEFT JOIN dbo.PHRPYCU0308 AS c308P ON c308.GroupBy = c308P.ReportID
306

307
					INNER JOIN ( SELECT * ,
308

309
                                        'N' RetroType
310

311
                                 FROM   PHRPYTR0301
312

313
                                 UNION ALL
314

315
                                 SELECT * ,
316

317
                                        'R' RetroType
318

319
                                 FROM   PHRPYTR0301RET
320

321
                               ) tr301 ON c308.WageType = tr301.WageType
322

323
                                          AND c308.RetroType = tr301.RetroType
324

325
                                          AND ( c308.PayrollType = @PayType OR @PayType = '' )
326

327
                    INNER JOIN ( SELECT m1.*
328

329
                                 FROM   dbo.PHRPA0001 m1
330

331
                                 WHERE  ( m1.StartDate <= @Endda AND m1.EndDate >= @Endda)
332

333
                               ) md001 ON md001.EmployeeID = tr301.EmployeeID
334

335
                    LEFT JOIN ( SELECT  m1.*
336

337
                                FROM    dbo.PHRPA0003 m1
338

339
                                WHERE   ( m1.StartDate <= @Endda AND m1.EndDate >= @Endda)
340

341
                              ) md003 ON md001.EmployeeID = md003.EmployeeID
342

343
                    LEFT JOIN ( SELECT  m1.*
344

345
                                FROM    dbo.PHRPA0002 m1
346

347
                                WHERE   ( m1.StartDate <= @Endda AND m1.EndDate >= @Endda)
348

349
                              ) md002 ON tr301.EmployeeID = md002.EmployeeID
350

351
                    LEFT JOIN dbo.PCMEPEMPAREA area ON md002.EmployeeArea = area.EmployeeArea
352

353
                                                       AND area.StartDate <= @Endda AND area.EndDate >= @Endda
354

355
                    LEFT JOIN ( SELECT  m1.*
356

357
                                FROM    dbo.PHROM0001 m1
358

359
                                WHERE   ObjectClass = 'O'
360

361
                                AND (StartDate <= @Endda AND EndDate >= @Endda)
362

363
                              ) org ON md002.Organization = org.ObjectID
364

365
                    LEFT JOIN ( SELECT  m1.*
366

367
                                FROM    PHROM0001 m1
368

369
                                WHERE   ObjectClass = 'P'
370

371
                                AND (StartDate <= @Endda AND EndDate >= @Endda)
372

373
                              ) pos ON md002.Position = pos.ObjectID
374

375
                    LEFT JOIN dbo.PHRPYPGRAD grd ON md003.PayrollGrade = grd.PayrollGrade
376

377
													AND md003.PayrollClass = grd.PayrollClass
378

379
                                                    AND grd.StartDate <= @Endda
380

381
                                                    AND grd.EndDate >= @Endda
382

383
                    LEFT JOIN dbo.PHRPAMSTAT ms ON md001.MaritalStatus = ms.MaritalStatus
384

385
                                                   AND ms.StartDate <= @Endda
386

387
                                                   AND ms.EndDate >= @Endda
388

389
                    LEFT JOIN dbo.PHRPYTAXSTAT taxstat ON md003.TaxStatus = taxstat.TaxStatus
390

391
                                                          AND taxstat.StartDate <= @Endda
392

393
                                                          AND taxstat.EndDate >= @Endda
394

395
					LEFT JOIN dbo.PHRPA0022 pa22 ON md002.EmployeeID = pa22.EmployeeID
396

397
													AND pa22.StartDate <= @Endda AND pa22.EndDate >= @Endda
398

399
            WHERE   tr301.EmployeeID = @EmpID
400

401
                    AND tr301.PayPeriodMonth = @PayMonth
402

403
                    AND tr301.PayPeriodYear = @PayYear
404

405
                    AND tr301.RunPeriodMonth = @PayMonth
406

407
                    AND tr301.RunPeriodYear = @PayYear
408

409
                    AND CAST(REPLACE(ISNULL(dbo.GetPEN(tr301.Amount), '0'),
410

411
                                     ',', '.') AS DECIMAL) <> 0
412

413
            ORDER BY c308.GroupBy ,
414

415
                    c308.WageType
416

417
        END
418

419
    ELSE
420

421
        BEGIN   
422

423
		
424

425
            SELECT  @PaySlipSigned PaySlipSigned ,
426

427
                    @CompanyName CompanyName ,
428

429
                    @CompanyLogo logo ,
430

431
                    c308.ReportID ,
432

433
                    c308.GroupBy ,
434

435
                    c308P.PayslipDescription ParentDescription ,
436

437
                    c308.Sequence ,
438

439
                    c308.PayslipDescription ,
440

441
                    c308.PayrollType ,
442

443
                    c308.WageType ,
444

445
                    c308.IsDisplayWageType ,
446

447
                    c308.IsDisplayNumber ,
448

449
                    c308.IsDisplayRate ,
450

451
                    c308.IsDisplayAmount ,
452

453
                    c308.StartDate ,
454

455
                    c308.EndDate ,
456

457
                    c308.IsActive ,
458

459
                    c308.ChangeBy ,
460

461
                    c308.ChangeDate ,
462

463
                    c308.CreateBy ,
464

465
                    c308.CreateDate ,
466

467
                    tr301Sim.EmployeeID ,
468

469
                    tr301Sim.PayPeriodMonth ,
470

471
                    tr301Sim.PayPeriodYear ,
472

473
                    tr301Sim.RunPeriodMonth ,
474

475
                    tr301Sim.RunPeriodYear ,
476

477
                    tr301Sim.SplitIndicator ,
478

479
                    CAST(REPLACE(ISNULL(dbo.GetPEN(tr301Sim.Rate), '0'), ',',
480

481
                                 '.') AS DECIMAL) 'rate' ,
482

483
                    CAST(REPLACE(ISNULL(dbo.GetPEN(tr301Sim.Amount), '0'), ',',
484

485
                                 '.') AS DECIMAL) 'amount' ,
486

487
                    CAST(REPLACE(ISNULL(dbo.GetPEN(tr301RSim.Rate), '0'), ',',
488

489
                                 '.') AS DECIMAL) 'rate_r' ,
490

491
                    CAST(REPLACE(ISNULL(dbo.GetPEN(tr301RSim.Amount), '0'),
492

493
                                 ',', '.') AS DECIMAL) 'amount_r' ,
494

495
                    ( CAST(REPLACE(ISNULL(dbo.GetPEN(tr301Sim.Rate), '0'), ',',
496

497
                                   '.') AS DECIMAL)
498

499
                      + CAST(REPLACE(ISNULL(dbo.GetPEN(tr301RSim.Rate), '0'),
500

501
                                     ',', '.') AS DECIMAL) ) 'total_rate' ,
502

503
                    ( CAST(REPLACE(ISNULL(dbo.GetPEN(tr301Sim.Amount), '0'),
504

505
                                   ',', '.') AS DECIMAL)
506

507
                      + CAST(REPLACE(ISNULL(dbo.GetPEN(tr301RSim.Amount), '0'),
508

509
                                     ',', '.') AS DECIMAL) ) 'total_amount' ,
510

511
                    tr301Sim.Number ,
512

513
                    tr301Sim.Currency ,
514

515
                    tr301Sim.Flag ,
516

517
                    md001.FullName ,
518

519
					md001.ExternalID ,
520

521
                    md003.TaxStatus ,
522

523
                    taxstat.TaxStatusDescription TaxStatusDesc ,
524

525
                    md001.MaritalStatus ,
526

527
                    ms.MaritalStatusDescription MaritalDesc ,
528

529
                    md003.PayrollType AS PayIndustry ,
530

531
                    md003.PayrollArea ,
532

533
                    md003.PayrollClass ,
534

535
                    md003.PayrollGrade ,
536

537
                    md003.NPWP ,
538

539
                    grd.PayrollGradeDescription AS PayGradeDesc ,
540

541
                    md002.Job ,
542

543
                    md002.EmployeeArea ,
544

545
                    area.EmployeeAreaDescription AreaDesc ,
546

547
                    md002.Organization ,
548

549
                    org.ObjectDescription OrgDesc ,
550

551
                    md002.Position ,
552

553
                    pos.ObjectDescription PosDesc
554

555
					,@Disclaimer AS Disclaimer
556

557
            FROM    dbo.PHRPYCU0308 AS c308
558

559
                    LEFT JOIN dbo.PHRPYCU0308 AS c308P ON c308.GroupBy = c308P.ReportID
560

561
                    INNER JOIN ( SELECT * ,
562

563
                                        'N' RetroType
564

565
                                 FROM   dbo.PHRPYTR0301SIM
566

567
                               ) tr301Sim ON c308.WageType = tr301Sim.WageType
568

569
                                             AND c308.RetroType = tr301Sim.RetroType
570

571
                                             AND ( c308.PayrollType = @PayType
572

573
                                                   OR @PayType = ''
574

575
                                                 )
576

577
                    LEFT OUTER JOIN ( SELECT    * ,
578

579
                                                'R' retrotype
580

581
                                      FROM      dbo.PHRPYTR0301RETSIM
582

583
                                    ) tr301RSim ON c308.WageType = tr301RSim.WageType
584

585
                                                   AND ( c308.PayrollType = @PayType
586

587
                                                         OR @PayType = ''
588

589
                                                       )
590

591
                                                   AND tr301RSim.EmployeeID = @EmpID
592

593
                                                   --AND tr301RSim.PayPeriodMonth = @PayMonth
594

595
                                                   --AND tr301RSim.PayPeriodYear = @PayYear
596

597
                                                   AND tr301RSim.RunPeriodMonth = @PayMonth
598

599
                                                   AND tr301RSim.RunPeriodYear = @PayYear
600

601
                    INNER JOIN ( SELECT m1.*
602

603
                                 FROM   dbo.PHRPA0001 m1
604

605
                                 WHERE  ( m1.StartDate <= @Endda
606

607
                                          AND m1.EndDate >= @Endda
608

609
                                        )
610

611
                               ) md001 ON md001.EmployeeID = tr301Sim.EmployeeID
612

613
                    LEFT JOIN ( SELECT  m1.*
614

615
                                FROM    dbo.PHRPA0003 m1
616

617
                                WHERE   ( m1.StartDate <= @Endda
618

619
                                          AND m1.EndDate >= @Endda
620

621
                                        )
622

623
                              ) md003 ON md001.EmployeeID = md003.EmployeeID
624

625
                    LEFT JOIN ( SELECT  m1.*
626

627
                                FROM    dbo.PHRPA0002 m1
628

629
                                WHERE   ( m1.StartDate <= @Endda
630

631
                                          AND m1.EndDate >= @Endda
632

633
                                        )
634

635
                              ) md002 ON tr301Sim.EmployeeID = md002.EmployeeID
636

637
                    LEFT JOIN dbo.PCMEPEMPAREA area ON md002.EmployeeArea = area.EmployeeArea
638

639
                                                       AND area.StartDate <= @Endda
640

641
                                                       AND area.EndDate >= @Endda
642

643
                    LEFT JOIN ( SELECT  m1.*
644

645
                                FROM    dbo.PHROM0001 m1
646

647
                                WHERE   ObjectClass = 'O'
648

649
                                AND (StartDate <= @Endda AND EndDate >= @Endda)
650

651
				--AND (StartDate <= @Endda AND StartDate >= @Endda)
652

653
                              ) org ON md002.Organization = org.ObjectID
654

655
                    LEFT JOIN ( SELECT  m1.*
656

657
                                FROM    PHROM0001 m1
658

659
                                WHERE   ObjectClass = 'P'
660

661
                                AND (StartDate <= @Endda AND EndDate >= @Endda)
662

663
				--AND (StartDate <= @Endda AND StartDate >= @Endda)
664

665
                              ) pos ON md002.Position = pos.ObjectID
666

667
                    LEFT JOIN dbo.PHRPYPGRAD grd ON md003.PayrollGrade = grd.PayrollGrade
668

669
													AND md003.PayrollClass = grd.PayrollClass
670

671
                                                    AND grd.StartDate <= @Endda
672

673
                                                    AND grd.EndDate >= @Endda
674

675
                    LEFT JOIN dbo.PHRPAMSTAT ms ON md001.MaritalStatus = ms.MaritalStatus
676

677
                                                   AND ms.StartDate <= @Endda
678

679
                                                   AND ms.EndDate >= @Endda
680

681
                    LEFT JOIN dbo.PHRPYTAXSTAT taxstat ON md003.TaxStatus = taxstat.TaxStatus
682

683
                                                          AND taxstat.StartDate <= @Endda
684

685
                                                          AND taxstat.EndDate >= @Endda
686

687
            WHERE   tr301Sim.EmployeeID = @EmpID
688

689
                    AND tr301Sim.PayPeriodMonth = @PayMonth
690

691
                    AND tr301Sim.PayPeriodYear = @PayYear
692

693
                    AND tr301Sim.RunPeriodMonth = @PayMonth
694

695
                    AND tr301Sim.RunPeriodYear = @PayYear
696

697
                    AND CAST(REPLACE(ISNULL(dbo.GetPEN(tr301Sim.Amount), '0'),
698

699
                                     ',', '.') AS DECIMAL) <> 0
700

701
            ORDER BY c308.GroupBy ,
702

703
                    c308.WageType
704

705
        END
(2-2/5)