Project

General

Profile

Feature #2264 » CRPTLPPOMESSPAYSLIP.sql

Tri Rizqiaty, 06/20/2023 01:41 PM

 
1
??USE [MinovaES_BIA_Dev]
2

3
GO
4

5
/****** Object:  StoredProcedure [dbo].[CRPTLPPOMESSPAYSLIP]    Script Date: 20/06/2023 13.41.30 ******/
6

7
SET ANSI_NULLS ON
8

9
GO
10

11
SET QUOTED_IDENTIFIER ON
12

13
GO
14

15
ALTER PROCEDURE [dbo].[CRPTLPPOMESSPAYSLIP]
16

17
    (
18

19
      @PayPeriod VARCHAR(6) ,
20

21
      @EmpID VARCHAR(20) ,
22

23
      @Running VARCHAR(2) ,
24

25
      @PayType VARCHAR(2) 
26

27
    )
28

29
AS
30

31

32

33
    --DECLARE @PayPeriod VARCHAR(6) = '202302'
34

35
    --DECLARE @EmpID VARCHAR(8) = '11050019'
36

37
    --DECLARE @Running VARCHAR(2) = '1'
38

39
    --DECLARE @PayType VARCHAR(2) = ''
40

41
    
42

43

44

45
    DECLARE @CompanyCode AS VARCHAR(50) 
46

47
    DECLARE @CompanyName AS VARCHAR(250) 
48

49
    DECLARE @CompanyLogo AS VARBINARY(MAX)
50

51
    DECLARE @PayMonth AS NVARCHAR(2)
52

53
    DECLARE @PayYear AS NVARCHAR(4)
54

55
    DECLARE @Begda AS NVARCHAR(8)
56

57
    DECLARE @Endda AS NVARCHAR(8)
58

59

60

61
    SET @PayMonth = RIGHT(@PayPeriod, 2)
62

63
    SET @PayYear = LEFT(@PayPeriod, 4)
64

65
    SET @Begda = @PayPeriod + '01'
66

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

69
    
70

71
   
72

73

74

75
    DECLARE @PaySlipSigned AS NVARCHAR(50)
76

77

78

79
    SELECT TOP ( 1 )
80

81
            @PaySlipSigned = Value
82

83
    FROM    dbo.PHRPYCU0307
84

85
    WHERE   ( PayrollParameter = 'PAYSLIPSIGNED' )
86

87
            AND ( StartDate <= @Endda
88

89
                  AND EndDate >= @Endda
90

91
                )
92

93

94

95
    IF ( @Running = '1' )
96

97
        BEGIN
98

99
            SELECT TOP ( 1 )
100

101
                    @CompanyCode = CompanyID
102

103
            FROM    dbo.PHRPYTR0300 
104

105
             WHERE   ( EmployeeID = @EmpID )
106

107
                    AND ( PayPeriodMonth = @PayMonth )
108

109
                    AND ( PayPeriodYear = @PayYear )
110

111
                    AND ( RunPeriodMonth = @PayMonth )
112

113
                    AND ( RunPeriodYear = @PayYear )
114

115
        END
116

117
    ELSE
118

119
        BEGIN
120

121
            SELECT TOP ( 1 )
122

123
                    @CompanyCode = CompanyID
124

125
            FROM    dbo.PHRPYTR0300SIM
126

127
            WHERE   ( EmployeeID = @EmpID )
128

129
                    AND ( PayPeriodMonth = @PayMonth )
130

131
                    AND ( PayPeriodMonth = @PayYear )
132

133
                    AND ( RunPeriodMonth = @PayMonth )
134

135
                    AND ( RunPeriodYear = @PayYear )
136

137
        END
138

139

140

141
       
142

143

144

145
    SELECT  @CompanyName = COM.CompanyDescription ,
146

147
            @CompanyLogo = CAT.FileData
148

149
    FROM    dbo.PCMEPCOMPID AS COM
150

151
	LEFT JOIN dbo.SFILECATALOG CAT ON COM.Logo = CAT.FileName
152

153
    WHERE   ( CompanyID = @CompanyCode )
154

155
            AND StartDate <= @Endda
156

157
            AND EndDate >= @Endda
158

159

160

161
	DECLARE @Disclaimer VARCHAR(250)
162

163
	SELECT @Disclaimer = Value1 FROM dbo.PCMEPGENPARAM WHERE Parameter = 'DISCLAIMEREPAYSLIP'
