CREATE TABLE [dbo].[SCBillingContractMiscCharges]
(
[BillingContractMiscChargeID] [int] NOT NULL IDENTITY(1, 1),
[InvoiceID] [int] NOT NULL,
[ContractDetailID] [int] NOT NULL,
[BaseFromDate] [datetime] NULL,
[BaseToDate] [datetime] NULL,
[OverageFromDate] [datetime] NULL,
[OverageToDate] [datetime] NULL,
[ContractMiscChargeID] [int] NOT NULL,
[MiscChargeCodeID] [int] NULL,
[Description] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Quantity] [decimal] (18, 6) NOT NULL,
[Rate] [decimal] (18, 6) NOT NULL,
[GLID] [int] NOT NULL,
[DeptID] [int] NULL,
[TaxFlag] [int] NOT NULL,
[BranchID] [int] NOT NULL,
[DivisionID] [int] NOT NULL,
[BalanceSheetGroupID] [int] NOT NULL,
[TaxCodeID] [int] NULL,
[BillWithID] [int] NOT NULL,
[BillFrequencyID] [int] NOT NULL,
[Amount] [money] NOT NULL,
[CreatorID] [varchar] (8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[CreateDate] [datetime] NOT NULL CONSTRAINT [DF_SCBillingContractMiscCharges_CreateDate] DEFAULT (getdate()),
[UpdatorID] [varchar] (8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[LastUpdate] [datetime] NOT NULL CONSTRAINT [DF_SCBillingContractMiscCharges_LastUpdate] DEFAULT (getdate()),
[TaxExemptCodeID] [int] NULL,
[Taxable] [bit] NOT NULL CONSTRAINT [DF_SCBillingContractMiscCharges_Taxable] DEFAULT ((0)),
[Method] [int] NOT NULL CONSTRAINT [DF_SCBillingContractMiscCharges_Method] DEFAULT ((0)),
[PercentMinimumAmount] [money] NULL,
[PercentMaximumAmount] [money] NULL,
[TaxFlagID] [int] NOT NULL,
[LocationID] [int] NULL,
[Address] [varchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_SCBillingContractMiscCharges_Address] DEFAULT (''),
[City] [varchar] (32) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_SCBillingContractMiscCharges_City] DEFAULT (''),
[State] [varchar] (16) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_SCBillingContractMiscCharges_State] DEFAULT (''),
[Zip] [varchar] (16) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_SCBillingContractMiscCharges_Zip] DEFAULT (''),
[County] [varchar] (32) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_SCBillingContractMiscCharges_County] DEFAULT (''),
[Country] [varchar] (32) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_SCBillingContractMiscCharges_Country] DEFAULT ('')
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[SCBillingContractMiscCharges] ADD CONSTRAINT [PK__SCBillin__3A6BA33595A038C3] PRIMARY KEY CLUSTERED ([BillingContractMiscChargeID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[SCBillingContractMiscCharges] ADD CONSTRAINT [FK_SCBillingContractMiscCharges_BalanceSheetGroupID_GLBalanceSheetGroups] FOREIGN KEY ([BalanceSheetGroupID]) REFERENCES [dbo].[GLBalanceSheetGroups] ([BalanceSheetGroupID])
GO
ALTER TABLE [dbo].[SCBillingContractMiscCharges] ADD CONSTRAINT [FK_SCBillingContractMiscCharges_BranchID_GLBranches] FOREIGN KEY ([BranchID]) REFERENCES [dbo].[GLBranches] ([BranchID])
GO
ALTER TABLE [dbo].[SCBillingContractMiscCharges] ADD CONSTRAINT [FK_SCBillingContractMiscCharges_ContractMiscChargeID_SCContractMiscCharges] FOREIGN KEY ([ContractMiscChargeID]) REFERENCES [dbo].[SCContractMiscCharges] ([MiscChargeID])
GO
ALTER TABLE [dbo].[SCBillingContractMiscCharges] ADD CONSTRAINT [FK_SCBillingContractMiscCharges_DeptID_GLDepts] FOREIGN KEY ([DeptID]) REFERENCES [dbo].[GLDepts] ([DeptID])
GO
ALTER TABLE [dbo].[SCBillingContractMiscCharges] ADD CONSTRAINT [FK_SCBillingContractMiscCharges_DivisionID_GLDivisions] FOREIGN KEY ([DivisionID]) REFERENCES [dbo].[GLDivisions] ([DivisionID])
GO
ALTER TABLE [dbo].[SCBillingContractMiscCharges] ADD CONSTRAINT [FK_SCBillingContractMiscCharges_GLID_GLAccounts] FOREIGN KEY ([GLID]) REFERENCES [dbo].[GLAccounts] ([AccountID])
GO
ALTER TABLE [dbo].[SCBillingContractMiscCharges] ADD CONSTRAINT [FK_SCBillingContractMiscCharges_InvoiceID_SCBillingContracts] FOREIGN KEY ([InvoiceID], [ContractDetailID]) REFERENCES [dbo].[SCBillingContracts] ([InvoiceID], [ContractDetailID])
GO
ALTER TABLE [dbo].[SCBillingContractMiscCharges] ADD CONSTRAINT [FK_SCBillingContractMiscCharges_LocationID_ARCustomers] FOREIGN KEY ([LocationID]) REFERENCES [dbo].[ARCustomers] ([CustomerID])
GO
ALTER TABLE [dbo].[SCBillingContractMiscCharges] ADD CONSTRAINT [FK_SCBillingContractMiscCharges_MiscChargeCodeID_SCContractMiscChargeCodes] FOREIGN KEY ([MiscChargeCodeID]) REFERENCES [dbo].[SCContractMiscChargeCodes] ([MiscChargeCodeID])
GO
ALTER TABLE [dbo].[SCBillingContractMiscCharges] ADD CONSTRAINT [FK_SCBillingContractMiscCharges_TaxcodeID_ShTaxCodes] FOREIGN KEY ([TaxCodeID]) REFERENCES [dbo].[ShTaxCodes] ([TaxCodeID])
GO
ALTER TABLE [dbo].[SCBillingContractMiscCharges] ADD CONSTRAINT [FK_SCBillingContractMiscCharges_TaxExemptCodeID_SHTaxExemptCodes] FOREIGN KEY ([TaxExemptCodeID]) REFERENCES [dbo].[SHTaxExemptCodes] ([TaxExemptCodeID])
GO
ALTER TABLE [dbo].[SCBillingContractMiscCharges] ADD CONSTRAINT [FK_SCBillingContractMiscCharges_TaxFlagID_ShTaxFlags] FOREIGN KEY ([TaxFlagID]) REFERENCES [dbo].[ShTaxFlags] ([TaxFlagID])
GO