Project

General

Profile

Bug #2923 » SP report pindah buku.txt

Muhammad Bintar, 07/25/2024 11:55 AM

 
1
DECLARE @SPPDNumber VARCHAR(500) ='DHC.03/SPH-0322/VI-24'
2
DECLARE @CostCenter VARCHAR(8)='00000089'
3
DECLARE @NumberReport VARCHAR(500) = '758403'
4
DECLARE @ReportDate VARCHAR(8) = '20240302'
5
DECLARE @paymentDate VARCHAR(8) = '20240302'
6
DECLARE @City VARCHAR(500) = 'Tangerang'
7
DECLARE @TravelStatus VARCHAR(8) = '02'
8
DECLARE @now VARCHAR(8) 
9
SET @now = dbo.fn_formatdatetime(GETDATE(), 'yyyymmdd')
10

    
11
DECLARE @Header TABLE
12
(	
13
	 EmployeeID VARCHAR(8)
14
	 ,StartDate VARCHAR(8)
15
	 ,EndDate VARCHAR(8)
16
	,SPPDNumber VARCHAR(60)
17
	,TravelReason VARCHAR(500)
18
	,TravelStatus VARCHAR(4)
19
	,Departure VARCHAR(50)
20
	,Destination VARCHAR(50)
21
	,Notes VARCHAR(500)
22
	,RegID VARCHAR(8)
23
	,HeaderSequence int
24
)
25
INSERT INTO @Header 
26
SELECT 
27
	pa62.EmployeeID
28
	,pa62.StartDate
29
	,pa62.EndDate
30
	,pa62.SPPDNumber
31
	,pa62.TravelReason
32
	,pa62.TravelStatus
33
	,pa62.Departure
34
	,pa62.Destination
35
	,pa62.Notes
36
	,pa62.RegID
37
	,pa62.HeaderSequence
38
FROM PHRPA0062 pa62
39
WHERE pa62.SPPDNumber = @SPPDNumber and pa62.TravelStatus = @TravelStatus
40

    
41
DECLARE @RouteTrans TABLE
42
(	
43
	 EmployeeID VARCHAR(8)
44
	,TransportType VARCHAR(8)
45
	,RegID VARCHAR(8)
46
	,HeaderSequence int
47
)
48
INSERT INTO @RouteTrans 
49
SELECT TOP 1
50
	pa63.EmployeeID
51
	,pa63.TransportType
52
	,pa63.RegID
53
	,pa63.HeaderSequence
54
FROM phrpa0063 pa63
55
	LEFT JOIN @Header as header ON pa63.EmployeeID = header.EmployeeID
56
			AND pa63.HeaderSequence = header.HeaderSequence
57

    
58

    
59
DECLARE @CostSumAmount TABLE
60
(	
61
	 EmployeeID VARCHAR(8)
62
	,AmountPlan decimal(18,2)
63
	,AmountApproval decimal(18,2)
64
	,CostCenter VARCHAR(8)
65
	,HeaderSequence int
66
)
67
INSERT INTO @CostSumAmount
68
SELECT
69
	header.EmployeeID
70
	,SUM(AmountPlan) AS AmountPlan
71
	,SUM(AmountApproval) AS AmountApprov
72
	,pa65.CostCenter
73
	,pa65.HeaderSequence
74
FROM phrpa0065 pa65
75
 INNER JOIN @Header as header ON pa65.EmployeeID = header.EmployeeID
76
			AND pa65.HeaderSequence = header.HeaderSequence
77
WHERE pa65.CostCenter = @CostCenter
78
GROUP BY header.EmployeeID
79
		,pa65.CostCenter
80
		,pa65.HeaderSequence
81

    
82
DECLARE @CostSumAmountFIX TABLE
83
(	
84
	
85
	AmountPlanFIX decimal(18,2)
86
	,AmountApprovalFIX decimal(18,2)
87
	,CostCenter VARCHAR(8)
88
)
89
INSERT INTO @CostSumAmountFIX
90
SELECT
91
	SUM(AmountPlan) AS AmountPlan
92
	,SUM(AmountApproval) AS AmountApprov
93
	,CostCenter
94
FROM @CostSumAmount 
95
Group by CostCenter
96

    
97
SELECT 
98
 header.*
99
 , Rou.TransportType