164

165

166

167

168

169
	IF @CompanyCode = '3000'
170

171
	BEGIN 
172

173
	SELECT @Disclaimer = Value1 FROM dbo.PCMEPGENPARAM WHERE Parameter = 'DISCLAIMEREPAYSLIPIHATEC'
174

175
	END
176

177

178

179

180

181

182

183

184

185

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
					dbo.fn_formatdatetime_indonesia(c308.StartDate, 'DD MMMM YYYY') as StartDateDesc,
226

227
                    c308.EndDate ,
228

229
                    c308.IsActive ,
230

231
                    c308.ChangeBy ,
232

233
                    c308.ChangeDate ,
234

235
                    c308.CreateBy ,
236

237
                    c308.CreateDate ,
238

239
                    tr301.EmployeeID ,
240

241
                    tr301.PayPeriodMonth ,
242

243
                    tr301.PayPeriodYear ,
244

245
                    tr301.RunPeriodMonth ,
246

247
                    tr301.RunPeriodYear ,
248

249
                    tr301.SplitIndicator ,
250

251
                    /*CAST(REPLACE(ISNULL(dbo.GetPEN(tr301.Rate), '0'), ',', '.') AS DECIMAL) 'rate' ,
252

253
                    CAST(REPLACE(ISNULL(dbo.GetPEN(tr301.Amount), '0'), ',',
254

255
                                 '.') AS DECIMAL) 'amount' ,
256

257
                    CAST(REPLACE(ISNULL(dbo.GetPEN(tr301R.Rate), '0'), ',',
258

259
                                 '.') AS DECIMAL) 'rate_r' ,
260

261
                    CAST(REPLACE(ISNULL(dbo.GetPEN(tr301R.Amount), '0'), ',',
262

263
                                 '.') AS DECIMAL) 'amount_r' ,
264

265
                    ( CAST(REPLACE(ISNULL(dbo.GetPEN(tr301.Rate), '0'), ',',
266

267
                                   '.') AS DECIMAL)
268

269
                      + CAST(REPLACE(ISNULL(dbo.GetPEN(tr301R.Rate), '0'), ',',
270

271
                                     '.') AS DECIMAL) ) 'total_rate' ,
272

273
                    ( CAST(REPLACE(ISNULL(dbo.GetPEN(tr301.Amount), '0'), ',',
274

275
                                   '.') AS DECIMAL)
276

277
                      + CAST(REPLACE(ISNULL(dbo.GetPEN(tr301R.Amount), '0'),
278

279
                                     ',', '.') AS DECIMAL) ) 'total_amount' ,*/
280

281
					/*CASE 
282

283
						WHEN tr301.WageType = 'MT' THEN  CASE WHEN CAST(REPLACE(ISNULL(dbo.GetPEN(tr301.Rate), '0'), ',','.') AS DECIMAL) > 0 THEN  CAST(REPLACE(ISNULL(dbo.GetPEN(tr301.Rate), '0'), ',','.') AS DECIMAL)  ELSE 0 END
284

285
						ELSE CAST(REPLACE(ISNULL(dbo.GetPEN(tr301.Rate), '0'), ',', '.') AS DECIMAL) END AS 'rate' ,
286

287
                    CASE 
288

289
						WHEN tr301.WageType = 'MT' THEN  CASE WHEN CAST(REPLACE(ISNULL(dbo.GetPEN(tr301.Amount), '0'), ',','.') AS DECIMAL) > 0 THEN  CAST(REPLACE(ISNULL(dbo.GetPEN(tr301.Amount), '0'), ',','.') AS DECIMAL)  ELSE 0 END
290

291
						ELSE CAST(REPLACE(ISNULL(dbo.GetPEN(tr301.Amount), '0'), ',','.') AS DECIMAL) END AS 'amount' ,*/
292

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

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

297
                    CONVERT(DECIMAL(18,2),tr301.Number) AS Number,
298

299
                    tr301.Currency ,
300

301
                    tr301.Flag ,
302

303
                    md001.FullName ,
304

305
					md001.ExternalID ,
306

307
					divcode.DivisionCodeDescription,
308

309
					om1.ObjectDescription,
310

311
                    md003.TaxStatus AS MaritalDesc,
312

313
                    taxstat.TaxStatusDescription TaxStatusDesc ,
314

