IF EXISTS(SELECT * FROM SYS.PROCEDURES WHERE NAME='PROC_INSERT_STK_SYNC_RECORD')
	DROP  PROCEDURE  dbo.PROC_INSERT_STK_SYNC_RECORD;
GO
	
CREATE PROCEDURE PROC_INSERT_STK_SYNC_RECORD
	@newId varchar(100)
	,@oId varchar(100)
	,@itemNo varchar(100)
	,@declaId varchar(100)
	,@syncId varchar(100)
	,@status int
AS
BEGIN

	UPDATE T_STK_INVENTORY set FBILLNO = @itemNo ,FSTATUS = @status WHERE FID = @oId

	INSERT INTO T_STK_INVENTORY_COPY (
		FID,FSTOCKORGID,FKEEPERTYPEID,FKEEPERID,FOWNERTYPEID,FOWNERID,
		FSTOCKID,FSTOCKLOCID,FAUXPROPID,FSTOCKSTATUSID,FLOT,FBOMID,FMTONO,
		FPROJECTNO,FPRODUCEDATE,FEXPIRYDATE,FBASEUNITID,FBASEQTY,FBASELOCKQTY,
		FSECQTY,FSECLOCKQTY,FSTOCKUNITID,FMATERIALID,FQTY,FLOCKQTY,FSECUNITID
		,FOBJECTTYPEID
		,FBASEAVBQTY,FAVBQTY,FSECAVBQTY,FUPDATETIME,FISEFFECTIVED,FBILLNO,FSTATUS
		,FITEMNO,FOSTKID,FDeclaId,FSyncId
	) SELECT
		@NID,FSTOCKORGID,FKEEPERTYPEID,FKEEPERID,FOWNERTYPEID,FOWNERID,
		FSTOCKID,FSTOCKLOCID,FAUXPROPID,FSTOCKSTATUSID,FLOT,FBOMID,FMTONO,
		FPROJECTNO,FPRODUCEDATE,FEXPIRYDATE,FBASEUNITID,FBASEQTY,FBASELOCKQTY,
		FSECQTY,FSECLOCKQTY,FSTOCKUNITID,FMATERIALID,FQTY,FLOCKQTY,FSECUNITID
		,'ke9dee1ad634f41fca88bb9296d86117d'
		,FBASEAVBQTY,FAVBQTY,FSECAVBQTY,FUPDATETIME,FISEFFECTIVED,FBILLNO,FSTATUS
		,@itemNo,FID,@declaId,@syncId
	FROM T_STK_INVENTORY
	WHERE FID = @oId

END