

/****** Object:  StoredProcedure [dbo].[API_CustomerPersonAfter]    Script Date: 2021-09-08 10:16:12 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[API_CustomerPersonAfter]
@SyncDbId int,
 @OrgId int,
 @NewId int,
 @Sch_Id int
AS
BEGIN
	SET NOCOUNT ON;

	/*
declare @SyncDbId int;
declare @OrgId int;
declare @NewId int;
declare @Sch_Id int;
*/


update dbo.ApiCustomerPersons set ErpId = @NewId where Id = @OrgId and ErpId =0;

-- pobieramy HistId
declare @HistId int;
set @HistId   = (select Max(Id) from dbo.ChangeInfos where SourceTable = 'KontaktyOsoby');

INSERT INTO [dbo].[ApiSyncItems]
           ([SyncId],[ObjectSaveTS],[SchemaId],[ObjectType],[ObjectId],[Message],[Status],[TS], HistId)
     VALUES
           (@SyncDbId,[dbo].[ApiGetSec](CURRENT_TIMESTAMP),@Sch_Id,31, @OrgId,'',2,CURRENT_TIMESTAMP,@HistId);
           
END


GO


