CREATE TABLE [dbo].[Act2SigniDin](
	[ID] [uniqueidentifier] NOT NULL,
	[RequestID] [uniqueidentifier] NOT NULL,
	[Name] [nvarchar](1024) NULL,
	[DateOfBirth] [datetime] NULL,
	[Gender] [nvarchar](25) NULL,
	[Address] [nvarchar](1024) NULL,
	[Email] [nvarchar](1024) NULL,
	[Phone] [nvarchar](1024) NULL,
	[Bin] [nvarchar](2048) NULL,
	[Syscreated] [datetime] NOT NULL,
	CONSTRAINT [PK_Act2SigniDin] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
go

ALTER TABLE [dbo].[Act2SigniDin] ADD  DEFAULT (newsequentialid()) FOR [ID]
go

ALTER TABLE [dbo].[Act2SigniDin] ADD  DEFAULT (getdate()) FOR [Syscreated]
go

ALTER TABLE [dbo].[Act2SigniDin]  WITH CHECK ADD FOREIGN KEY([RequestID])
REFERENCES [dbo].[Absences] ([ID])
ON UPDATE CASCADE
ON DELETE CASCADE
go


declare @reqtype int
select @reqtype = LongValue from BacoSettings where SettingType = 0 and SettingGroup = 'general' and SettingName = 'CSEasyAct2SignReqTypeSigner'

if @reqtype is null
	select @reqtype = StringValue from BacoSettings where SettingType = 0 and SettingGroup = 'general' and SettingName = 'CSEasyAct2SignReqTypeSigner' and StringValue is not null and ISNUMERIC(StringValue) = 1

if @reqtype is not null
begin
	update RequestFieldOptions 
	set SelectionValues = '0,Link in e-mail;1,SMS One-Time Password;2,iDin;3,iDin Complete'
	where 
		RequestType = @reqtype 
		and FieldID = 68
end
go


if not exists(select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'Act2SignLog' and COLUMN_NAME = 'iDinCompleteCount')
begin
	alter table [dbo].[Act2SignLog]
		add [iDinCompleteCount] [int] NOT NULL DEFAULT(0)
end
go