100
 , tptyp.TransportTypeDescription
101
 , costSum.AmountPlan
102
 , costSum.AmountApproval
103
 , amountFix.AmountPlanFIX 
104
 , amountFix.AmountApprovalFIX
105
 ,@NumberReport as NumberReport
106
  ,dbo.fn_formatdatetime_indonesia(@ReportDate, 'DD MMMM YYYY') as ReportDate
107
  ,@City as City
108
 ,dbo.fn_formatdatetime_indonesia(@paymentDate, 'DD MMM YYYY') as payDate
109
 ,pa01.FullName
110
 --,header.StartDate
111
 --,header.EndDate
112
 ,DATEDIFF(DAY, header.StartDate, header.EndDate) + 1  as countDay
113
 ,chom1_K.NomorAkun as acountK
114
 ,chom1_K.DeskripsiAkun as descK
115
 ,Case when header.TravelStatus = '01' then chom1_D.NomorAkun
116
	when header.TravelStatus= '02' then chom1_Dtyp2.NomorAkun end as Account
117
 ,Case when header.TravelStatus = '01' then chom1_D.DeskripsiAkun
118
	when header.TravelStatus= '02' then chom1_Dtyp2.DeskripsiAkun end as DescAccount
119
,CASE WHEN header.TravelStatus = '01' then amountFix.AmountPlanFIX 
120
	when header.TravelStatus= '02' then amountFix.AmountApprovalFIX end as Amount
121
,pa3.BankAccount
122
	,pa3.BankAccountName
123
	,amountFix.CostCenter
124
	,dtlSppd.TempatDikeluarkan
125
	, dbo.fn_formatdatetime_indonesia(dtlSppd.TanggalSPPD, 'DD MMMM YYYY') as TanggalSPPD
126
	, Case when header.TravelStatus = '01' then costSum.AmountPlan
127
	when header.TravelStatus= '02' then costSum.AmountApproval end as AmountKreditDetail
128
 	 ,dbo.fn_formatdatetime_indonesia(header.StartDate, 'DD/MM/YYYY') AS StartDateFor
129
	,dbo.fn_formatdatetime_indonesia(header.EndDate, 'DD/MM/YYYY') AS EndDateFor
130
FROM @Header header
131
LEFT JOIN @RouteTrans Rou ON header.EmployeeID = Rou.EmployeeID
132
				AND header.HeaderSequence = Rou.HeaderSequence
133
LEFT JOIN @CostSumAmount costSum ON header.EmployeeID = costSum.EmployeeID
134
LEFT JOIN @CostSumAmountFIX amountFix on costSum.CostCenter = amountFix.CostCenter
135
LEFT JOIN PHRPA0001 pa01 ON header.EmployeeID = pa01.EmployeeID
136
		AND pa01.EndDate >= @now
137
LEFT JOIN PHRPA0002 pa02 ON header.EmployeeID = pa02.EmployeeID
138
		AND pa02.EndDate >= @now
139
LEFT JOIN CHROM0001 chom1_D ON amountFix.CostCenter = chom1_D.ObjectID
140
		AND chom1_D.DebitKredit = 'D'
141
		AND chom1_D.ModuleType = '1'
142
		AND chom1_D.Rencana = '1'
143
LEFT JOIN CHROM0001 chom1_Dtyp2 ON amountFix.CostCenter = chom1_Dtyp2.ObjectID
144
		AND chom1_Dtyp2.DebitKredit = 'D'
145
		AND chom1_Dtyp2.ModuleType = '1'
146
		AND chom1_Dtyp2.Rencana = '2'
147
LEFT JOIN CHROM0001 chom1_K ON amountFix.CostCenter = chom1_K.ObjectID
148
		AND chom1_K.DebitKredit = 'K'
149
		AND chom1_K.ModuleType = '1'
150
LEFT JOIN PHRPA0003 pa3 ON header.EmployeeID = pa3.EmployeeID
151
			AND pa3.StartDate <= @now
152
			AND pa3.EndDate >= @now
153
LEFT JOIN PHRTVTPTYP tptyp ON Rou.TransportType = tptyp.TransportType
154
LEFT JOIN CTRSPPDNUMBER dtlSppd ON header.SPPDNumber = dtlSppd.SPPDNumber
155
where costSum.CostCenter = @CostCenter
(4-4/6)