CREATE TABLE [dbo].[StatementDetail]
(
[SDPriKey] [int] NOT NULL IDENTITY(1, 1),
[SHPriKey] [int] NOT NULL,
[SSPriKey] [int] NULL,
[OrderControl] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Description] [varchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Amount] [money] NULL CONSTRAINT [DF_StatementDetail_Amount] DEFAULT (0),
[Split] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ANPriKey] [int] NULL,
[BranchPriKey] [int] NOT NULL,
[CRNumber] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[DateTimeCreated] [datetime] NULL,
[CreatedBy] [int] NULL,
[VoidedDate] [datetime] NULL,
[VoidedBy] [int] NULL,
[PTPriKey] [int] NULL,
[CheckConf] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[CRNote] [int] NULL,
[OrdPriKey] [int] NULL,
[Status] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[VoidedNote] [int] NULL,
[UnappliedCash] [smallint] NULL,
[UnappliedAmount] [money] NULL CONSTRAINT [DF_StatementDetail_UnappliedAmount] DEFAULT (0),
[PaymentCodePriKey] [int] NULL,
[Balance] [money] NULL CONSTRAINT [DF_StatementDetail_Balance] DEFAULT (0),
[ApplyAmount] [money] NULL CONSTRAINT [DF_StatementDetail_ApplyAmount] DEFAULT (0),
[AmountRemaining] [money] NULL CONSTRAINT [DF_StatementDetail_AmountRemaining] DEFAULT (0),
[ContestCharge] [smallint] NULL CONSTRAINT [DF_StatementDetail_ContestCharge] DEFAULT (0),
[VanLineRefund] [smallint] NULL CONSTRAINT [DF_StatementDetail_VanLineRefund] DEFAULT (0),
[CustomerNumber] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[DivisionFID] [int] NULL,
[SortBy] [varchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[PMImportDetailFID] [int] NULL,
[UnappliedBranchFID] [int] NULL,
[UnappliedDivisionFID] [int] NULL,
[CRPrinted] [bit] NOT NULL CONSTRAINT [DF_StatementDetail_CRPrinted] DEFAULT ((0)),
[IsApplyGridBuilt] [bit] NOT NULL CONSTRAINT [DF_StatementDetail_IsApplyGridBuilt] DEFAULT ((0))
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[StatementDetail] ADD CONSTRAINT [PK_StatementDetail] PRIMARY KEY CLUSTERED ([SDPriKey]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_StatementDetail_Amount] ON [dbo].[StatementDetail] ([Amount]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_StatementDetail_ANPriKey] ON [dbo].[StatementDetail] ([ANPriKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_StatementDetail_BranchPriKey] ON [dbo].[StatementDetail] ([BranchPriKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_StatementDetail_CreatedBy] ON [dbo].[StatementDetail] ([CreatedBy]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_StatementDetail_CRNote] ON [dbo].[StatementDetail] ([CRNote]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_StatementDetail_DivisionFID] ON [dbo].[StatementDetail] ([DivisionFID]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_StatementDetail_OrdPriKey] ON [dbo].[StatementDetail] ([OrdPriKey]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_StatementDetail_PaymentCodePriKey] ON [dbo].[StatementDetail] ([PaymentCodePriKey]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_StatementDetail_SHPriKey] ON [dbo].[StatementDetail] ([SHPriKey]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_StatementDetail_SSPriKey] ON [dbo].[StatementDetail] ([SSPriKey]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_StatementDetail_Status] ON [dbo].[StatementDetail] ([Status]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_StatementDetail_VoidedBy] ON [dbo].[StatementDetail] ([VoidedBy]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_StatementDetail_VoidedNote] ON [dbo].[StatementDetail] ([VoidedNote]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[StatementDetail] ADD CONSTRAINT [FK_StatementDetail_AccountingNote] FOREIGN KEY ([ANPriKey]) REFERENCES [dbo].[AccountingNote] ([ANPriKey])
GO
ALTER TABLE [dbo].[StatementDetail] ADD CONSTRAINT [FK_StatementDetail_BRANCH] FOREIGN KEY ([BranchPriKey]) REFERENCES [dbo].[Branch] ([BranchPriKey])
GO
ALTER TABLE [dbo].[StatementDetail] ADD CONSTRAINT [FK_StatementDetail_Sysuser] FOREIGN KEY ([CreatedBy]) REFERENCES [dbo].[Sysuser] ([SysUserID])
GO
ALTER TABLE [dbo].[StatementDetail] ADD CONSTRAINT [FK_StatementDetail_AccountingNote2] FOREIGN KEY ([CRNote]) REFERENCES [dbo].[AccountingNote] ([ANPriKey])
GO
ALTER TABLE [dbo].[StatementDetail] ADD CONSTRAINT [FK_StatementDetail_Division] FOREIGN KEY ([DivisionFID]) REFERENCES [dbo].[Division] ([DivisionID])
GO
ALTER TABLE [dbo].[StatementDetail] ADD CONSTRAINT [FK_StatementDetail_Orders] FOREIGN KEY ([OrdPriKey]) REFERENCES [dbo].[Orders] ([PriKey])
GO
ALTER TABLE [dbo].[StatementDetail] ADD CONSTRAINT [FK_StatementDetail_PaymentCode] FOREIGN KEY ([PaymentCodePriKey]) REFERENCES [dbo].[PaymentCode] ([PaymentCodePriKey])
GO
ALTER TABLE [dbo].[StatementDetail] ADD CONSTRAINT [FK_StatementDetail_PaymentType] FOREIGN KEY ([PTPriKey]) REFERENCES [dbo].[PaymentType] ([PTPriKey])
GO
ALTER TABLE [dbo].[StatementDetail] ADD CONSTRAINT [FK_StatementDetail_StatementHeader] FOREIGN KEY ([SHPriKey]) REFERENCES [dbo].[StatementHeader] ([SHPriKey])
GO
ALTER TABLE [dbo].[StatementDetail] ADD CONSTRAINT [FK_StatementDetail_SplitStatement] FOREIGN KEY ([SSPriKey]) REFERENCES [dbo].[SplitStatement] ([SSPriKey])
GO
ALTER TABLE [dbo].[StatementDetail] ADD CONSTRAINT [FK_StatementDetail_UnappliedBranch] FOREIGN KEY ([UnappliedBranchFID]) REFERENCES [dbo].[Branch] ([BranchPriKey])
GO
ALTER TABLE [dbo].[StatementDetail] ADD CONSTRAINT [FK_StatementDetail_UnappliedDivision] FOREIGN KEY ([UnappliedDivisionFID]) REFERENCES [dbo].[Division] ([DivisionID])
GO
ALTER TABLE [dbo].[StatementDetail] ADD CONSTRAINT [FK_StatementDetail_Sysuser1] FOREIGN KEY ([VoidedBy]) REFERENCES [dbo].[Sysuser] ([SysUserID])
GO
ALTER TABLE [dbo].[StatementDetail] ADD CONSTRAINT [FK_StatementDetail_AccountingNote1] FOREIGN KEY ([VoidedNote]) REFERENCES [dbo].[AccountingNote] ([ANPriKey])
GO
GRANT SELECT ON [dbo].[StatementDetail] TO [MssExec]
GRANT INSERT ON [dbo].[StatementDetail] TO [MssExec]
GRANT DELETE ON [dbo].[StatementDetail] TO [MssExec]
GRANT UPDATE ON [dbo].[StatementDetail] TO [MssExec]
GO