CREATE TABLE [dbo].[InvoicedHeader]
(
[IHPriKey] [int] NOT NULL IDENTITY(1, 1),
[ANPriKey] [int] NULL,
[OrdPriKey] [int] NOT NULL,
[OrderNumber] [varchar] (23) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[InvoiceNumber] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[PrePaymentAmount] [money] NULL,
[InvoiceTotal] [money] NOT NULL,
[InvoiceDate] [datetime] NOT NULL,
[CreatedByFID] [int] NOT NULL,
[CreatedDate] [datetime] NOT NULL,
[InvoiceType] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[AlternateBillToFID] [int] NULL,
[CustomerNumber] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[CustomerName] [varchar] (65) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[BillingContact] [varchar] (61) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[BillingAddress] [varchar] (256) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[BillingCity] [dbo].[AddressCity] NULL,
[BillingState] [dbo].[AddressState] NULL,
[BillingPostalCode] [dbo].[AddressPostalCode] NULL,
[MoveFromAddress] [varchar] (768) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[MoveFromCity] [dbo].[AddressCity] NULL,
[MoveFromState] [dbo].[AddressState] NULL,
[MoveToAddress] [varchar] (768) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[MoveToCity] [dbo].[AddressCity] NULL,
[MoveToState] [dbo].[AddressState] NULL,
[HeaderVanlineAddressFID] [int] NULL,
[HeaderBranchAddressFID] [int] NULL,
[HeaderTitle] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[HeaderAddress] [dbo].[Address] NULL,
[HeaderCity] [dbo].[AddressCity] NULL,
[HeaderState] [dbo].[AddressState] NULL,
[HeaderPostalCode] [dbo].[AddressPostalCode] NULL,
[HeaderPhone] [dbo].[PhoneCombined] NULL,
[HeaderExtension] [dbo].[PhoneExtension] NULL,
[HeaderEmail] [varchar] (120) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[RemittanceVanlineAddressFID] [int] NULL,
[RemittanceBranchAddressFID] [int] NULL,
[RemittanceTitle] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[RemittanceAddress] [dbo].[Address] NULL,
[RemittanceCity] [dbo].[AddressCity] NULL,
[RemittanceState] [dbo].[AddressState] NULL,
[RemittancePostalCode] [dbo].[AddressPostalCode] NULL,
[RemittancePhone] [dbo].[PhoneCombined] NULL,
[RemittanceExtension] [dbo].[PhoneExtension] NULL,
[RemittanceEmail] [varchar] (120) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ShipperFirstName] [varchar] (16) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ShipperLastName] [varchar] (26) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[SalesPersonFirstName] [varchar] (16) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[SalesPersonLastName] [varchar] (26) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ChargeAmount] [decimal] (19, 2) NOT NULL CONSTRAINT [DF_InvoicedHeader_ChargeAmount] DEFAULT ((0)),
[ChargeAmountType] [varchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[MinimumCharge] [money] NOT NULL CONSTRAINT [DF_InvoicedHeader_MinimumCharge] DEFAULT ((0)),
[Conditions] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[DOT] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[PONumber] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Weight] [int] NULL,
[Tariff] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Miles] [int] NULL,
[InvoiceStatusFID] [int] NOT NULL,
[ClaimFID] [int] NULL,
[BillingAddress2] [varchar] (256) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[BillingAddress3] [varchar] (256) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[BillingCountryName] [varchar] (61) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[MoveFromCountryCodeStandardFID] [int] NULL,
[MoveToCountryCodeStandardFID] [int] NULL,
[InvoiceTermsOverrideOptionFID] [int] NOT NULL CONSTRAINT [DF_InvoicedHeader_InvoiceTermsOverrideOptionFID] DEFAULT ((1)),
[DueDate] [datetime] NULL,
[OriginalCustomerNumber] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ReportName] [varchar] (425) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[CustomerInvoiceReportFID] [int] NULL,
[MoveFromPostalCode] [dbo].[AddressPostalCode] NULL,
[MoveToPostalCode] [dbo].[AddressPostalCode] NULL,
[SalesTaxTotal] [money] NULL,
[SalesTaxCommitted] [bit] NULL,
[ServiceCalculatedSalesTax] [bit] NULL,
[TaxExemptionCode] [varchar] (25) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[GeneratingID] [uniqueidentifier] NULL,
[TaxServiceID] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[InvoicedHeader] ADD CONSTRAINT [PK_InvoicedHeader] PRIMARY KEY CLUSTERED ([IHPriKey]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_InvoicedHeader_ANPriKey] ON [dbo].[InvoicedHeader] ([ANPriKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_InvoicedHeader_CreatedByFID] ON [dbo].[InvoicedHeader] ([CreatedByFID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_InvoicedHeader_InvoiceNumber] ON [dbo].[InvoicedHeader] ([InvoiceNumber]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_InvoicedHeader_OrdPriKey] ON [dbo].[InvoicedHeader] ([OrdPriKey]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[InvoicedHeader] ADD CONSTRAINT [FK_InvoicedHeader_AccountingNote] FOREIGN KEY ([ANPriKey]) REFERENCES [dbo].[AccountingNote] ([ANPriKey])
GO
ALTER TABLE [dbo].[InvoicedHeader] ADD CONSTRAINT [FK_InvoicedHeader_Claim] FOREIGN KEY ([ClaimFID]) REFERENCES [dbo].[Claim] ([ClaimID])
GO
ALTER TABLE [dbo].[InvoicedHeader] ADD CONSTRAINT [FK_InvoicedHeader_Sysuser] FOREIGN KEY ([CreatedByFID]) REFERENCES [dbo].[Sysuser] ([SysUserID])
GO
ALTER TABLE [dbo].[InvoicedHeader] ADD CONSTRAINT [FK_InvoicedHeader_CustomerInvoiceReport] FOREIGN KEY ([CustomerInvoiceReportFID]) REFERENCES [dbo].[CustomerInvoiceReport] ([CustomerInvoiceReportID])
GO
ALTER TABLE [dbo].[InvoicedHeader] ADD CONSTRAINT [FK_HeaderInvoicedHeader_BranchAddress] FOREIGN KEY ([HeaderBranchAddressFID]) REFERENCES [dbo].[BranchAddress] ([BranchAddressID])
GO
ALTER TABLE [dbo].[InvoicedHeader] ADD CONSTRAINT [FK_HeaderInvoicedHeader_VanlineAddress] FOREIGN KEY ([HeaderVanlineAddressFID]) REFERENCES [dbo].[VanlineAddress] ([VanlineAddressID])
GO
ALTER TABLE [dbo].[InvoicedHeader] ADD CONSTRAINT [FK_InvoicedHeader_InvoiceStatus] FOREIGN KEY ([InvoiceStatusFID]) REFERENCES [dbo].[InvoiceStatus] ([InvoiceStatusID])
GO
ALTER TABLE [dbo].[InvoicedHeader] ADD CONSTRAINT [FK_InvoicedHeader_InvoiceTermsOverrideOption] FOREIGN KEY ([InvoiceTermsOverrideOptionFID]) REFERENCES [dbo].[InvoiceTermsOverrideOption] ([InvoiceTermsOverrideOptionID])
GO
ALTER TABLE [dbo].[InvoicedHeader] ADD CONSTRAINT [FK_InvoicedHeader_Orders] FOREIGN KEY ([OrdPriKey]) REFERENCES [dbo].[Orders] ([PriKey])
GO
ALTER TABLE [dbo].[InvoicedHeader] ADD CONSTRAINT [FK_RemittanceInvoicedHeader_BranchAddress] FOREIGN KEY ([RemittanceBranchAddressFID]) REFERENCES [dbo].[BranchAddress] ([BranchAddressID])
GO
ALTER TABLE [dbo].[InvoicedHeader] ADD CONSTRAINT [FK_RemittanceInvoicedHeader_VanlineAddress] FOREIGN KEY ([RemittanceVanlineAddressFID]) REFERENCES [dbo].[VanlineAddress] ([VanlineAddressID])
GO
GRANT SELECT ON [dbo].[InvoicedHeader] TO [MssExec]
GRANT INSERT ON [dbo].[InvoicedHeader] TO [MssExec]
GRANT DELETE ON [dbo].[InvoicedHeader] TO [MssExec]
GRANT UPDATE ON [dbo].[InvoicedHeader] TO [MssExec]
GO
EXEC sp_addextendedproperty N'MS_Description', N'This field is used internally to identify the initial customer selected by the user for this invoice.', 'SCHEMA', N'dbo', 'TABLE', N'InvoicedHeader', 'COLUMN', N'OriginalCustomerNumber'
GO
EXEC sp_addextendedproperty N'MS_Description', N'This field is used internally to locate the report used to generate the actual invoice.', 'SCHEMA', N'dbo', 'TABLE', N'InvoicedHeader', 'COLUMN', N'ReportName'
GO