CREATE TABLE [dbo].[BillingMinorItem]
(
[BMinPriKey] [int] NOT NULL IDENTITY(1, 1),
[BMajPriKey] [int] NOT NULL,
[ANPriKey] [int] NULL,
[ICPriKey] [int] NOT NULL,
[InvoiceFlag] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Description] [varchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Amount] [money] NOT NULL,
[InvoiceAmount] [money] NULL,
[Percentage] [float] NULL,
[Quantity] [float] NULL,
[Rate] [float] NULL,
[AgentPercentage] [float] NULL,
[GrossAmount] [money] NULL,
[Discount] [float] NULL,
[DocDate] [datetime] NULL,
[JournalDate] [datetime] NULL,
[PostedDate] [datetime] NULL,
[PostedBy] [int] NULL,
[LSPriKey] [int] NULL,
[ABTPriKey] [int] NULL,
[ApplyToDoc] [int] NULL,
[IHPriKey] [int] NULL,
[DivisionFID] [int] NULL,
[AllocatedInvoiceAmount] [money] NULL,
[ReductionAmount] [decimal] (12, 2) NULL,
[ReducedInvoiceAmount] [decimal] (12, 2) NULL,
[Quantity2] [float] NULL,
[RateTypeFID] [int] NULL,
[RevenueRatingImportedSplitHaulFID] [int] NULL,
[BranchFID] [int] NULL,
[ARBranchFID] [int] NULL,
[ARDivisionFID] [int] NULL,
[PointOfServiceFID] [int] NULL,
[CustomerInvoiceReportEDIItemFID] [int] NULL,
[ExtraStopFID] [int] NULL,
[SalesTaxItem] [bit] NULL,
[DocumentNumber] [varchar] (21) 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].[BillingMinorItem] ADD CONSTRAINT [PK_BillingMinorItem] PRIMARY KEY NONCLUSTERED ([BMinPriKey]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_BillingMinorItem_Amount] ON [dbo].[BillingMinorItem] ([Amount]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_BillingMinorItem_ApplyToDoc] ON [dbo].[BillingMinorItem] ([ApplyToDoc]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_BillingMinorItem_BMajPriKey] ON [dbo].[BillingMinorItem] ([BMajPriKey]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_BillingMinorItem_Branch] ON [dbo].[BillingMinorItem] ([BranchFID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_BillingMinorItem_DocumentNumber_IHPriKey] ON [dbo].[BillingMinorItem] ([DocumentNumber], [IHPriKey]) INCLUDE ([BMinPriKey], [RevenueRatingImportedSplitHaulFID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_BillingMinorItem_IHPriKey] ON [dbo].[BillingMinorItem] ([IHPriKey]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_BillingMinorItem_LSPrikey] ON [dbo].[BillingMinorItem] ([LSPriKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_BillingMinorItem_PostedBy] ON [dbo].[BillingMinorItem] ([PostedBy]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[BillingMinorItem] ADD CONSTRAINT [FK_BillingMinorItem_AlternateBillTo] FOREIGN KEY ([ABTPriKey]) REFERENCES [dbo].[AlternateBillTo] ([ABTPriKey])
GO
ALTER TABLE [dbo].[BillingMinorItem] ADD CONSTRAINT [FK_BillingMinorItem_AccountingNote] FOREIGN KEY ([ANPriKey]) REFERENCES [dbo].[AccountingNote] ([ANPriKey])
GO
ALTER TABLE [dbo].[BillingMinorItem] ADD CONSTRAINT [FK_BillingMinorItem_ARBranchFID] FOREIGN KEY ([ARBranchFID]) REFERENCES [dbo].[Branch] ([BranchPriKey])
GO
ALTER TABLE [dbo].[BillingMinorItem] ADD CONSTRAINT [FK_BillingMinorItem_ARDivision] FOREIGN KEY ([ARDivisionFID]) REFERENCES [dbo].[Division] ([DivisionID])
GO
ALTER TABLE [dbo].[BillingMinorItem] ADD CONSTRAINT [FK_BillingMinorItem_BillingMajorItem] FOREIGN KEY ([BMajPriKey]) REFERENCES [dbo].[BillingMajorItem] ([BMajPriKey])
GO
ALTER TABLE [dbo].[BillingMinorItem] ADD CONSTRAINT [FK_BillingMinorItem_BranchFID] FOREIGN KEY ([BranchFID]) REFERENCES [dbo].[Branch] ([BranchPriKey])
GO
ALTER TABLE [dbo].[BillingMinorItem] ADD CONSTRAINT [FK_BillingMinorItem_CustomerInvoiceReportEDIItem] FOREIGN KEY ([CustomerInvoiceReportEDIItemFID]) REFERENCES [dbo].[CustomerInvoiceReportEDIItem] ([CustomerInvoiceReportEDIItemID])
GO
ALTER TABLE [dbo].[BillingMinorItem] ADD CONSTRAINT [FK_BillingMinorItem_Division] FOREIGN KEY ([DivisionFID]) REFERENCES [dbo].[Division] ([DivisionID])
GO
ALTER TABLE [dbo].[BillingMinorItem] ADD CONSTRAINT [FK_BillingMinorItem_ExtraStop] FOREIGN KEY ([ExtraStopFID]) REFERENCES [dbo].[XtraStop] ([PriKey])
GO
ALTER TABLE [dbo].[BillingMinorItem] ADD CONSTRAINT [FK_BillingMinorItem_ItemCode] FOREIGN KEY ([ICPriKey]) REFERENCES [dbo].[ItemCode] ([ICPriKey])
GO
ALTER TABLE [dbo].[BillingMinorItem] ADD CONSTRAINT [FK_BillingMinorItem_LaborRatingTypeFID] FOREIGN KEY ([LaborRatingTypeFID]) REFERENCES [dbo].[LaborRatingType] ([LaborRatingTypeID])
GO
ALTER TABLE [dbo].[BillingMinorItem] ADD CONSTRAINT [FK_BillingMinorItem_LocServ] FOREIGN KEY ([LSPriKey]) REFERENCES [dbo].[LocServ] ([PriKey])
GO
ALTER TABLE [dbo].[BillingMinorItem] ADD CONSTRAINT [FK_BillingMinorItem_PointOfService] FOREIGN KEY ([PointOfServiceFID]) REFERENCES [dbo].[PointOfService] ([PointOfServiceID])
GO
ALTER TABLE [dbo].[BillingMinorItem] ADD CONSTRAINT [FK_BillingMinorItem_Sysuser] FOREIGN KEY ([PostedBy]) REFERENCES [dbo].[Sysuser] ([SysUserID])
GO
ALTER TABLE [dbo].[BillingMinorItem] ADD CONSTRAINT [FK_BillingMinorItem_RateType] FOREIGN KEY ([RateTypeFID]) REFERENCES [dbo].[RateTypes] ([RTypePriKey])
GO
GRANT SELECT ON [dbo].[BillingMinorItem] TO [MssExec]
GRANT INSERT ON [dbo].[BillingMinorItem] TO [MssExec]
GRANT DELETE ON [dbo].[BillingMinorItem] TO [MssExec]
GRANT UPDATE ON [dbo].[BillingMinorItem] TO [MssExec]
GO
EXEC sp_addextendedproperty N'MS_Description', N'Refers to the original BillingMinorItem transaction', 'SCHEMA', N'dbo', 'TABLE', N'BillingMinorItem', 'COLUMN', N'ApplyToDoc'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Invoice Header Primary Key. A non-null value indicates that an invoice exists for this item.', 'SCHEMA', N'dbo', 'TABLE', N'BillingMinorItem', 'COLUMN', N'IHPriKey'
GO