CREATE TABLE [dbo].[StorageItems]
(
[StorageItemsPriKey] [int] NOT NULL IDENTITY(1, 1),
[StoragePriKey] [int] NOT NULL,
[StorageItemTypePriKey] [int] NOT NULL,
[Description] [varchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Quantity] [decimal] (10, 4) NULL,
[Rate] [float] NULL,
[IsManualRate] [bit] NOT NULL,
[Amount] [money] NOT NULL,
[IsManualAmount] [bit] NOT NULL,
[Discount] [decimal] (10, 4) NULL,
[IsRecurring] [bit] NOT NULL,
[RecurringEndDate] [datetime] NULL,
[ANPriKey] [int] NULL,
[Location] [varchar] (512) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[WarehousePriKey] [int] NOT NULL,
[IsFinishedBilling] [bit] NOT NULL,
[IsBilled] [bit] NOT NULL CONSTRAINT [DF_StorageItems_IsBilled] DEFAULT (0),
[BeginBillingDate] [datetime] NULL,
[DivisionFID] [int] NULL,
[Quantity2] [decimal] (10, 4) NULL,
[RateTypeFID] [int] NULL,
[EffectiveDate] [datetime] NULL,
[ARBranchFID] [int] NULL,
[ARDivisionFID] [int] NULL,
[LaborRatingTypeFID] [int] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[StorageItems] ADD CONSTRAINT [PK_StorageItems] PRIMARY KEY NONCLUSTERED ([StorageItemsPriKey]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_StorageItems_StoragePriKey] ON [dbo].[StorageItems] ([StoragePriKey]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
ALTER TABLE [dbo].[StorageItems] ADD CONSTRAINT [FK_StorageItems_AccountingNote] FOREIGN KEY ([ANPriKey]) REFERENCES [dbo].[AccountingNote] ([ANPriKey])
GO
ALTER TABLE [dbo].[StorageItems] ADD CONSTRAINT [FK_StorageItems_ARBranch] FOREIGN KEY ([ARBranchFID]) REFERENCES [dbo].[Branch] ([BranchPriKey])
GO
ALTER TABLE [dbo].[StorageItems] ADD CONSTRAINT [FK_StorageItems_ARDivision] FOREIGN KEY ([ARDivisionFID]) REFERENCES [dbo].[Division] ([DivisionID])
GO
ALTER TABLE [dbo].[StorageItems] ADD CONSTRAINT [FK_StorageItems_Division] FOREIGN KEY ([DivisionFID]) REFERENCES [dbo].[Division] ([DivisionID])
GO
ALTER TABLE [dbo].[StorageItems] ADD CONSTRAINT [FK_StorageItems_LaborRatingTypeFID] FOREIGN KEY ([LaborRatingTypeFID]) REFERENCES [dbo].[LaborRatingType] ([LaborRatingTypeID])
GO
ALTER TABLE [dbo].[StorageItems] ADD CONSTRAINT [FK_StorageItems_RateType] FOREIGN KEY ([RateTypeFID]) REFERENCES [dbo].[RateTypes] ([RTypePriKey])
GO
ALTER TABLE [dbo].[StorageItems] ADD CONSTRAINT [FK_StorageItems_StorageItemType] FOREIGN KEY ([StorageItemTypePriKey]) REFERENCES [dbo].[StorageItemType] ([StorageItemTypePriKey])
GO
ALTER TABLE [dbo].[StorageItems] ADD CONSTRAINT [FK_StorageItems_Storage] FOREIGN KEY ([StoragePriKey]) REFERENCES [dbo].[Storage] ([StoragePriKey]) ON DELETE CASCADE ON UPDATE CASCADE
GO
ALTER TABLE [dbo].[StorageItems] ADD CONSTRAINT [FK_StorageItems_Warehouse] FOREIGN KEY ([WarehousePriKey]) REFERENCES [dbo].[Warehouse] ([WarehousePriKey])
GO
GRANT SELECT ON [dbo].[StorageItems] TO [MssExec]
GRANT INSERT ON [dbo].[StorageItems] TO [MssExec]
GRANT DELETE ON [dbo].[StorageItems] TO [MssExec]
GRANT UPDATE ON [dbo].[StorageItems] TO [MssExec]
GO
EXEC sp_addextendedproperty N'MS_Description', N'Amount for the item.', 'SCHEMA', N'dbo', 'TABLE', N'StorageItems', 'COLUMN', N'Amount'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Foreign key to an accounting note.', 'SCHEMA', N'dbo', 'TABLE', N'StorageItems', 'COLUMN', N'ANPriKey'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Foreign key to the AR branch for the item.', 'SCHEMA', N'dbo', 'TABLE', N'StorageItems', 'COLUMN', N'ARBranchFID'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Foreign key to the division for the item.', 'SCHEMA', N'dbo', 'TABLE', N'StorageItems', 'COLUMN', N'ARDivisionFID'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Description of the storage item type.', 'SCHEMA', N'dbo', 'TABLE', N'StorageItems', 'COLUMN', N'Description'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Discount used with system calculated amount only.', 'SCHEMA', N'dbo', 'TABLE', N'StorageItems', 'COLUMN', N'Discount'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Indicates if the item has been billed or not.', 'SCHEMA', N'dbo', 'TABLE', N'StorageItems', 'COLUMN', N'IsBilled'
GO
EXEC sp_addextendedproperty N'MS_Description', N'0 if the item should be billed. 1 if the item should no longer be billed.', 'SCHEMA', N'dbo', 'TABLE', N'StorageItems', 'COLUMN', N'IsFinishedBilling'
GO
EXEC sp_addextendedproperty N'MS_Description', N'0 if the Amount is system calculated. 1 if the amount is manually calculated.', 'SCHEMA', N'dbo', 'TABLE', N'StorageItems', 'COLUMN', N'IsManualAmount'
GO
EXEC sp_addextendedproperty N'MS_Description', N'0 if the rate is system calculated. 1 if the rate is manually calculated.', 'SCHEMA', N'dbo', 'TABLE', N'StorageItems', 'COLUMN', N'IsManualRate'
GO
EXEC sp_addextendedproperty N'MS_Description', N'0 if the item is not billing on a recurring basis. 1 if the item is billing on a recurring basis.', 'SCHEMA', N'dbo', 'TABLE', N'StorageItems', 'COLUMN', N'IsRecurring'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Location or directions to the order in storage.', 'SCHEMA', N'dbo', 'TABLE', N'StorageItems', 'COLUMN', N'Location'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Quantity of the item.', 'SCHEMA', N'dbo', 'TABLE', N'StorageItems', 'COLUMN', N'Quantity'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Rate for the item.', 'SCHEMA', N'dbo', 'TABLE', N'StorageItems', 'COLUMN', N'Rate'
GO
EXEC sp_addextendedproperty N'MS_Description', N'First date the item no longer bills.', 'SCHEMA', N'dbo', 'TABLE', N'StorageItems', 'COLUMN', N'RecurringEndDate'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Primary key.', 'SCHEMA', N'dbo', 'TABLE', N'StorageItems', 'COLUMN', N'StorageItemsPriKey'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Foreign key to a storage item type.', 'SCHEMA', N'dbo', 'TABLE', N'StorageItems', 'COLUMN', N'StorageItemTypePriKey'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Foreign key to a storage order.', 'SCHEMA', N'dbo', 'TABLE', N'StorageItems', 'COLUMN', N'StoragePriKey'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Foreign key to a warehouse the item is at.', 'SCHEMA', N'dbo', 'TABLE', N'StorageItems', 'COLUMN', N'WarehousePriKey'
GO