CREATE TABLE [dbo].[InvoicedDetail]
(
[IDPriKey] [int] NOT NULL IDENTITY(1, 1),
[IGPriKey] [int] NOT NULL,
[Description] [varchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Amount] [money] NULL,
[ItemCode] [int] NULL,
[Quantity] [float] NULL,
[Rate] [float] NULL,
[Discount] [float] NULL,
[GrossAmount] [money] NULL,
[SortOrder] [int] NOT NULL,
[BillingMajorFID] [int] NULL,
[BillingMinorFID] [int] NULL,
[Rollup] [bit] NOT NULL CONSTRAINT [DF_InvoicedDetail_Rollup] DEFAULT ((0)),
[Hidden] [bit] NOT NULL CONSTRAINT [DF_InvoicedDetail_Hidden] DEFAULT ((0)),
[Adhoc] [bit] NOT NULL CONSTRAINT [DF_InvoicedDetail_Adhoc] DEFAULT ((0)),
[ClaimHandlingRevenueFID] [int] NULL,
[ClaimItemDueFromFID] [int] NULL,
[Quantity2] [float] NULL,
[RateTypeFID] [int] NULL,
[CustomerInvoiceReportEDIItemFID] [int] NULL,
[PointOfServiceFID] [int] NULL,
[ExtraStopFID] [int] NULL,
[NoteText] [varchar] (1024) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[LaborRatingTypeFID] [int] NULL,
[RateSource] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[RateSourceRecord] [int] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[InvoicedDetail] ADD CONSTRAINT [PK_InvoicedDetail] PRIMARY KEY CLUSTERED ([IDPriKey]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_InvoicedDetail_BillingMajor] ON [dbo].[InvoicedDetail] ([BillingMajorFID]) INCLUDE ([IGPriKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_InvoicedDetail_BillingMinor] ON [dbo].[InvoicedDetail] ([BillingMinorFID]) INCLUDE ([IGPriKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_InvoicedDetail_ExtraStopFID] ON [dbo].[InvoicedDetail] ([ExtraStopFID]) INCLUDE ([IGPriKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_InvoicedDetail_IGPriKey] ON [dbo].[InvoicedDetail] ([IGPriKey]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[InvoicedDetail] ADD CONSTRAINT [FK_InvoicedDetail_CustomerInvoiceReportEDIItem] FOREIGN KEY ([CustomerInvoiceReportEDIItemFID]) REFERENCES [dbo].[CustomerInvoiceReportEDIItem] ([CustomerInvoiceReportEDIItemID])
GO
ALTER TABLE [dbo].[InvoicedDetail] ADD CONSTRAINT [FK_InvoicedDetail_ExtraStop] FOREIGN KEY ([ExtraStopFID]) REFERENCES [dbo].[XtraStop] ([PriKey])
GO
ALTER TABLE [dbo].[InvoicedDetail] ADD CONSTRAINT [FK_InvoicedDetail_InvoicedGroup] FOREIGN KEY ([IGPriKey]) REFERENCES [dbo].[InvoicedGroup] ([IGPriKey]) ON DELETE CASCADE ON UPDATE CASCADE
GO
ALTER TABLE [dbo].[InvoicedDetail] ADD CONSTRAINT [FK_InvoicedDetail_LaborRatingTypeFID] FOREIGN KEY ([LaborRatingTypeFID]) REFERENCES [dbo].[LaborRatingType] ([LaborRatingTypeID])
GO
ALTER TABLE [dbo].[InvoicedDetail] ADD CONSTRAINT [FK_InvoicedDetail_PointOfService] FOREIGN KEY ([PointOfServiceFID]) REFERENCES [dbo].[PointOfService] ([PointOfServiceID])
GO
ALTER TABLE [dbo].[InvoicedDetail] ADD CONSTRAINT [FK_InvoiceDetail_RateType] FOREIGN KEY ([RateTypeFID]) REFERENCES [dbo].[RateTypes] ([RTypePriKey])
GO
GRANT SELECT ON [dbo].[InvoicedDetail] TO [MssExec]
GRANT INSERT ON [dbo].[InvoicedDetail] TO [MssExec]
GRANT DELETE ON [dbo].[InvoicedDetail] TO [MssExec]
GRANT UPDATE ON [dbo].[InvoicedDetail] TO [MssExec]
GO