USE [MinovaES_DEMO_GolfCourse]
GO
/****** Object:  StoredProcedure [dbo].[ERPRPTSALESDOCDETAIL1]    Script Date: 20/10/2025 14.32.31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[ERPRPTSALESDOCDETAIL1]

 @DocNo varchar (8),
 @DocDate varchar (10),
 @DocType varchar (8),
 @DocStatus varchar (10)

 AS

--declare @DocNo varchar (8) =''
--declare @DocDate varchar (10) =''
--declare @DocType varchar (8) =''
--declare @DocStatus varchar (10) ='10'


select distinct header.CompanyID
,compid.CompanyDescription
,header.DocNo
,header.DocDate
,header.DocStatus
,case
	when header.DocDate =null then '' 
	when header.DocDate ='' then '' 
		else dbo.fn_formatdatetime_indonesia(header.DocDate, 'DD MMMM YYYY') end as DocDateDesc
,header.CustomerID
,header.DocType
,doctype.DocTypeDesc as DocTypeDesc
,'' AS CustomerIDDesc--customer.[Description] as CustomerIDDesc
,header.ExtDocRef
,header.[Description]
from PTRSALESHEADER header
left join PCMEPCOMPID compid
	on header.CompanyID = compid.CompanyID
full outer join PTRSALESPAYTERM term 
	ON header.DocNo = term.DocNo
left join PCMBSDOCTYPE doctype 
	on header.DocType = doctype.DocType
left join PMDCUS0001 customer 
	on header.CustomerID = customer.CustomerID
where 
	(header.DocNo = @DocNo or @DocNo='') 
	and
	(header.DocDate =@DocDate or @DocDate='')
	 and
	 (header.DocType = @DocType or @DocType ='')
	 and
	  (header.DocStatus = @DocStatus or @DocStatus='')