315
                    md001.MaritalStatus ,
316

317
                    taxstat.TaxStatusDescription TaxStatus ,
318

319
                    md003.PayrollType AS PayIndustry ,
320

321
                    md003.PayrollArea ,
322

323
                    md003.PayrollClass ,
324

325
                    md003.PayrollGrade ,
326

327
                    md003.NPWP ,
328

329
                    grd.PayrollGradeDescription AS PayGradeDesc ,
330

331
                    md002.Job ,
332

333
                    md002.EmployeeArea ,
334

335
                    area.EmployeeAreaDescription AreaDesc ,
336

337
                    md002.Organization ,
338

339
                    org.ObjectDescription OrgDesc ,
340

341
                    md002.Position ,
342

343
                    pos.ObjectDescription PosDesc
344

345
					,@Disclaimer AS Disclaimer
346

347
					,md002.EmployeeSubType
348

349
					,empstyp.EmployeeSubTypeDesc
350

351
            FROM    dbo.PHRPYCU0308 AS c308
352

353
                    LEFT JOIN dbo.PHRPYCU0308 AS c308P ON c308.GroupBy = c308P.ReportID
354

355
					INNER JOIN ( SELECT * ,
356

357
                                        'N' RetroType
358

359
                                 FROM   PHRPYTR0301
360

361
                                 UNION ALL
362

363
                                 SELECT * ,
364

365
                                        'R' RetroType
366

367
                                 FROM   PHRPYTR0301RET
368

369
                               ) tr301 ON c308.WageType = tr301.WageType
370

371
                                          AND c308.RetroType = tr301.RetroType
372

373
                                          AND ( c308.PayrollType = @PayType
374

375
                                                OR @PayType = ''
376

377
                                              )
378

379
                    /*INNER JOIN ( SELECT * ,
380

381
                                        'N' RetroType
382

383
                                 FROM   dbo.PHRPYTR0301
384

385
                               ) tr301 ON c308.WageType = tr301.WageType
386

387
                                          AND c308.RetroType = tr301.RetroType
388

389
                                          AND ( c308.PayrollType = @PayType
390

391
                                                OR @PayType = ''
392

393
                                              )
394

395
                    --INNER JOIN @TableResult AS TblOto ON TblOto.EmployeeID = tr301.EmployeeID
396

397
                    LEFT OUTER JOIN ( SELECT    * ,
398

399
                                                'R' retrotype
400

401
                                      FROM      dbo.PHRPYTR0301RET
402

403
                                    ) tr301R ON c308.WageType = tr301R.WageType
404

405
                                                AND ( c308.PayrollType = @PayType
406

407
                                                      OR @PayType = ''
408

409
                                                    )
410

411
                                                AND tr301R.EmployeeID = @EmpID
412

413
                                                AND tr301R.PayPeriodMonth = @PayMonth
414

415
                                                AND tr301R.PayPeriodYear = @PayYear
416

417
                                                AND tr301R.RunPeriodMonth = @PayMonth
418

419
                                                AND tr301R.RunPeriodYear = @PayYear */
420

421
                    INNER JOIN ( SELECT m1.*
422

423
                                 FROM   dbo.PHRPA0001 m1
424

425
                                 WHERE  ( m1.StartDate <= @Endda
426

427
                                          AND m1.EndDate >= @Endda
428

429
                                        )
430

431
                               ) md001 ON md001.EmployeeID = tr301.EmployeeID
432

433
                    LEFT JOIN ( SELECT  m1.*
434

435
                                FROM    dbo.PHRPA0003 m1
436

437
                                WHERE   ( m1.StartDate <= @Endda
438

439
                                          AND m1.EndDate >= @Endda
440

441
                                        )
442

443
                              ) md003 ON md001.EmployeeID = md003.EmployeeID
444

445
                    LEFT JOIN ( SELECT  m1.*
446

447
                                FROM    dbo.PHRPA0002 m1
448

449
                                WHERE   ( m1.StartDate <= @Endda
450

451
                                          AND m1.EndDate >= @Endda
452

453
                                        )
454

455
                              ) md002 ON tr301.EmployeeID = md002.EmployeeID
456

457
                    LEFT JOIN dbo.PCMEPEMPAREA area ON md002.EmployeeArea = area.EmployeeArea
458

459
                                                       AND area.StartDate <= @Endda
460

461
                                                       AND area.EndDate >= @Endda
