1
|
USE [MinovaES_Internal_2021]
|
2
|
GO
|
3
|
/****** Object: StoredProcedure [dbo].[PRPTINVDOCRECAP] Script Date: 1/19/2022 10:33:02 AM ******/
|
4
|
SET ANSI_NULLS ON
|
5
|
GO
|
6
|
SET QUOTED_IDENTIFIER ON
|
7
|
GO
|
8
|
ALTER PROCEDURE [dbo].[PRPTINVDOCRECAP]
|
9
|
(
|
10
|
--//@CompanyID VARCHAR(20)
|
11
|
--//,@BussinessUnit VARCHAR(20)
|
12
|
@DocDateStart VARCHAR(20)
|
13
|
,@DocDateEnd VARCHAR(20)
|
14
|
,@DocStatus VARCHAR(20)
|
15
|
,@Warehouse VARCHAR(20)
|
16
|
)
|
17
|
AS
|
18
|
|
19
|
----//DECLARE @CompanyID VARCHAR(20) = ''
|
20
|
----//DECLARE @BussinessUnit VARCHAR(20) = ''
|
21
|
--DECLARE @DocDateStart VARCHAR(20) = ''
|
22
|
--DECLARE @DocDateEnd VARCHAR(20) = ''
|
23
|
--DECLARE @DocStatus VARCHAR(20) = ''
|
24
|
--DECLARE @Warehouse VARCHAR(20) = ''
|
25
|
|
26
|
IF (@DocDateStart <> '') BEGIN SET @DocDateStart = @DocDateStart END ELSE BEGIN SET @DocDateStart = '19000101' END
|
27
|
IF (@DocDateEnd <> '') BEGIN SET @DocDateEnd = @DocDateEnd END ELSE BEGIN SET @DocDateEnd = '99991231' END
|
28
|
|
29
|
DECLARE @TRecap TABLE
|
30
|
(
|
31
|
[DocNo] [VARCHAR](20) NOT NULL,
|
32
|
[DocType] [VARCHAR](20) NULL,
|
33
|
[DocDate] [VARCHAR](20) NULL,
|
34
|
[DocStatus] [VARCHAR](20) NULL,
|
35
|
[SendID] [VARCHAR](20) NULL,
|
36
|
[SendType] [VARCHAR](20) NULL,
|
37
|
[SendArea] [VARCHAR](50) NULL,
|
38
|
[SendWarehouse] [VARCHAR](20) NULL,
|
39
|
[ReceiverID] [VARCHAR](20) NULL,
|
40
|
[ReceiverType] [VARCHAR](20) NULL,
|
41
|
[ReceiverPlant] [VARCHAR](20) NULL,
|
42
|
[CreateBy] [VARCHAR](18) NULL,
|
43
|
[CreateDate] [VARCHAR](14) NULL,
|
44
|
[ChangeBy] [VARCHAR](18) NULL,
|
45
|
[ChangeDate] [VARCHAR](14) NULL,
|
46
|
[ReceiverWarehouse] [VARCHAR](20) NULL,
|
47
|
[StartDate] [VARCHAR](8) NULL,
|
48
|
[EndDate] [VARCHAR](8) NULL,
|
49
|
[TransTypeRef] [VARCHAR](20) NULL,
|
50
|
[DocTypeRef] [VARCHAR](20) NULL,
|
51
|
[DocIDRef] [VARCHAR](20) NULL,
|
52
|
[DocItemRef] [VARCHAR](20) NULL,
|
53
|
[ProcessID] [VARCHAR](8) NULL,
|
54
|
[Description] [VARCHAR](500) NULL,
|
55
|
[IntDocRef] [VARCHAR](50) NULL,
|
56
|
[ExtDocRef] [VARCHAR](50) NULL,
|
57
|
[RefType] [VARCHAR](2) NULL,
|
58
|
[CompanyID] [VARCHAR](4) NULL,
|
59
|
DocTypeDesc [VARCHAR](MAX),
|
60
|
docdatedesc [VARCHAR](20),
|
61
|
docstatdesc [VARCHAR](20),
|
62
|
sendwhdesc [VARCHAR](20),
|
63
|
recievwhdesc [VARCHAR](20)
|
64
|
)
|
65
|
|
66
|
INSERT INTO @TRecap
|
67
|
SELECT DISTINCT ih.*
|
68
|
,dt.DocTypeDesc
|
69
|
,dbo.fn_formatdatetime(ih.DocDate, 'dd/mm/yyyy') AS docdatedesc
|
70
|
,ds.Description AS docstatdesc
|
71
|
,swh.Description AS sendwhdesc
|
72
|
,rwh.Description AS recievwhdesc
|
73
|
FROM dbo.PTRMATERIALHEAD AS ih
|
74
|
LEFT JOIN dbo.PCMBSDOCTYPE AS dt
|
75
|
ON ih.DocType = dt.DocType
|
76
|
LEFT JOIN dbo.PCMBSLOGDOCSTATUS AS ds
|
77
|
ON ih.DocStatus = ds.DocStatus
|
78
|
LEFT JOIN dbo.PCMFILOWAREHOUSE AS swh
|
79
|
ON ih.SendWarehouse = swh.Warehouse
|
80
|
LEFT JOIN dbo.PCMFILOWAREHOUSE AS rwh
|
81
|
ON ih.ReceiverWarehouse = rwh.Warehouse
|
82
|
WHERE (ih.DocStatus = @DocStatus OR @DocStatus = '')
|
83
|
--AND (ih.CompanyID = @CompanyID OR @CompanyID = '')
|
84
|
--AND (ih.BusinessUnit = @BussinessUnit OR @BussinessUnit = '')
|
85
|
AND (ih.DocDate BETWEEN @DocDateStart AND @DocDateEnd)
|
86
|
AND (ih.SendWarehouse = @Warehouse OR @Warehouse = '')
|
87
|
|
88
|
INSERT INTO @TRecap
|
89
|
SELECT DISTINCT ih.*
|
90
|
,dt.DocTypeDesc
|
91
|
,dbo.fn_formatdatetime(ih.DocDate, 'dd/mm/yyyy') AS docdatedesc
|
92
|
,ds.Description AS docstatdesc
|
93
|
,swh.Description AS sendwhdesc
|
94
|
,rwh.Description AS recievwhdesc
|
95
|
FROM dbo.PTRMATERIALHEAD AS ih
|
96
|
LEFT JOIN dbo.PCMBSDOCTYPE AS dt
|
97
|
ON ih.DocType = dt.DocType
|
98
|
LEFT JOIN dbo.PCMBSLOGDOCSTATUS AS ds
|
99
|
ON ih.DocStatus = ds.DocStatus
|
100
|
LEFT JOIN dbo.PCMFILOWAREHOUSE AS swh
|
101
|
ON ih.SendWarehouse = swh.Warehouse
|
102
|
LEFT JOIN dbo.PCMFILOWAREHOUSE AS rwh
|
103
|
ON ih.ReceiverWarehouse = rwh.Warehouse
|
104
|
WHERE (ih.DocStatus = @DocStatus OR @DocStatus = '')
|
105
|
--AND (ih.CompanyID = @CompanyID OR @CompanyID = '')
|
106
|
--AND (ih.BusinessUnit = @BussinessUnit OR @BussinessUnit = '')
|
107
|
AND (ih.DocDate BETWEEN @DocDateStart AND @DocDateEnd)
|
108
|
AND (ih.ReceiverWarehouse = @Warehouse OR @Warehouse = '' )
|
109
|
|
110
|
INSERT INTO @TRecap
|
111
|
SELECT DISTINCT ih.[DocNo]
|
112
|
,ih.[DocType]
|
113
|
,ih.[DocDate]
|
114
|
,ih.[DocStatus]
|
115
|
,ih.[SendID]
|
116
|
,ih.[SendType]
|
117
|
,ih.[SendArea]
|
118
|
,ih.[SendWarehouse]
|
119
|
,ih.[ReceiverID]
|
120
|
,ih.[ReceiverType]
|
121
|
,ih.[ReceiverPlant]
|
122
|
,ih.[CreateBy]
|
123
|
,ih.[CreateDate]
|
124
|
,ih.[ChangeBy]
|
125
|
,ih.[ChangeDate]
|
126
|
,ih.[ReceiverWarehouse]
|
127
|
,''
|
128
|
,''
|
129
|
,ih.[TransTypeRef]
|
130
|
,ih.[DocTypeRef]
|
131
|
,ih.[DocIDRef]
|
132
|
,ih.[DocItemRef]
|
133
|
,ih.[ProcessID]
|
134
|
,ih.[Description]
|
135
|
,ih.[IntDocRef]
|
136
|
,ih.[ExtDocRef]
|
137
|
,ih.[RefType]
|
138
|
,ih.[CompanyID]
|
139
|
,dt.DocTypeDesc
|
140
|
,dbo.fn_formatdatetime(ih.DocDate, 'dd/mm/yyyy') AS docdatedesc
|
141
|
,ds.Description AS docstatdesc
|
142
|
,swh.Description AS sendwhdesc
|
143
|
,rwh.Description AS recievwhdesc
|
144
|
FROM dbo.PTRMATERIALHEADINTERNAL AS ih
|
145
|
LEFT JOIN dbo.PCMBSDOCTYPE AS dt
|
146
|
ON ih.DocType = dt.DocType
|
147
|
LEFT JOIN dbo.PCMBSLOGDOCSTATUS AS ds
|
148
|
ON ih.DocStatus = ds.DocStatus
|
149
|
LEFT JOIN dbo.PCMFILOWAREHOUSE AS swh
|
150
|
ON ih.SendWarehouse = swh.Warehouse
|
151
|
LEFT JOIN dbo.PCMFILOWAREHOUSE AS rwh
|
152
|
ON ih.ReceiverWarehouse = rwh.Warehouse
|
153
|
WHERE (ih.DocStatus = @DocStatus OR @DocStatus = '')
|
154
|
--AND (ih.CompanyID = @CompanyID OR @CompanyID = '')
|
155
|
--AND (ih.BusinessUnit = @BussinessUnit OR @BussinessUnit = '')
|
156
|
AND (ih.DocDate BETWEEN @DocDateStart AND @DocDateEnd)
|
157
|
|
158
|
SELECT DISTINCT * FROM @TRecap
|