Project

General

Profile

Bug #2944 » PTRFILOAUTOPOSTING_20241113.sql

Tri Rizqiaty, 11/13/2024 11:25 AM

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

3
AS
4

5

6

7
DECLARE @Now VARCHAR(20) = dbo.fn_formatdatetime(GETDATE(),'yyyymmdd')
8

9
--DECLARE @Now VARCHAR(20) = '20240119'
10

11

12

13
--DECLARE @FINHEAD TABLE (
14

15
--	[DocNo] [VARCHAR](20) NOT NULL,
16

17
--	[DocType] [VARCHAR](20) NULL,
18

19
--	[DocTypeTo] [VARCHAR](20) NULL,
20

21
--	[DocDate] [VARCHAR](20) NULL,
22

23
--	[DocStatus] [VARCHAR](20) NULL,
24

25
--	[Description] [VARCHAR](500) NULL,
26

27
--	[FiscalYear] [VARCHAR](20) NULL,
28

29
--	[FiscalPeriod] [VARCHAR](20) NULL,
30

31
--	[FiscalPeriodYear] [VARCHAR](20) NULL,
32

33
--	[CompanyID] [VARCHAR](20) NULL,
34

35
--	[IntDocRef] [VARCHAR](100) NULL,
36

37
--	[ExtDocRef] [VARCHAR](50) NULL,
38

39
--	[BusinessUnit] [VARCHAR](50) NULL,
40

41
--	[PostingDate] [VARCHAR](20) NULL,
42

43
--	[Curency] [VARCHAR](20) NULL,
44

45
--	[CreateBy] [VARCHAR](50) NULL,
46

47
--	[CreateDate] [VARCHAR](14) NULL,
48

49
--	[ChangeBy] [VARCHAR](50) NULL,
50

51
--	[ChangeDate] [VARCHAR](14) NULL,
52

53
--	[CustomerID] [VARCHAR](50) NULL,
54

55
--	[VendorID] [VARCHAR](50) NULL,
56

57
--	[TotalDebet] [DECIMAL](30, 0) NULL,
58

59
--	[TotalCredit] [DECIMAL](30, 0) NULL,
60

61
--	[InvoiceNumber] [VARCHAR](50) NULL,
62

63
--	[FakturNumber] [VARCHAR](50) NULL,
64

65
--	[VendorInvoiceNumber] [VARCHAR](50) NULL,
66

67
--	[KwitansiNumber] [VARCHAR](24) NULL,
68

69
--	[IntDocTrType] [VARCHAR](50) NULL,
70

71
--	[Regular] [VARCHAR](50) NULL,
72

73
--	[CashPlan] [VARCHAR](50) NULL,
74

75
--	[StartDate] [VARCHAR](8) NULL,
76

77
--	[EndDate] [VARCHAR](8) NULL,
78

79
--	[RegularDate] [VARCHAR](10) NULL,
80

81
--	[RefType] [VARCHAR](2) NULL,
82

83
--	[RefStatus] [VARCHAR](2) NULL,
84

85
--	[TransTypeRef] [VARCHAR](20) NULL,
86

87
--	[DocTypeRef] [VARCHAR](20) NULL,
88

89
--	[DocIDRef] [VARCHAR](20) NULL,
90

91
--	[DocItemRef] [VARCHAR](20) NULL,
92

93
--	[ProcessID] [VARCHAR](8) NULL,
94

95
--	[ExternalID] [VARCHAR](50) NULL,
96

97
--	[CostCenter] [VARCHAR](50) NULL,
98

99
--	[TotSalesRef] [DECIMAL](30, 0) NULL,
100

101
--	[TotInvoiceRef] [DECIMAL](30, 0) NULL,
102

103
--	[BalanceRef] [DECIMAL](30, 0) NULL,
104

105
--	[DueDate] [VARCHAR](8) NULL,
106

107
--	[Abbreviation] [VARCHAR](500) NULL,
108

109
--	[TotAmoPurc] [DECIMAL](18, 2) NULL,
110

111
--	[CustPONumber] [VARCHAR](50) NULL,
112

113
--	[FakturFlag] [VARCHAR](4) NULL,
114

115
--	[AutoFlag] [VARCHAR](20) NULL,
116

117
--	[StartDatePlan] [VARCHAR](20) NULL,
118

119
--	[FinishDatePlan] [VARCHAR](14) NULL,
120

121
--	[StartDateActual] [VARCHAR](30) NULL,
122

123
--	[FinishDateActual] [VARCHAR](14) NULL,
124

125
--	[FakturDate] [VARCHAR](20) NULL
126

127
--)
128

129

130

131
--INSERT INTO @FINHEAD
132

133
--SELECT DISTINCT *
134

135
--FROM PTRFINANCEHEAD AS head
136

137
--WHERE head.DocStatus = '2'
138

139
--	AND head.PostingDate = @now
140

141

142

143
INSERT INTO PTRFILOPOSTING
144

145
SELECT DISTINCT head.DocNo,
146

147
				item.DocItemID,
148

149
				head.DocType,
150

151
				head.DocDate,
152

153
				'9' AS DocStatus,
154

155
				head.FiscalYear,
156

157
				head.FiscalPeriod,
158

159
				head.CompanyID,
160

161
				head.BusinessUnit,
162

163
				head.CostCenter,
164

165
				'' AS SLType,
166

167
				'' AS SLID,
168

169
				head.PostingDate,
170

171
				item.GLAccountID,
172

173
				item.Currency,
174

175
				item.AmountDebet,
176

177
				item.AmountCredit,
178

179
				item.AmountDebetCompCurr,
180

181
				item.AmountCreditCompCurr,
182

183
				'ServicePosting' AS CreateBy,
184

185
				dbo.fn_formatdatetime(GETDATE(),'yyyymmddhhnnss') AS CreateDate,
186

187
				'ServicePosting' AS ChangeBy,
188

189
				dbo.fn_formatdatetime(GETDATE(),'yyyymmddhhnnss') AS ChangeDate,
190

191
				item.CompanyCurrency,
192

193
				item.ItemStatus
194

195
				--item.CashActivityType,
196

197
				--item.CashActivityDetail		
198

199
FROM dbo.PTRFINANCEHEAD AS head
200

201
LEFT JOIN dbo.PTRFINANCEITEM AS item
202

203
	ON head.DocNo = item.DocNo
204

205
WHERE head.PostingDate = @Now
206

207
	AND head.DocStatus = '2' --//-- 2=park
208

209

210

211
UPDATE PTRFINANCEHEAD
212

213
SET DocStatus = '9'
214

215
--SELECT * FROM PTRFINANCEHEAD
216

217
WHERE DocStatus = '2'
218

219
	AND PostingDate = @now
220

221

222

223

224

225

(2-2/2)