462

463
                    LEFT JOIN ( SELECT  m1.*
464

465
                                FROM    dbo.PHROM0001 m1
466

467
                                WHERE   ObjectClass = 'O'
468

469
                                AND (StartDate <= @Endda AND EndDate >= @Endda)
470

471
				--AND (StartDate <= @Endda AND StartDate >= @Endda)
472

473
                              ) org ON md002.Organization = org.ObjectID
474

475
                    LEFT JOIN ( SELECT  m1.*
476

477
                                FROM    PHROM0001 m1
478

479
                                WHERE   ObjectClass = 'P'
480

481
                                AND (StartDate <= @Endda AND EndDate >= @Endda)
482

483
				--AND (StartDate <= @Endda AND StartDate >= @Endda)
484

485
                              ) pos ON md002.Position = pos.ObjectID
486

487
                    LEFT JOIN dbo.PHRPYPGRAD grd ON md003.PayrollGrade = grd.PayrollGrade
488

489
													AND md003.PayrollClass = grd.PayrollClass
490

491
                                                    AND grd.StartDate <= @Endda
492

493
                                                    AND grd.EndDate >= @Endda
494

495
                    LEFT JOIN dbo.PHRPAMSTAT ms ON md001.MaritalStatus = ms.MaritalStatus
496

497
                                                   AND ms.StartDate <= @Endda
498

499
                                                   AND ms.EndDate >= @Endda
500

501
                    LEFT JOIN dbo.PHRPYTAXSTAT taxstat ON md003.TaxStatus = taxstat.TaxStatus
502

503
                                                          AND taxstat.StartDate <= @Endda
504

505
                                                          AND taxstat.EndDate >= @Endda
506

507
					LEFT JOIN PCMEMPDVSCODE divcode ON md002.DivisionCode=divcode.DivisionCode
508

509
					LEFT JOIN PHRPA0002 mdpos ON mdpos.EmployeeID=md001.EmployeeID and mdpos.EndDate = '99991231'
510

511
					LEFT JOIN PHROM0001 om1 ON mdpos.Position=om1.ObjectID and om1.ObjectClass='P'
512

513
					LEFT JOIN PCMEPEMPSTYP AS empstyp
514

515
						ON empstyp.EmployeeSubType = md002.EmployeeSubType
516

517
            WHERE   tr301.EmployeeID = @EmpID
518

519
                    AND tr301.PayPeriodMonth = @PayMonth
520

521
                    AND tr301.PayPeriodYear = @PayYear
522

523
                    AND tr301.RunPeriodMonth = @PayMonth
524

525
                    AND tr301.RunPeriodYear = @PayYear
526

527
			  --AND hr_tr0301.amount <> 0
528

529
                    AND CAST(REPLACE(ISNULL(dbo.GetPEN(tr301.Amount), '0'),
530

531
                                     ',', '.') AS DECIMAL) <> 0
532

533
            ORDER BY c308.GroupBy ,
534

535
                    c308.WageType
536

537
        END
538

539
    ELSE
540

541
        BEGIN   
542

543
		
544

545
            SELECT  @PaySlipSigned PaySlipSigned ,
546

547
                    @CompanyName CompanyName ,
548

549
                    @CompanyLogo logo ,
550

551
                    c308.ReportID ,
552

553
                    c308.GroupBy ,
554

555
                    c308P.PayslipDescription ParentDescription ,
556

557
                    c308.Sequence ,
558

559
                    c308.PayslipDescription ,
560

561
                    c308.PayrollType ,
562

563
                    c308.WageType ,
564

565
                    c308.IsDisplayWageType ,
566

567
                    c308.IsDisplayNumber ,
568

569
                    c308.IsDisplayRate ,
570

571
                    c308.IsDisplayAmount ,
572

573
					dbo.fn_formatdatetime_indonesia(c308.StartDate, 'DD MMMM YYYY') as StartDateDesc,
574

575
                    c308.StartDate ,
576

577
                    c308.EndDate ,
578

579
                    c308.IsActive ,
580

581
                    c308.ChangeBy ,
582

583
                    c308.ChangeDate ,
584

585
                    c308.CreateBy ,
586

587
                    c308.CreateDate ,
588

589
                    tr301Sim.EmployeeID ,
590

591
                    tr301Sim.PayPeriodMonth ,
592

593
                    tr301Sim.PayPeriodYear ,
