CREATE TABLE [dbo].[QuoteGroup]
(
[QuoteGroupID] [int] NOT NULL IDENTITY(1, 1),
[QuoteHeaderFID] [int] NOT NULL,
[ItemCodeFID] [int] NULL,
[RateTypeFID] [int] NULL,
[Description] [varchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Rate] [money] NULL,
[Quantity] [decimal] (10, 4) NULL,
[Quantity2] [decimal] (10, 4) NULL,
[Charge] [money] NULL,
[QuoteServiceProviderTypeFID] [int] NULL,
[VendorID] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[VendorQuotedCharge] [money] NULL,
[VendorActualCharge] [money] NULL,
[SortOrder] [int] NULL,
[PONumber] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[InvoiceNumber] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ServiceDate] [datetime] NULL,
[NoteText] [varchar] (1024) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[LaborRatingTypeFID] [int] NULL,
[QuoteServiceProviderBillToFID] [int] NULL,
[RateSource] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[RateSourceRecord] [int] NULL,
[CurrentRowVersion] [timestamp] NOT NULL,
[ExternalVendorID] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ExternalVendorName] [varchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[IsLocked] [bit] NOT NULL CONSTRAINT [DF_QuoteGroup_IsLocked] DEFAULT ((0))
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[QuoteGroup] ADD CONSTRAINT [CK_QuoteGroup_ServiceProvider_Agent] CHECK (([QuoteServiceProviderTypeFID] IS NULL AND [VendorID] IS NULL OR [QuoteServiceProviderTypeFID] IS NULL AND [VendorID] IS NOT NULL OR [QuoteServiceProviderTypeFID] IS NOT NULL AND [VendorID] IS NULL))
GO
ALTER TABLE [dbo].[QuoteGroup] ADD CONSTRAINT [PK_QuoteGroup] PRIMARY KEY NONCLUSTERED ([QuoteGroupID]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_QuoteGroup_QuoteHeader] ON [dbo].[QuoteGroup] ([QuoteHeaderFID], [QuoteGroupID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[QuoteGroup] ADD CONSTRAINT [FK_QuoteGroup_ItemCode] FOREIGN KEY ([ItemCodeFID]) REFERENCES [dbo].[ItemCode] ([ICPriKey])
GO
ALTER TABLE [dbo].[QuoteGroup] ADD CONSTRAINT [FK_QuoteGroup_LaborRatingTypeFID] FOREIGN KEY ([LaborRatingTypeFID]) REFERENCES [dbo].[LaborRatingType] ([LaborRatingTypeID])
GO
ALTER TABLE [dbo].[QuoteGroup] ADD CONSTRAINT [FK_QuoteGroup_QuoteHeader] FOREIGN KEY ([QuoteHeaderFID]) REFERENCES [dbo].[QuoteHeader] ([QuoteHeaderID])
GO
ALTER TABLE [dbo].[QuoteGroup] ADD CONSTRAINT [FK_QuoteGroup_QuoteServiceProviderBillToFID] FOREIGN KEY ([QuoteServiceProviderBillToFID]) REFERENCES [dbo].[QuoteServiceProviderBillTo] ([QuoteServiceProviderBillToID])
GO
ALTER TABLE [dbo].[QuoteGroup] ADD CONSTRAINT [FK_QuoteGroup_QuoteServiceProviderType] FOREIGN KEY ([QuoteServiceProviderTypeFID]) REFERENCES [dbo].[QuoteServiceProviderType] ([QuoteServiceProviderTypeID])
GO
ALTER TABLE [dbo].[QuoteGroup] ADD CONSTRAINT [FK_QuoteGroup_RateType] FOREIGN KEY ([RateTypeFID]) REFERENCES [dbo].[RateTypes] ([RTypePriKey])
GO
GRANT SELECT ON [dbo].[QuoteGroup] TO [MssExec]
GRANT INSERT ON [dbo].[QuoteGroup] TO [MssExec]
GRANT DELETE ON [dbo].[QuoteGroup] TO [MssExec]
GRANT UPDATE ON [dbo].[QuoteGroup] TO [MssExec]
GO