CREATE TABLE [dbo].[ARAPReceivablePayableDistributions]
(
[ReceivablePayableDistributionID] [int] NOT NULL IDENTITY(1, 1),
[ReceivablePayableID] [int] NOT NULL,
[SourceDetailID] [int] NULL,
[SourceDetailID2] [int] NULL,
[GLID] [int] NOT NULL,
[BranchID] [int] NOT NULL,
[DivisionID] [int] NOT NULL,
[BalanceSheetGroupID] [int] NOT NULL,
[GLTypeID] [int] NOT NULL,
[DistTypeID] [int] NOT NULL,
[Amount] [money] NOT NULL,
[TermDiscount] [money] NOT NULL,
[OpenAmount] [money] NOT NULL,
[Freight] [money] NOT NULL CONSTRAINT [DF_ARAPReceivablePayableDistributions_Freight] DEFAULT ((0)),
[Discount] [money] NOT NULL CONSTRAINT [DF_ARAPReceivablePayableDistributions_Discount] DEFAULT ((0)),
[Tax] [money] NOT NULL CONSTRAINT [DF_ARAPReceivablePayableDistributions_Tax] DEFAULT ((0)),
[Fee] [money] NOT NULL CONSTRAINT [DF_ARAPReceivablePayableDistributions_Fee] DEFAULT ((0)),
[IntercompanyGLID] [int] NULL,
[CashbookIntercompanyGLID] [int] NULL,
[TermDiscountBaseAmount] [money] NOT NULL CONSTRAINT [DF_ARAPReceivablePayableDistributions_TermDiscountBaseAmount] DEFAULT ((0))
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[ARAPReceivablePayableDistributions] ADD CONSTRAINT [PK__ARAPRece__7EFF043E6F44D590] PRIMARY KEY CLUSTERED ([ReceivablePayableDistributionID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[ARAPReceivablePayableDistributions] ADD CONSTRAINT [FK_ARAPReceivablePayableDistributions_BalanceSheetGroupID_GLBalanceSheetGroups] FOREIGN KEY ([BalanceSheetGroupID]) REFERENCES [dbo].[GLBalanceSheetGroups] ([BalanceSheetGroupID])
GO
ALTER TABLE [dbo].[ARAPReceivablePayableDistributions] ADD CONSTRAINT [FK_ARAPReceivablePayableDistributions_BranchID_GLBranches] FOREIGN KEY ([BranchID]) REFERENCES [dbo].[GLBranches] ([BranchID])
GO
ALTER TABLE [dbo].[ARAPReceivablePayableDistributions] ADD CONSTRAINT [FK_ARAPReceivablePayableDistributions_CashbookIntercompanyGLID_GLAccounts] FOREIGN KEY ([CashbookIntercompanyGLID]) REFERENCES [dbo].[GLAccounts] ([AccountID])
GO
ALTER TABLE [dbo].[ARAPReceivablePayableDistributions] ADD CONSTRAINT [FK_ARAPReceivablePayableDistributions_DivisionID_GLDivisions] FOREIGN KEY ([DivisionID]) REFERENCES [dbo].[GLDivisions] ([DivisionID])
GO
ALTER TABLE [dbo].[ARAPReceivablePayableDistributions] ADD CONSTRAINT [FK_ARAPReceivablePayableDistributions_GLID_GLAccounts] FOREIGN KEY ([GLID]) REFERENCES [dbo].[GLAccounts] ([AccountID])
GO
ALTER TABLE [dbo].[ARAPReceivablePayableDistributions] ADD CONSTRAINT [FK_ARAPReceivablePayableDistributions_IntercompanyGLID_GLAccounts] FOREIGN KEY ([IntercompanyGLID]) REFERENCES [dbo].[GLAccounts] ([AccountID])
GO
ALTER TABLE [dbo].[ARAPReceivablePayableDistributions] ADD CONSTRAINT [FK_ARAPReceivablePayableDistributions_ReceivablePayableID_ARAPReceivablePayables] FOREIGN KEY ([ReceivablePayableID]) REFERENCES [dbo].[ARAPReceivablePayables] ([ReceivablePayableID])
GO