Project

General

Profile

Feature #3869 » PRPTPUDOCRECAP_20251021.sql

Tri Rizqiaty, 10/21/2025 04:28 PM

 
1
??USE [MinovaES_Tulisan_Dev]
2

3
GO
4

5
/****** Object:  StoredProcedure [dbo].[PRPTPUDOCRECAP]    Script Date: 21/10/2025 09.23.31 ******/
6

7
SET ANSI_NULLS ON
8

9
GO
10

11
SET QUOTED_IDENTIFIER ON
12

13
GO
14

15

16

17

18

19

20

21
ALTER PROCEDURE [dbo].[PRPTPUDOCRECAP]
22

23
(
24

25
	@CompanyID VARCHAR(20)
26

27
	,@BussinessUnit VARCHAR(20)
28

29
	,@DocDateStart VARCHAR(20)
30

31
	,@DocDateEnd VARCHAR(20)
32

33
	,@DocStatus VARCHAR(20)
34

35
	,@DocType VARCHAR (20)
36

37
)
38

39
AS
40

41

42

43
--DECLARE @CompanyID VARCHAR(20) = '1000'
44

45
--DECLARE @BussinessUnit VARCHAR(20) = ''
46

47
--DECLARE @DocDateStart VARCHAR(20) = ''
48

49
--DECLARE @DocDateEnd VARCHAR(20) = ''
50

51
--DECLARE @DocStatus VARCHAR(20) = ''
52

53
--DECLARE @DocType VARCHAR(20) = ''
54

55

56

57
IF (@DocDateStart <> '') BEGIN SET @DocDateStart = @DocDateStart END ELSE BEGIN SET @DocDateStart = '19000101' END
58

59
IF (@DocDateEnd <> '') BEGIN SET @DocDateEnd = @DocDateEnd END ELSE BEGIN SET @DocDateEnd = '99991231' END
60

61

62

63

64

65
DECLARE @nowyear VARCHAR (4) = dbo.fn_formatdatetime(GETDATE(), 'yyyy')
66

67

68

69
SELECT distinct head.DocNo, SUM(ISNULL(item.NetAmount,0)) as NetAmount 
70

71
into #NetAmount
72

73
FROM PTRPURCHHEAD  head
74

75
left join PTRPURCHITEM item on head.DocNo=item.DocNo
76

77
where ( head.DocType= @DocType OR @DocType = '')
78

79
	and (head.DocStatus=@DocStatus OR @DocStatus ='')
80

81
	--and left(head.DocDate,4)=@nowyear 
82

83
	and head.DocDate BETWEEN @DocDateStart and @DocDateEnd
84

85
group by head.DocNo
86

87

88

89
SELECT DISTINCT comp.CompanyDescription
90

91
				,'PURCHASE RECAP' as Title
92

93
				,sh.* 
94

95
				,dt.DocTypeDesc
96

97
				,bus.Description AS budesc
98

99
				,wh.Description AS whdesc
100

101
				,dbo.fn_formatdatetime(sh.DocDate, 'dd/mm/yyyy') AS docdatedesc
102

103
				,ds.Description AS docstatdesc
104

105
				,ven.Description AS vendordesc
106

107
				,dbo.fn_formatdatetime(sh.InvoiceDate, 'dd/mm/yyyy') AS invoicedatedesc
108

109
				,COALESCE(NetAmount.NetAmount,0)  as NetAmount
110

111
FROM dbo.PTRPURCHHEAD AS sh
112

113
LEFT JOIN #NetAmount NetAmount on sh.DocNo=NetAmount.DocNo
114

115
LEFT JOIN dbo.PCMBSDOCTYPE AS dt
116

117
	ON sh.DocType = dt.DocType
118

119
LEFT JOIN dbo.PCMEPCOMPID AS comp
120

121
	ON comp.CompanyID = sh.CompanyID
122

123
LEFT JOIN dbo.PCMFILOBUSUNIT AS bus	
124

125
	ON bus.BuCode = sh.BusinessUnit
126

127
LEFT JOIN dbo.PCMFILOWAREHOUSE AS wh
128

129
	ON sh.Warehouse = wh.Warehouse
130

131
LEFT JOIN dbo.PCMBSPURCHASEDOCSTATUS AS ds
132

133
	ON sh.DocStatus = ds.DocStatus
134

135
LEFT JOIN dbo.PMDVEN0001 AS ven
136

137
	ON ven.VendorID = sh.VendorID
138

139
WHERE (sh.CompanyID = @CompanyID OR @CompanyID = '')
140

141
	AND (sh.BusinessUnit = @BussinessUnit OR @BussinessUnit = '')
142

143
	AND (sh.DocStatus = @DocStatus OR @DocStatus = '')
144

145
	AND (sh.DocDate BETWEEN @DocDateStart AND @DocDateEnd)
146

147
	AND (sh.DocType= @DocType or @DocType='')
148

149
	----select * from PCMBSPURCHASEDOCSTATUS
150

151

152

153
	drop table #NetAmount
(5-5/5)