--ALTER PROCEDURE PFILOGENERATESTOCK
--(
--	@MaterialID VARCHAR(20)
--	,@UserName VARCHAR(250)
--)
--AS

--DECLARE @MaterialID VARCHAR(20) = '00000063'
--DECLARE @UserName VARCHAR(250) = 'tri'

INSERT INTO dbo.PMDMAT0004
SELECT @MaterialID AS MaterialID
	,ROW_NUMBER() OVER(ORDER BY wh.Warehouse ASC) AS SeqID
	,'1000' AS CompanyID
	,'' AS LogisticID
	,wh.Warehouse
	,'' AS Storage
	,'' AS Bin
	,'0001' AS StockStatus
	,'' AS GLValuationID
	,0 AS Qty
	,0 AS TotalValuation
	,1 AS Sequence
	,'' AS SerialNumber
	,@UserName AS CreateBy
	,dbo.fn_formatdatetime(GETDATE(),'yyyymmddhhnnss') AS CreateDate
	,@UserName AS ChangeBy
	,dbo.fn_formatdatetime(GETDATE(),'yyyymmddhhnnss') AS ChangeDate
	,'' AS SORDID
	,'' AS PRODID
	,'' AS INTRID
	,'' AS POID
	,1 AS StockType
	,'' AS DocIDRef
	,'' AS DocTypeRef
	,'' AS TransTypeRef
FROM dbo.PCMFILOWAREHOUSE AS wh


--SELECT * FROM dbo.PMDMAT0004