594

595
                    tr301Sim.RunPeriodMonth ,
596

597
                    tr301Sim.RunPeriodYear ,
598

599
                    tr301Sim.SplitIndicator ,
600

601
                    CAST(REPLACE(ISNULL(dbo.GetPEN(tr301Sim.Rate), '0'), ',',
602

603
                                 '.') AS DECIMAL) 'rate' ,
604

605
                    CAST(REPLACE(ISNULL(dbo.GetPEN(tr301Sim.Amount), '0'), ',',
606

607
                                 '.') AS DECIMAL) 'amount' ,
608

609
                    CAST(REPLACE(ISNULL(dbo.GetPEN(tr301RSim.Rate), '0'), ',',
610

611
                                 '.') AS DECIMAL) 'rate_r' ,
612

613
                    CAST(REPLACE(ISNULL(dbo.GetPEN(tr301RSim.Amount), '0'),
614

615
                                 ',', '.') AS DECIMAL) 'amount_r' ,
616

617
                    ( CAST(REPLACE(ISNULL(dbo.GetPEN(tr301Sim.Rate), '0'), ',',
618

619
                                   '.') AS DECIMAL)
620

621
                      + CAST(REPLACE(ISNULL(dbo.GetPEN(tr301RSim.Rate), '0'),
622

623
                                     ',', '.') AS DECIMAL) ) 'total_rate' ,
624

625
                    ( CAST(REPLACE(ISNULL(dbo.GetPEN(tr301Sim.Amount), '0'),
626

627
                                   ',', '.') AS DECIMAL)
628

629
                      + CAST(REPLACE(ISNULL(dbo.GetPEN(tr301RSim.Amount), '0'),
630

631
                                     ',', '.') AS DECIMAL) ) 'total_amount' ,
632

633
                    tr301Sim.Number ,
634

635
                    tr301Sim.Currency ,
636

637
                    tr301Sim.Flag ,
638

639
                    md001.FullName ,
640

641
					md001.ExternalID ,
642

643
					divcode.DivisionCodeDescription,
644

645
					om1.ObjectDescription,
646

647
                    md003.TaxStatus AS MaritalDesc,
648

649
                    taxstat.TaxStatusDescription TaxStatusDesc ,
650

651
                    md001.MaritalStatus ,
652

653
                    taxstat.TaxStatusDescription TaxStatus ,
654

655
                    md003.PayrollType AS PayIndustry ,
656

657
                    md003.PayrollArea ,
658

659
                    md003.PayrollClass ,
660

661
                    md003.PayrollGrade ,
662

663
                    md003.NPWP ,
664

665
                    grd.PayrollGradeDescription AS PayGradeDesc ,
666

667
                    md002.Job ,
668

669
                    md002.EmployeeArea ,
670

671
                    area.EmployeeAreaDescription AreaDesc ,
672

673
                    md002.Organization ,
674

675
                    org.ObjectDescription OrgDesc ,
676

677
                    md002.Position ,
678

679
                    pos.ObjectDescription PosDesc
680

681
					,@Disclaimer AS Disclaimer
682

683
            FROM    dbo.PHRPYCU0308 AS c308
684

685
                    LEFT JOIN dbo.PHRPYCU0308 AS c308P ON c308.GroupBy = c308P.ReportID
686

687
                    INNER JOIN ( SELECT * ,
688

689
                                        'N' RetroType
690

691
                                 FROM   dbo.PHRPYTR0301SIM
692

693
                               ) tr301Sim ON c308.WageType = tr301Sim.WageType
694

695
                                             AND c308.RetroType = tr301Sim.RetroType
696

697
                                             AND ( c308.PayrollType = @PayType
698

699
                                                   OR @PayType = ''
700

701
                                                 )
702

703
                    LEFT OUTER JOIN ( SELECT    * ,
704

705
                                                'R' retrotype
706

707
                                      FROM      dbo.PHRPYTR0301RETSIM
708

709
                                    ) tr301RSim ON c308.WageType = tr301RSim.WageType
710

711
                                                   AND ( c308.PayrollType = @PayType
712

713
                                                         OR @PayType = ''
714

715
                                                       )
716

717
                                                   AND tr301RSim.EmployeeID = @EmpID
718

719
                                                   --AND tr301RSim.PayPeriodMonth = @PayMonth
720

721
                                                   --AND tr301RSim.PayPeriodYear = @PayYear
