CREATE TABLE [dbo].[Claim]
(
[ClaimID] [int] NOT NULL IDENTITY(1, 1),
[OrdersFID] [int] NOT NULL,
[ClaimTypeFID] [int] NOT NULL,
[ClaimStatusFID] [int] NOT NULL,
[ClaimNumber] [varchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[MultiLossAlertNumber] [varchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[CreatedDate] [datetime] NOT NULL CONSTRAINT [DF_Claim_CreatedDate] DEFAULT (getdate()),
[CreatedBySysUserFID] [int] NOT NULL,
[ClosedDate] [datetime] NULL,
[ForwardTo] [varchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ForwardDate] [datetime] NULL,
[TotalAmount] [money] NOT NULL CONSTRAINT [DF_Claim_TotalAmount] DEFAULT ((0)),
[AdjusterSysUserFID] [int] NULL,
[ClaimInsuranceProviderFID] [int] NULL,
[InsuranceDeductible] [money] NOT NULL CONSTRAINT [DF_Claim_InsuranceDeductible] DEFAULT ((0)),
[NoFault] [bit] NOT NULL CONSTRAINT [DF_Claim_NoFault] DEFAULT ((0)),
[ProfilesFID] [int] NULL,
[RollOutsFID] [int] NULL,
[BranchFID] [int] NOT NULL,
[DivisionFID] [int] NULL,
[ClaimFormSentDate] [datetime] NULL,
[ActualClaimReceivedDate] [datetime] NULL,
[ActualClosedToCustomerDate] [datetime] NULL
) ON [PRIMARY]
GO
CREATE trigger [dbo].[ClaimTaskFieldChanged] on [dbo].[Claim]
after update
as
set nocount on
if( update( CreatedDate ) or update( ClosedDate ) or update( ClaimFormSentDate ) or update( ActualClaimReceivedDate ) or update( ActualClosedToCustomerDate ) )
begin
update ToDo set ToDo.DueDate =
case DependencyDate.FieldName
when 'CreatedDate' then dbo.udfTaskDueDate( ToDo.DueType, ToDo.DueDays, inserted.CreatedDate )
when 'ClosedDate' then dbo.udfTaskDueDate( ToDo.DueType, ToDo.DueDays, inserted.ClosedDate )
when 'ClaimFormSentDate' then dbo.udfTaskDueDate( ToDo.DueType, ToDo.DueDays, inserted.ClaimFormSentDate )
when 'ActualClaimReceivedDate' then dbo.udfTaskDueDate( ToDo.DueType, ToDo.DueDays, inserted.ActualClaimReceivedDate )
when 'ActualClosedToCustomerDate' then dbo.udfTaskDueDate( ToDo.DueType, ToDo.DueDays, inserted.ActualClosedToCustomerDate )
else ToDo.DueDate
end
from ToDo
inner join inserted on inserted.OrdersFID = ToDo.OrderID and inserted.ClaimNumber = ToDo.Identifier
inner join DependencyDate on ToDo.DependencyDateID = DependencyDate.DependencyDateID
where DependencyDate.TableName = 'Claim'
end
if( update( AdjusterSysUserFID ) )
begin
update ToDo set TaskUserFID =
case CoordinatorType.FieldName
when 'AdjusterSysUserFID' then inserted.AdjusterSysUserFID
end
from ToDo
inner join inserted on inserted.OrdersFID = ToDo.OrderID and inserted.ClaimNumber = ToDo.Identifier
inner join CoordinatorType on ToDo.CoordinatorTypeFID = CoordinatorType.CoordinatorTypeID
where CoordinatorType.TableName = 'Claim'
end
GO
ALTER TABLE [dbo].[Claim] ADD CONSTRAINT [PK_Claim] PRIMARY KEY NONCLUSTERED ([ClaimID]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_Claim_AdjusterSysUserFID] ON [dbo].[Claim] ([AdjusterSysUserFID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_Claim_CreatedBySysUserFID] ON [dbo].[Claim] ([CreatedBySysUserFID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_Claim_OrderID_ClaimNumber] ON [dbo].[Claim] ([OrdersFID], [ClaimNumber]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Claim] ADD CONSTRAINT [FK_Claim_AdjusterSysUser] FOREIGN KEY ([AdjusterSysUserFID]) REFERENCES [dbo].[Sysuser] ([SysUserID])
GO
ALTER TABLE [dbo].[Claim] ADD CONSTRAINT [FK_Claim_Branch] FOREIGN KEY ([BranchFID]) REFERENCES [dbo].[Branch] ([BranchPriKey])
GO
ALTER TABLE [dbo].[Claim] ADD CONSTRAINT [FK_Claim_ClaimInsuranceProvider] FOREIGN KEY ([ClaimInsuranceProviderFID]) REFERENCES [dbo].[ClaimInsuranceProvider] ([ClaimInsuranceProviderID])
GO
ALTER TABLE [dbo].[Claim] ADD CONSTRAINT [FK_Claim_ClaimStatus] FOREIGN KEY ([ClaimStatusFID]) REFERENCES [dbo].[ClaimStatus] ([ClaimStatusID])
GO
ALTER TABLE [dbo].[Claim] ADD CONSTRAINT [FK_Claim_ClaimType] FOREIGN KEY ([ClaimTypeFID]) REFERENCES [dbo].[ClaimType] ([ClaimTypeID])
GO
ALTER TABLE [dbo].[Claim] ADD CONSTRAINT [FK_Claim_CreatedBySysUser] FOREIGN KEY ([CreatedBySysUserFID]) REFERENCES [dbo].[Sysuser] ([SysUserID])
GO
ALTER TABLE [dbo].[Claim] ADD CONSTRAINT [FK_Claim_Division] FOREIGN KEY ([DivisionFID]) REFERENCES [dbo].[Division] ([DivisionID])
GO
ALTER TABLE [dbo].[Claim] ADD CONSTRAINT [FK_Claim_Orders] FOREIGN KEY ([OrdersFID]) REFERENCES [dbo].[Orders] ([PriKey])
GO
ALTER TABLE [dbo].[Claim] ADD CONSTRAINT [FK_Claim_Profiles] FOREIGN KEY ([ProfilesFID]) REFERENCES [dbo].[Profiles] ([ProfileID])
GO
ALTER TABLE [dbo].[Claim] ADD CONSTRAINT [FK_Claim_RollOuts] FOREIGN KEY ([RollOutsFID]) REFERENCES [dbo].[RollOuts] ([RollOutID])
GO
GRANT SELECT ON [dbo].[Claim] TO [MssExec]
GRANT INSERT ON [dbo].[Claim] TO [MssExec]
GRANT DELETE ON [dbo].[Claim] TO [MssExec]
GRANT UPDATE ON [dbo].[Claim] TO [MssExec]
GO