Project

General

Profile

Bug #4164 » GETFILODOCREFPROD.sql

Tri Rizqiaty, 02/09/2026 04:31 PM

 
1
??CREATE FUNCTION [dbo].[GETFILODOCREFPROD] () ------//------ tanpa validasi docstatus
2

3
RETURNS TABLE
4

5
AS
6

7
RETURN
8

9
(
10

11
 
12

13
 SELECT DISTINCT * FROM (SELECT  ref.TransType ,ref.DocType , ref.TransTypeRef ,ref.DocTypeRef ,ref.DocStatusRef ,docdata.DocNo ,docdata.DocDate , docdata.CompanyID, docdata.BusinessUnit, docdata.Description, docdata.DocItemID, docdata.ExternalID, docdata.DocStatus, docdata.CustomerID, docdata.VendorID  FROM PCMBSDOCREF ref 
14

15
 
16

17
 INNER JOIN ( SELECT 'FIN' AS TransType ,DocType ,finhead.DocNo ,DocDate ,finhead.CompanyID, finhead.BusinessUnit, '' AS Description , '' AS DocItemID, ExternalID, finhead.DocStatus, finhead.CustomerID, finhead.VendorID FROM PTRFINANCEHEAD finhead 
18

19
 
20

21
 INNER JOIN dbo.PTRFINANCEITEM finitem 
22

23
 
24

25
 ON finitem.DocNo = finhead.DocNo  WHERE finhead.DocNo IN (SELECT DISTINCT DocNo FROM PTRFINANCEITEM 
26

27
 
28

29
 WHERE (ItemStatus = '0' OR ItemStatus = '1'))  UNION ALL  SELECT 'SLS' AS TransType , DocType , slsHead.DocNo , DocDate ,CompanyID, BusinessUnit, '' AS Description , '' AS DocItemID, '' AS ExternalID, slsHead.DocStatus, slsHead.CustomerID, '' AS VendorID FROM PTRSALESHEADER slsHead 
30

31
 
32

33
 UNION ALL  SELECT 'PUR' AS TransType , DocType , purHead.DocNo , DocDate ,CompanyID, BusinessUnit, '' AS Description , '' AS DocItemID, '' AS ExternalID, purHead.DocStatus, '' AS CustomerID, purHead.VendorID AS VendorID FROM PTRPURCHHEAD purHead 
34

35
 
36

37
 UNION ALL  SELECT 'PRD' AS TransType ,DocType ,DocNo ,DocDate ,CompanyID, '0' AS BusinessUnit, '' AS Description , '' AS DocItemID, '' AS ExternalID, DocStatus, '' AS CustomerID, '' AS VendorID FROM PTRPRODUCTIONHEAD --WHERE DocStatus IN ('2','4')
38

39
 
40

41
 UNION ALL  SELECT 'DLVR' AS TransType ,DocType ,DocNo ,DocDate ,'0' AS CompanyID , '0' AS BusinessUnit, '' AS Description , '' AS DocItemID, '' AS ExternalID, DocStatus, '' AS CustomerID, '' AS VendorID FROM PTRDELIVERYHEAD 
42

43
 
44

45
 UNION ALL  SELECT DISTINCT 'MTR' AS TransType ,DocType ,mtrHead.DocNo ,DocDate ,ReceiverID AS CompanyID , '0' AS BusinessUnit, '' AS Description , '' AS DocItemID, '' AS ExternalID, mtrHead.DocStatus, '' AS CustomerID, '' AS VendorID FROM PTRMATERIALHEAD mtrHead 
46

47
 
48

49
 INNER JOIN dbo.PTRMATERIALITEM mtrItem 
50

51
 
52

53
 ON mtrHead.DocNo = mtrItem.DocNo ) AS docdata ON ref.TransTypeRef = docdata.TransType AND ref.DocTypeRef = docdata.DocType ) AS tbl 
54

55
 )
(6-6/8)