722

723
                                                   AND tr301RSim.RunPeriodMonth = @PayMonth
724

725
                                                   AND tr301RSim.RunPeriodYear = @PayYear
726

727
                    INNER JOIN ( SELECT m1.*
728

729
                                 FROM   dbo.PHRPA0001 m1
730

731
                                 WHERE  ( m1.StartDate <= @Endda
732

733
                                          AND m1.EndDate >= @Endda
734

735
                                        )
736

737
                               ) md001 ON md001.EmployeeID = tr301Sim.EmployeeID
738

739
                    LEFT JOIN ( SELECT  m1.*
740

741
                                FROM    dbo.PHRPA0003 m1
742

743
                                WHERE   ( m1.StartDate <= @Endda
744

745
                                          AND m1.EndDate >= @Endda
746

747
                                        )
748

749
                              ) md003 ON md001.EmployeeID = md003.EmployeeID
750

751
                    LEFT JOIN ( SELECT  m1.*
752

753
                                FROM    dbo.PHRPA0002 m1
754

755
                                WHERE   ( m1.StartDate <= @Endda
756

757
                                          AND m1.EndDate >= @Endda
758

759
                                        )
760

761
                              ) md002 ON tr301Sim.EmployeeID = md002.EmployeeID
762

763
                    LEFT JOIN dbo.PCMEPEMPAREA area ON md002.EmployeeArea = area.EmployeeArea
764

765
                                                       AND area.StartDate <= @Endda
766

767
                                                       AND area.EndDate >= @Endda
768

769
                    LEFT JOIN ( SELECT  m1.*
770

771
                                FROM    dbo.PHROM0001 m1
772

773
                                WHERE   ObjectClass = 'O'
774

775
                                AND (StartDate <= @Endda AND EndDate >= @Endda)
776

777
				--AND (StartDate <= @Endda AND StartDate >= @Endda)
778

779
                              ) org ON md002.Organization = org.ObjectID
780

781
                    LEFT JOIN ( SELECT  m1.*
782

783
                                FROM    PHROM0001 m1
784

785
                                WHERE   ObjectClass = 'P'
786

787
                                AND (StartDate <= @Endda AND EndDate >= @Endda)
788

789
				--AND (StartDate <= @Endda AND StartDate >= @Endda)
790

791
                              ) pos ON md002.Position = pos.ObjectID
792

793
                    LEFT JOIN dbo.PHRPYPGRAD grd ON md003.PayrollGrade = grd.PayrollGrade
794

795
													AND md003.PayrollClass = grd.PayrollClass
796

797
                                                    AND grd.StartDate <= @Endda
798

799
                                                    AND grd.EndDate >= @Endda
800

801
                    LEFT JOIN dbo.PHRPAMSTAT ms ON md001.MaritalStatus = ms.MaritalStatus
802

803
                                                   AND ms.StartDate <= @Endda
804

805
                                                   AND ms.EndDate >= @Endda
806

807
                    LEFT JOIN dbo.PHRPYTAXSTAT taxstat ON md003.TaxStatus = taxstat.TaxStatus
808

809
                                                          AND taxstat.StartDate <= @Endda
810

811
                                                          AND taxstat.EndDate >= @Endda
812

813
					LEFT JOIN PCMEMPDVSCODE divcode ON md002.DivisionCode=divcode.DivisionCode
814

815
					LEFT JOIN PHRPA0002 mdpos ON mdpos.EmployeeID=md001.EmployeeID and mdpos.EndDate = '99991231'
816

817
					LEFT JOIN PHROM0001 om1 ON mdpos.Position=om1.ObjectID and om1.ObjectClass='P'
818

819
            WHERE   tr301Sim.EmployeeID = @EmpID
820

821
                    AND tr301Sim.PayPeriodMonth = @PayMonth
822

823
                    AND tr301Sim.PayPeriodYear = @PayYear
824

825
                    AND tr301Sim.RunPeriodMonth = @PayMonth
826

827
                    AND tr301Sim.RunPeriodYear = @PayYear
828

829
                    AND CAST(REPLACE(ISNULL(dbo.GetPEN(tr301Sim.Amount), '0'),
830

831
                                     ',', '.') AS DECIMAL) <> 0
832

833
            ORDER BY c308.GroupBy ,
834

835
                    c308.WageType
836

837
        END
(3-3/3)