/*
Msg 1776, Level 16, State 0, Line 4943
There are no primary or candidate keys in the referenced table 'dbo.VoucherRow' that match the referencing column list in the foreign key 'FK_AllocationPeriod_VoucherRow'.
Msg 1750, Level 16, State 0, Line 4943
Could not create constraint or index. See previous errors.
Msg 4917, Level 16, State 0, Line 4946
Constraint 'FK_AllocationPeriod_VoucherRow' does not exist.
Msg 4916, Level 16, State 0, Line 4946
Could not enable or disable the constraint. See previous errors.
*/

USE [eaShard1]
GO
/****** Object:  Table [dbo].[Account]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Account](
	[Name] [nvarchar](100) NOT NULL,
	[Number] [bigint] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[FiscalYearId] [uniqueidentifier] NOT NULL,
	[IsActive] [bit] NOT NULL,
	[VatCodeId] [uniqueidentifier] NULL,
	[Balance] [money] NOT NULL,
	[OpeningBalance] [money] NOT NULL,
	[CreatedByUserId] [uniqueidentifier] NULL,
	[ModifiedByUserId] [uniqueidentifier] NULL,
	[CreatedUtc] [datetime2](7) NULL,
	[IsBlockedForManualBooking] [bit] NOT NULL,
	[ModifiedUtc] [datetime2](7) NOT NULL,
	[IsCostCenterAllowed] [bit] NOT NULL,
	[IsProjectAllowed] [bit] NOT NULL,
	[Type] [int] NULL,
	[ReferenceCode] [nvarchar](20) NOT NULL,
	[AllowTransactionText] [bit] NOT NULL,
	[IsFirstCostCenterMandatory] [bit] NULL,
 CONSTRAINT [PK_Account] PRIMARY KEY CLUSTERED 
(
	[CompanyId] ASC,
	[FiscalYearId] ASC,
	[Number] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[AccountingPeriodLock]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AccountingPeriodLock](
	[LockDate] [datetime] NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[PreviousLockDate] [datetime2](7) NULL,
 CONSTRAINT [PK_AccountingPeriodLock] PRIMARY KEY CLUSTERED 
(
	[CompanyId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[AccountingTemplate]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AccountingTemplate](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Category] [int] NOT NULL,
	[Name] [nvarchar](100) NULL,
	[Description] [nvarchar](250) NULL,
	[IsVisible] [bit] NOT NULL,
	[IsChangeable] [bit] NOT NULL,
	[VoucherActionType] [int] NULL,
	[NameEnglish] [varchar](200) NULL,
 CONSTRAINT [PK_AccountingTemplate] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[AccountingTemplateRow]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AccountingTemplateRow](
	[Id] [uniqueidentifier] NOT NULL,
	[AccountingTemplateId] [uniqueidentifier] NOT NULL,
	[AccountingType] [int] NOT NULL,
	[LineNumber] [int] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[AccountNumber] [bigint] NOT NULL,
 CONSTRAINT [PK_AccountingTemplateRow] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[AccountRange]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AccountRange](
	[FromAccountNumber] [int] NOT NULL,
	[ToAccountNumber] [int] NOT NULL,
	[ChartOfAccountsInfoId] [uniqueidentifier] NOT NULL,
	[AccountRangeType] [int] NOT NULL,
	[Id] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_AccountRange] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [UK_AccountRange_FromAccountNumber] UNIQUE NONCLUSTERED 
(
	[AccountRangeType] ASC,
	[ChartOfAccountsInfoId] ASC,
	[FromAccountNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [UK_AccountRange_ToAccountNumber] UNIQUE NONCLUSTERED 
(
	[AccountRangeType] ASC,
	[ChartOfAccountsInfoId] ASC,
	[ToAccountNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[AccountReceivableTermsOfPaymentRelation]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AccountReceivableTermsOfPaymentRelation](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[TermsOfPaymentId] [uniqueidentifier] NOT NULL,
	[AccountNumber] [bigint] NOT NULL,
 CONSTRAINT [PK_AccountReceivableTermsOfPaymentRelation] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[AccountReferenceCode]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AccountReferenceCode](
	[Id] [uniqueidentifier] NOT NULL,
	[ReferenceCode] [varchar](50) NULL,
	[Description] [varchar](200) NULL,
 CONSTRAINT [PK_AccountReferenceCode] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[AccountValuationHistory]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AccountValuationHistory](
	[CompanyId] [uniqueidentifier] NOT NULL,
	[FiscalYearId] [uniqueidentifier] NOT NULL,
	[AccountNumber] [bigint] NOT NULL,
	[Date] [date] NOT NULL,
	[Value] [money] NOT NULL,
	[CostCenterItemId] [uniqueidentifier] NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[AllocationPeriod]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AllocationPeriod](
	[Id] [uniqueidentifier] NOT NULL,
	[SupplierInvoiceId] [uniqueidentifier] NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[VoucherId] [uniqueidentifier] NULL,
	[BookkeepingDate] [datetime2](7) NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[Status] [int] NOT NULL,
	[SupplierInvoiceRowId] [uniqueidentifier] NULL,
	[ManualVoucherId] [uniqueidentifier] NULL,
	[ManualVoucherRowLine] [int] NULL,
 CONSTRAINT [PK_AllocationPeriod] PRIMARY KEY CLUSTERED 
(
	[CompanyId] ASC,
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[AllocationPeriodRow]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AllocationPeriodRow](
	[Id] [uniqueidentifier] NOT NULL,
	[AllocationPeriodId] [uniqueidentifier] NOT NULL,
	[AccountNumber] [bigint] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Amount] [money] NOT NULL,
	[DebitCredit] [int] NOT NULL,
	[Quantity] [decimal](19, 2) NULL,
	[Weight] [decimal](19, 2) NULL,
 CONSTRAINT [PK_AllocationPeriodRow] PRIMARY KEY CLUSTERED 
(
	[CompanyId] ASC,
	[AllocationPeriodId] ASC,
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Article]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Article](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Number] [nvarchar](40) NOT NULL,
	[Name] [nvarchar](50) NULL,
	[ArticleAccountCodingId] [uniqueidentifier] NOT NULL,
	[UnitId] [uniqueidentifier] NOT NULL,
	[IsActive] [bit] NOT NULL,
	[NetPrice] [money] NOT NULL,
	[NameEnglish] [nvarchar](50) NULL,
	[CreatedUtc] [datetime2](7) NULL,
	[ChangedUtc] [datetime2](7) NOT NULL,
	[Group] [int] NOT NULL,
	[StockBalance] [decimal](19, 4) NULL,
	[StockBalanceManuallyChanged] [datetime2](7) NULL,
	[SyncId] [nvarchar](36) NOT NULL,
	[StockBalanceReserved] [decimal](19, 4) NULL,
	[GrossPrice] [money] NOT NULL,
	[UsesMoss] [bit] NOT NULL,
	[MdsSyncState] [int] NOT NULL,
	[HouseWorkType] [int] NULL,
	[SendToWebshop] [bit] NOT NULL,
	[PurchasePrice] [decimal](19, 4) NOT NULL,
	[PurchasePriceManuallyChanged] [datetime2](7) NULL,
 CONSTRAINT [PK_Article] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[ArticleAccountCoding]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ArticleAccountCoding](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
	[ArticleType] [int] NOT NULL,
	[IsActive] [bit] NOT NULL,
	[IsChangeable] [bit] NOT NULL,
	[SalesAccountNumber] [bigint] NULL,
	[SalesNoVatAccountNumber] [bigint] NULL,
	[SalesEgNoVatAccountNumber] [bigint] NULL,
	[SalesEgAccountNumber] [bigint] NULL,
	[SalesOutsideEgAccountNumber] [bigint] NULL,
	[SalesEgThirdPartyAccountNumber] [bigint] NULL,
	[SalesConstructionAccountNumber] [bigint] NULL,
	[ChangedUtc] [datetime2](7) NOT NULL,
	[VatRateId] [uniqueidentifier] NOT NULL,
	[IsWebShopPrefered] [bit] NOT NULL,
	[SalesMossAccountNumber] [bigint] NULL,
	[NameEnglish] [varchar](200) NULL,
	[SalesNoVatCodeAccountNumber] [bigint] NULL,
 CONSTRAINT [PK_ArticleAccountCoding] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[ArticleLabel]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ArticleLabel](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
	[Description] [nvarchar](400) NULL,
 CONSTRAINT [PK_ArticleLabel] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[ArticlePriceHistory]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ArticlePriceHistory](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[ArticleId] [uniqueidentifier] NOT NULL,
	[PriceType] [int] NOT NULL,
	[UpdatedUtc] [datetime2](7) NOT NULL,
	[Value] [money] NOT NULL,
 CONSTRAINT [PK_ArticlePriceHistory] PRIMARY KEY NONCLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[ArticleToArticleLabel]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ArticleToArticleLabel](
	[CompanyId] [uniqueidentifier] NOT NULL,
	[ArticleId] [uniqueidentifier] NOT NULL,
	[ArticleLabelId] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_ArticleToArticleLabel] PRIMARY KEY CLUSTERED 
(
	[CompanyId] ASC,
	[ArticleId] ASC,
	[ArticleLabelId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[AutoInvoiceInboundDocument]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AutoInvoiceInboundDocument](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[SupplierInvoiceId] [uniqueidentifier] NULL,
	[SequenceNumber] [int] NOT NULL,
	[FileType] [int] NOT NULL,
	[Status] [int] NOT NULL,
	[DocumentId] [uniqueidentifier] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[Source] [int] NOT NULL,
	[LastParseTryUtc] [datetime2](7) NULL,
 CONSTRAINT [PK_AutoInvoiceInboundStatus] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[AutoInvoiceInboundDocumentAttachment]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AutoInvoiceInboundDocumentAttachment](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[AutoInvoiceInboundDocumentId] [uniqueidentifier] NOT NULL,
	[FileType] [int] NOT NULL,
	[DocumentId] [uniqueidentifier] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
 CONSTRAINT [PK_AutoInvoiceInboundDocumentAttachment] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[AutoInvoiceInterimSupplier]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AutoInvoiceInterimSupplier](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
	[CorporateIdentityNumber] [nvarchar](20) NULL,
	[Address1] [nvarchar](50) NULL,
	[Address2] [nvarchar](50) NULL,
	[PostalCode] [nvarchar](10) NULL,
	[City] [nvarchar](50) NULL,
	[CountryCode] [nvarchar](2) NULL,
	[BankCountryCode] [nvarchar](2) NULL,
	[CurrencyCode] [nvarchar](3) NULL,
	[Telephone] [nvarchar](50) NULL,
	[MobilePhone] [nvarchar](50) NULL,
	[EmailAddress] [nvarchar](255) NULL,
	[WwwAddress] [nvarchar](255) NULL,
	[BankAccountNumber] [nvarchar](50) NULL,
	[BankgiroNumber] [nvarchar](10) NULL,
	[PlusgiroNumber] [nvarchar](10) NULL,
	[BankName] [nvarchar](50) NULL,
	[BankCurrencyCode] [nvarchar](3) NULL,
	[BankBic] [nvarchar](50) NULL,
	[BankBban] [nvarchar](50) NULL,
	[BankIban] [nvarchar](50) NULL,
	[BankCode] [nvarchar](50) NULL,
	[TermsOfPaymentId] [uniqueidentifier] NOT NULL,
	[CompanyBankAccountId] [uniqueidentifier] NULL,
	[Ocr] [bit] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[VatNumber] [nvarchar](20) NULL,
 CONSTRAINT [PK_AutoInvoiceInterimSupplier] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[AutoInvoiceOutboundStatus]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AutoInvoiceOutboundStatus](
	[Id] [uniqueidentifier] NOT NULL,
	[CustomerInvoiceId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Status] [nvarchar](50) NOT NULL,
	[Time] [datetime2](7) NOT NULL,
	[Error] [nvarchar](max) NULL,
	[CreatedUtc] [datetime2](7) NULL,
 CONSTRAINT [PK_AutoInvoiceOutboundStatus] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[AutoInvoiceSIMessage]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AutoInvoiceSIMessage](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[BankBIC] [nvarchar](11) NOT NULL,
	[MessageType] [int] NOT NULL,
	[Status] [int] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[RetryCount] [int] NOT NULL,
	[StatusDateUtc] [datetime2](7) NULL,
	[BankAccountId] [uniqueidentifier] NULL,
 CONSTRAINT [PK_AutoInvoiceSIMessage] PRIMARY KEY CLUSTERED 
(
	[CompanyId] ASC,
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Bank]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Bank](
	[Id] [uniqueidentifier] NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
	[BIC] [nvarchar](11) NOT NULL,
	[CountryCode] [nvarchar](2) NOT NULL,
	[Type] [int] NOT NULL,
	[TransactionFeePercentage] [decimal](5, 4) NULL,
	[TransactionFeeFixed] [money] NULL,
	[EikaGroup] [bit] NOT NULL,
	[SpareBankenGroup] [bit] NOT NULL,
 CONSTRAINT [PK_Bank] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [UK_BankNameCountry] UNIQUE NONCLUSTERED 
(
	[CountryCode] ASC,
	[Name] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[BankAccountTransfer]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BankAccountTransfer](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Description] [nvarchar](100) NULL,
	[BankAccountId] [uniqueidentifier] NOT NULL,
	[BankAccountName] [nvarchar](100) NULL,
	[Amount] [money] NOT NULL,
	[AccountCodingTemplateName] [nvarchar](100) NULL,
	[Date] [datetime2](7) NULL,
	[TransferType] [int] NOT NULL,
 CONSTRAINT [PK_BankAccountTransfer] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[BankAccountTransferRow]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BankAccountTransferRow](
	[Id] [uniqueidentifier] NOT NULL,
	[BankAccountTransferId] [uniqueidentifier] NOT NULL,
	[AccountName] [nvarchar](200) NOT NULL,
	[RowNumber] [int] NOT NULL,
	[DebitCredit] [int] NOT NULL,
	[AmountInTransactionCurrency] [money] NOT NULL,
	[VatCodeId] [uniqueidentifier] NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[FiscalYearId] [uniqueidentifier] NOT NULL,
	[AccountNumber] [bigint] NOT NULL,
	[AmountInBaseCurrency] [money] NULL,
	[TransactionCurrency] [nvarchar](3) NOT NULL,
	[CostCenterItemId1] [uniqueidentifier] NULL,
	[CostCenterItemId2] [uniqueidentifier] NULL,
	[CostCenterItemId3] [uniqueidentifier] NULL,
	[ProjectId] [uniqueidentifier] NULL,
	[VatAmount] [money] NULL,
	[Quantity] [decimal](19, 4) SPARSE  NULL,
	[Weight] [decimal](19, 4) SPARSE  NULL,
	[DeliveryDate] [datetime] SPARSE  NULL,
	[HarvestYear] [int] SPARSE  NULL,
 CONSTRAINT [PK_BankAccountTransferRow] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[BankIntegrationInformationDnbNor]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BankIntegrationInformationDnbNor](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[NextHeaderSequenceNumber] [int] NOT NULL,
	[NextOrderSequenceNumber] [int] NOT NULL,
	[LastBankSyncUtc] [datetime2](7) NOT NULL,
	[BankId] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_BankIntegrationInformationDnbNor] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[BankTransaction]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BankTransaction](
	[Id] [uniqueidentifier] NOT NULL,
	[BankTransactionBatchId] [uniqueidentifier] NULL,
	[Amount] [money] NOT NULL,
	[AmountCurrency] [nvarchar](3) NOT NULL,
	[Charge] [money] NOT NULL,
	[ChargeCurrency] [nvarchar](3) NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[TransactionDate] [datetime2](7) NULL,
	[ExchangeRate] [numeric](18, 12) NOT NULL,
	[HiddenReference] [nvarchar](50) NULL,
	[InvoiceReference] [nvarchar](max) NULL,
	[OriginalAmount] [money] NOT NULL,
	[OriginalAmountCurrency] [nvarchar](3) NULL,
	[CreatedUtc] [datetime2](7) NULL,
	[BusinessTransactionId] [uniqueidentifier] NULL,
	[BankTransactionOrigin] [int] NOT NULL,
	[CompanyBankAccountId] [uniqueidentifier] NOT NULL,
	[ValidForAutomaticReconciliation] [bit] NOT NULL,
	[IsUnpacked] [bit] NOT NULL,
	[IsWaitingForUnpackingInformation] [bit] NOT NULL,
	[UnpackingInformationReference] [nvarchar](20) NULL,
	[SuggestedMatchBusinessTransactionId] [uniqueidentifier] NULL,
	[SuggestedMatchSourceId] [uniqueidentifier] NULL,
	[SuggestedMatchSourceType] [int] NOT NULL,
	[SuggestedMatchVoucherId] [uniqueidentifier] NULL,
	[SuggestedMatchVoucherType] [int] NOT NULL,
	[SuggestedMatchNumber] [varchar](255) NULL,
	[SuggestedMatchReference] [varchar](255) NULL,
	[SuggestedMatchName] [varchar](255) NULL,
	[SuggestedMatchAmount] [money] NOT NULL,
	[IsSuspectedDuplicate] [bit] NOT NULL,
	[IsPreliminary] [bit] NOT NULL,
	[Beneficiary] [nvarchar](200) NULL,
	[BeneficiaryBank] [nvarchar](200) NULL,
	[InstructedReference] [nvarchar](200) NULL,
	[TransactionFeedbackFileInformationId] [uniqueidentifier] SPARSE  NULL,
	[UnstructuredRemittanceInfo] [nvarchar](400) NULL,
	[MasterBankTransactionReferenceId] [uniqueidentifier] SPARSE  NULL,
	[IsMasterBankTransaction] [bit] NOT NULL,
 CONSTRAINT [PK_BankTransaction] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[BankTransactionBatch]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BankTransactionBatch](
	[Id] [uniqueidentifier] NOT NULL,
	[Filename] [nvarchar](255) NOT NULL,
	[CreatedUtc] [datetime] NOT NULL,
	[OpeningBalance] [money] NOT NULL,
	[ClosingBalance] [money] NOT NULL,
	[CompanyBankAccountId] [uniqueidentifier] NOT NULL,
	[ReferenceNumber] [nvarchar](100) NOT NULL,
	[OpeningDate] [datetime2](7) NULL,
	[BankMessageId] [uniqueidentifier] NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_BankTransactionBatch] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[BankTransactionReconciliation]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BankTransactionReconciliation](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Summary] [varchar](4096) NOT NULL,
	[VoucherNumber] [varchar](255) NOT NULL,
	[UserId] [uniqueidentifier] NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[BankTransactionId] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_BankTransactionReconciliation] PRIMARY KEY NONCLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[BankTransactionReconciliationRow]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BankTransactionReconciliationRow](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[BankTransactionReconciliationId] [uniqueidentifier] NOT NULL,
	[BusinessTransactionId] [uniqueidentifier] NOT NULL,
	[AmountInTransactionCurrency] [money] NOT NULL,
	[Action] [int] NOT NULL,
	[ReconciliationType] [int] NOT NULL,
	[PaymentVoucherId] [uniqueidentifier] NULL,
	[BankId] [uniqueidentifier] NULL,
	[BankAccountType] [int] NULL,
	[BankAccountNumber] [nvarchar](35) NULL,
 CONSTRAINT [PK_BankTransactionReconciliationRow] PRIMARY KEY NONCLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[BusinessTransaction]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BusinessTransaction](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[SourceId] [uniqueidentifier] NULL,
	[CompanyBankAccountId] [uniqueidentifier] NULL,
	[SourceType] [int] NOT NULL,
	[TransactionDate] [datetime2](7) NULL,
	[DisplayId] [nvarchar](50) NOT NULL,
	[VoucherId] [uniqueidentifier] NULL,
	[DueDate] [datetime2](7) NULL,
	[Reference] [nvarchar](max) NULL,
	[HiddenReference] [nvarchar](50) NULL,
	[OriginalAmountInTransactionCurrency] [money] NOT NULL,
	[OriginalAmountInBaseCurrency] [money] NOT NULL,
	[OriginalChargeInTransactionCurrency] [money] NOT NULL,
	[OriginalChargeInBaseCurrency] [money] NOT NULL,
	[RemainingAmountInTransactionCurrency] [money] NOT NULL,
	[RemainingAmountInBaseCurrency] [money] NOT NULL,
	[RemainingChargeInTransactionCurrency] [money] NOT NULL,
	[RemainingChargeInBaseCurrency] [money] NOT NULL,
	[TransactionCurrency] [nvarchar](3) NOT NULL,
	[BaseCurrency] [nvarchar](3) NOT NULL,
	[ChargeCurrency] [nvarchar](3) NOT NULL,
	[ExchangeRate] [numeric](18, 12) NOT NULL,
	[LastReconciliationType] [int] NOT NULL,
	[LastReconciliationDateUtc] [datetime2](7) NULL,
	[LastUpdated] [datetime2](7) NULL,
	[CreatedUtc] [datetime2](7) NULL,
	[DeductionAmountInBaseCurrency] [money] NOT NULL,
 CONSTRAINT [PK_BusinessTransaction] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[BusinessTransactionReconciliation]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BusinessTransactionReconciliation](
	[CompanyId] [uniqueidentifier] NOT NULL,
	[BankBusinessTransactionId] [uniqueidentifier] NOT NULL,
	[UserId] [uniqueidentifier] NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
 CONSTRAINT [PK_BusinessTransactionReconciliation] PRIMARY KEY CLUSTERED 
(
	[CompanyId] ASC,
	[BankBusinessTransactionId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[BusinessTransactionReconciliationRow]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BusinessTransactionReconciliationRow](
	[CompanyId] [uniqueidentifier] NOT NULL,
	[BankBusinessTransactionId] [uniqueidentifier] NOT NULL,
	[LineNumber] [smallint] NOT NULL,
	[EventBusinessTransactionId] [uniqueidentifier] NOT NULL,
	[AmountInTransactionCurrency] [money] NOT NULL,
	[Action] [int] NOT NULL,
	[ReconciliationType] [int] NOT NULL,
	[PaymentVoucherId] [uniqueidentifier] NULL,
 CONSTRAINT [PK_BusinessTransactionReconciliationRow] PRIMARY KEY CLUSTERED 
(
	[CompanyId] ASC,
	[BankBusinessTransactionId] ASC,
	[LineNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[ChartOfAccountsExtension]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ChartOfAccountsExtension](
	[AccountName] [nvarchar](200) NOT NULL,
	[AccountNumber] [int] NOT NULL,
	[ChartOfAccountsInfoId] [uniqueidentifier] NOT NULL,
	[Id] [uniqueidentifier] NOT NULL,
	[VatCodeId] [uniqueidentifier] NULL,
	[TypeOfBusiness] [int] NOT NULL,
	[IsCostCenterAllowed] [bit] NOT NULL,
	[IsProjectAllowed] [bit] NOT NULL,
	[Type] [int] NULL,
	[AllowTransactionText] [bit] NOT NULL,
 CONSTRAINT [PK_ChartOfAccountsExtension] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [UK_ChartOfAccountsExtension_AccountNo] UNIQUE NONCLUSTERED 
(
	[AccountNumber] ASC,
	[ChartOfAccountsInfoId] ASC,
	[TypeOfBusiness] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[ChartOfAccountsInfo]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ChartOfAccountsInfo](
	[Id] [uniqueidentifier] NOT NULL,
	[Name] [nvarchar](50) NULL,
	[Year] [int] NOT NULL,
	[CountryCode] [nvarchar](2) NOT NULL,
 CONSTRAINT [PK_ChartOfAccountsInfo] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[ChartOfAccountsTemplate]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ChartOfAccountsTemplate](
	[AccountName] [nvarchar](100) NOT NULL,
	[AccountNumber] [bigint] NOT NULL,
	[ChartOfAccountsInfoId] [uniqueidentifier] NOT NULL,
	[Id] [uniqueidentifier] NOT NULL,
	[VatCodeId] [uniqueidentifier] NULL,
	[IsActiveWhenHasCars] [bit] NOT NULL,
	[IsActiveWhenHasConsultingBusiness] [bit] NOT NULL,
	[IsActiveWhenHasEmployees] [bit] NOT NULL,
	[IsActiveWhenHasTemporaryEmployees] [bit] NOT NULL,
	[IsActiveWhenSoleProprietorship] [bit] NOT NULL,
	[IsActiveWhenCorporation] [bit] NOT NULL,
	[IsActiveWhenGeneralPartnership] [bit] NOT NULL,
	[IsActiveWhenNonProfitOrganization] [bit] NOT NULL,
	[IsActiveWhenEconomicAssociation] [bit] NOT NULL,
	[IsActiveWhenCooperatives] [bit] NOT NULL,
	[IsActiveWhenLimitedPartnership] [bit] NOT NULL,
	[IsBlockedForManualBooking] [bit] NOT NULL,
	[IsCostCenterAllowed] [bit] NOT NULL,
	[IsProjectAllowed] [bit] NOT NULL,
	[Type] [int] NULL,
	[ReferenceCode] [nvarchar](20) NOT NULL,
	[AllowTransactionText] [bit] NOT NULL,
	[IsActiveWhenPublicLimited] [bit] NOT NULL,
 CONSTRAINT [PK_ChartOfAccountsTemplate] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [UK_ChartOfAccountsTemplate_AccountNo] UNIQUE NONCLUSTERED 
(
	[ChartOfAccountsInfoId] ASC,
	[AccountNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Company]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Company](
	[Id] [uniqueidentifier] NOT NULL,
	[CorporateIdentityNumber] [nvarchar](20) NOT NULL,
	[Name] [nvarchar](100) NOT NULL,
	[Address1] [nvarchar](40) NULL,
	[Address2] [nvarchar](40) NULL,
	[PostalCode] [nvarchar](10) NULL,
	[BaseCurrencyCode] [nvarchar](3) NOT NULL,
	[City] [nvarchar](40) NULL,
	[Phone] [nvarchar](20) NULL,
	[Mobile] [nvarchar](20) NULL,
	[Fax] [nvarchar](20) NULL,
	[Email] [nvarchar](255) NULL,
	[Web] [nvarchar](255) NULL,
	[VatCode] [nvarchar](14) NULL,
	[BankgiroNumber] [nvarchar](20) NULL,
	[PlusgiroNumber] [nvarchar](20) NULL,
	[HasFTaxCard] [bit] NOT NULL,
	[UsesMiddlemansSaleOfGoodsEc] [bit] NOT NULL,
	[UsesReverseConstructionVat] [bit] NOT NULL,
	[UsesRotReducedInvoicing] [bit] NOT NULL,
	[Residence] [nvarchar](80) NULL,
	[RotReducedInvoicingMaxAmount] [money] NULL,
	[RotReducedInvoicingPercent] [decimal](10, 4) NULL,
	[State] [int] NOT NULL,
	[UseAdvancedMode] [bit] NOT NULL,
	[VatPeriodType] [int] NOT NULL,
	[TypeOfBusiness] [int] NOT NULL,
	[FirstVatDate] [datetime2](7) NULL,
	[VismaCustomerNumber] [int] NULL,
	[CountryCode] [nvarchar](2) NOT NULL,
	[CreatedUtc] [datetime2](7) NULL,
	[PreviousCompanyId] [uniqueidentifier] NULL,
	[CompanyStatus] [int] NOT NULL,
	[VismaCustomerId] [uniqueidentifier] NULL,
	[VismaWebshopStatus] [int] NOT NULL,
	[VismaWebshopLatestOrderNumber] [int] NOT NULL,
	[VismaWebshopLatestReceiveTimeUtc] [datetime2](7) NOT NULL,
	[CompanySystemType] [int] NOT NULL,
	[VismaWebshopSyncIsRequired] [bit] NOT NULL,
	[DanskeBankNumber] [nvarchar](10) NULL,
	[VismaWebshopLatestSendTimeUtc] [datetime2](7) NOT NULL,
	[AutoInvoiceLatestReceivedErrorNumber] [int] NOT NULL,
	[LastEdiSupplierInvoiceNumber] [int] NOT NULL,
	[EdiGlnNumber] [nvarchar](255) NULL,
	[UsesOcr] [bit] NOT NULL,
	[PrintTheme] [int] NOT NULL,
	[TrialExpireDate] [date] NULL,
	[LatePaymentFee] [decimal](10, 4) NOT NULL,
	[FirstPaymentReminderWithoutFee] [bit] NOT NULL,
	[CollectionThreshold] [int] NOT NULL,
	[UsesQr] [bit] NOT NULL,
	[PaymentFileActivated] [bit] NOT NULL,
	[UsesCostCenter] [bit] NOT NULL,
	[Modules] [nvarchar](1024) NULL,
	[UsesSupplierinvoiceApproval] [bit] NOT NULL,
	[ProductVariant] [int] NOT NULL,
	[OriginalCompanySystemType] [int] NULL,
	[AutoInvoiceStatus] [int] NOT NULL,
	[CompanyDepreciation] [int] NOT NULL,
	[LastSie4iExportDate] [datetime2](7) NULL,
	[AutoInvoiceLatestReceivedOutboundStatusTime] [datetime2](7) NULL,
	[AutoInvoiceOutboundStatusLatestSyncTime] [datetime2](7) NULL,
	[ShowPayroll] [bit] NOT NULL,
	[UsesMoss] [bit] NOT NULL,
	[DefaultSalaryPaymentDay] [int] NOT NULL,
	[AccountingPeriodLockSettingsType] [int] NOT NULL,
	[TaxDeclarationDate] [datetime2](7) NULL,
	[AutoInvoiceInboundStatus] [int] NOT NULL,
	[MdsSyncState] [int] NOT NULL,
	[UsesProject] [bit] NOT NULL,
	[HasCustomStandardAccounts] [bit] NOT NULL,
	[HasTimeIntegration] [bit] NOT NULL,
	[AutoInvoiceB2CStatus] [int] NOT NULL,
	[UsesTransactionText] [bit] NOT NULL,
	[InvoicePrintSettingsType] [int] NOT NULL,
	[AccountNumberDigits] [int] NOT NULL,
	[UsesQuickInvoice] [bit] NOT NULL,
	[MigrationGuideState] [int] NOT NULL,
	[HasCustomVatCodeSettings] [bit] NOT NULL,
	[AutoInvoiceB2CStatusChanged] [datetime2](7) NULL,
	[AutoInvoiceB2CStatusLatestSyncTime] [datetime2](7) NULL,
	[MigrationExportApplication] [int] NULL,
	[AutoInvoiceB2CStatusSyncRetryCount] [int] NOT NULL,
	[AutoInvoiceOutboundStatusSyncRetryCount] [int] NOT NULL,
	[AutoInvoiceInboundSyncRetryCount] [int] NOT NULL,
	[UsesVatRowSuggestions] [bit] NOT NULL,
	[RutMaxAmountForPersBelow65Year] [money] NOT NULL,
	[RutMaxAmountForPersOver65Year] [money] NOT NULL,
	[RutReducedInvoicingPercent] [decimal](10, 4) NOT NULL,
	[AutoInvoiceInboundLatestSyncTime] [datetime2](7) NULL,
	[UseAsTemplate] [bit] NOT NULL,
	[TemplateDescription] [nvarchar](50) NULL,
	[ScanningFailEmail] [varchar](100) NULL,
	[AutoInvoiceScanningStatus] [int] NOT NULL,
	[OdpCompanyId] [bigint] NULL,
	[AutoInvoiceSendWithoutElectronicAddressActivatedDate] [datetime2](7) NULL,
	[Swish] [nvarchar](100) NULL,
	[Vipps] [nvarchar](100) NULL,
	[Mcash] [nvarchar](100) NULL,
	[MobilePay] [nvarchar](100) NULL,
	[UsesArticle] [bit] NOT NULL,
	[UsesUnit] [bit] NOT NULL,
	[UsesQuantity] [bit] NOT NULL,
	[UsesPrice] [bit] NOT NULL,
	[ShowLogotypeInEmail] [bit] NOT NULL,
	[AllowTransactionText] [bit] NULL,
	[EnvelopeType] [int] NOT NULL,
	[ShowPricesExclVatPC] [bit] NOT NULL,
	[HasAltinnCredentialsSet] [bit] NOT NULL,
	[BankgiroNumberPrint] [nvarchar](20) NULL,
	[ShowOrder] [bit] NOT NULL,
	[ShowQuote] [bit] NOT NULL,
	[UsesUnrestrictedInvoicePayments] [bit] NOT NULL,
	[ShowProject] [bit] NOT NULL,
	[HasDigipoortCertificateEnabled] [bit] NOT NULL,
	[DomesticCurrencyRounding] [int] NOT NULL,
	[SendVatReportToAuthority] [bit] NOT NULL,
	[Applications] [nvarchar](1024) NULL,
	[UsesDeferredPaymentSending] [bit] NOT NULL,
	[AutoinvoiceSIStatus] [int] NOT NULL,
	[LastEdiReceiverInfoNumber] [int] NOT NULL,
	[UsesSupplierInvoiceEdit] [bit] NOT NULL,
	[IsAgricultureCompany] [bit] NULL,
	[UsesAgricultureQuantity] [bit] NULL,
	[UsesAgricultureWeight] [bit] NULL,
	[UsesAgricultureDeliveryDate] [bit] NULL,
	[UsesAgricultureHarvestYear] [bit] NULL,
	[UsesVatReportApproval] [bit] NOT NULL,
	[IsInCollaboration] [bit] NOT NULL,
	[AllowEndUserToRecordPayment] [bit] NOT NULL,
	[UsesNewTaxReport] [bit] NOT NULL,
 CONSTRAINT [PK_Company] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CompanyBankAccount]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CompanyBankAccount](
	[Id] [uniqueidentifier] NOT NULL,
	[BankId] [uniqueidentifier] NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CurrencyCode] [nvarchar](3) NOT NULL,
	[BBAN] [nvarchar](35) NULL,
	[IBAN] [nvarchar](35) NULL,
	[BankAgreementStatus] [int] NOT NULL,
	[BankAccountType] [int] NOT NULL,
	[Name] [nvarchar](200) NOT NULL,
	[LastManualReconciliationDateUtc] [datetime2](7) NULL,
	[GlAccountNumber] [bigint] NOT NULL,
	[IsActive] [bit] NOT NULL,
	[FirstAccountStatementRecievedDateUtc] [datetime2](7) NULL,
	[BankAgreementStatusChangedAtUtc] [datetime2](7) NULL,
	[ModifiedUtc] [datetime2](7) NULL,
	[CreatedUtc] [datetime2](7) NULL,
	[TransactionFeeFixed] [money] NULL,
	[TransactionFeePercentage] [decimal](5, 4) NULL,
	[LastBankOpeningBalanceDate] [datetime2](7) NULL,
	[LastBankOpeningBalance] [money] NULL,
	[LastBankClosingBalance] [money] NULL,
	[LastBankClosingBalanceDate] [datetime2](7) NULL,
	[LastImportedTransactionDate] [datetime2](7) NULL,
	[LastImportedReference] [varchar](max) NULL,
	[LastImportedTransactionAmount] [money] NULL,
	[LastImportedBalance] [money] NULL,
	[BankAgreementVariant] [int] NOT NULL,
	[PendingIncomingBankMessages] [bit] NOT NULL,
	[IsDefaultChequeAccount] [bit] NOT NULL,
	[BankAccountHolderName] [varchar](100) NOT NULL,
	[NameEnglish] [varchar](200) NULL,
	[UsesAutopay] [bit] NOT NULL,
	[NextAutopayMessageOutId] [int] NOT NULL,
	[ForceAddNewAutopayAgreement] [bit] NOT NULL,
	[ManualServicesAddedAutopay] [bit] NOT NULL,
	[UseManualPayments] [bit] NOT NULL,
	[AutopayCustomerIdFromBank] [varchar](20) NULL,
	[ShowOnInvoicePrintout] [bit] NOT NULL,
	[AutopayMigrationStatus] [int] NOT NULL,
	[AutopayMigrationErrors] [int] NOT NULL,
	[AutopayMigrationLastError] [nvarchar](max) NULL,
	[ServiceCode] [nvarchar](20) NULL,
 CONSTRAINT [PK_CompanyBankAccount] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [UK_CompanyBankAccount_GlAccountNumber] UNIQUE NONCLUSTERED 
(
	[CompanyId] ASC,
	[GlAccountNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CompanyEvent]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CompanyEvent](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[Type] [int] NOT NULL,
	[Username] [nvarchar](256) NULL,
	[Message] [nvarchar](max) NULL,
 CONSTRAINT [PK_CompanyEvent] PRIMARY KEY NONCLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CompanyExtra]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CompanyExtra](
	[CompanyId] [uniqueidentifier] NOT NULL,
	[DowngradeReason] [nvarchar](2048) NULL,
 CONSTRAINT [PK_CompanyExtra] PRIMARY KEY CLUSTERED 
(
	[CompanyId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CompanyFlag]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CompanyFlag](
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Name] [nvarchar](255) NOT NULL,
	[Value] [bit] NOT NULL,
 CONSTRAINT [PK_CompanyFlag] PRIMARY KEY NONCLUSTERED 
(
	[CompanyId] ASC,
	[Name] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CompanyNumberSeries]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CompanyNumberSeries](
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CustomerInvoiceNumber] [int] NOT NULL,
	[IsCustomerInvoiceNumberLocked] [bit] NOT NULL,
	[JournalNumber] [int] NOT NULL,
	[OrderNumber] [int] NOT NULL,
	[QuoteNumber] [int] NOT NULL,
	[IsQuoteNumberLocked] [bit] NOT NULL,
	[QuickVoucherEntryNumber] [int] NOT NULL,
	[IsOrderNumberLocked] [bit] NOT NULL,
	[PaymentFileNumber] [int] NOT NULL,
	[EmployeeNumber] [int] NOT NULL,
	[WebshopAccountNumberForPayment] [bigint] NULL,
 CONSTRAINT [PK_CompanyNumberSeries] PRIMARY KEY CLUSTERED 
(
	[CompanyId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CompanyText]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CompanyText](
	[CompanyId] [uniqueidentifier] NOT NULL,
	[QuoteEmailDomestic] [nvarchar](2048) NULL,
	[QuoteEmailForeign] [nvarchar](2048) NULL,
	[InvoiceEmailDomestic] [nvarchar](2048) NULL,
	[InvoiceEmailForeign] [nvarchar](2048) NULL,
	[OverDueTextDomestic] [nvarchar](2048) NULL,
	[OverDueTextForeign] [nvarchar](2048) NULL,
	[OrderEmailDomestic] [nvarchar](2048) NULL,
	[OrderEmailForeign] [nvarchar](2048) NULL,
	[CustomerInvoiceTextDomestic] [nvarchar](200) NULL,
	[CustomerInvoiceTextForeign] [nvarchar](200) NULL,
	[QuoteTextDomestic] [nvarchar](200) NULL,
	[QuoteTextForeign] [nvarchar](200) NULL,
	[OrderTextDomestic] [nvarchar](200) NULL,
	[OrderTextForeign] [nvarchar](200) NULL,
	[CollectionInvoiceTextDomestic] [nvarchar](400) NULL,
	[CollectionInvoiceTextForeign] [nvarchar](400) NULL,
	[CollectionEmailTextDomestic] [nvarchar](2048) NULL,
	[CollectionEmailTextForeign] [nvarchar](2048) NULL,
	[ReminderInvoiceTextDomestic] [nvarchar](400) NULL,
	[ReminderInvoiceTextForeign] [nvarchar](400) NULL,
	[ReminderEmailTextDomestic] [nvarchar](2048) NULL,
	[ReminderEmailTextForeign] [nvarchar](2048) NULL,
	[AutoInvoiceActivationRequestEmailDomestic] [nvarchar](2048) NULL,
	[AutoInvoiceActivationRequestEmailForeign] [nvarchar](2048) NULL,
	[PayslipEmailTextDomestic] [nvarchar](2048) NULL,
 CONSTRAINT [PK_CompanyText] PRIMARY KEY CLUSTERED 
(
	[CompanyId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CompanyVoucherSeries]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CompanyVoucherSeries](
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Misc] [nchar](1) NOT NULL,
	[BankAndCash] [nchar](1) NOT NULL,
	[Customer] [nchar](1) NOT NULL,
	[Supplier] [nchar](1) NOT NULL,
	[Vat] [nchar](1) NOT NULL,
	[Payment] [nchar](1) NOT NULL,
	[Payout] [nchar](1) NOT NULL,
	[Corrections] [nchar](1) NOT NULL,
	[Inventory] [nchar](1) NOT NULL,
	[Salary] [nchar](1) NOT NULL,
	[EmployerReport] [nchar](1) NOT NULL,
 CONSTRAINT [PK_CompanyVoucherSeries] PRIMARY KEY CLUSTERED 
(
	[CompanyId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CostCenter]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CostCenter](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Name] [nvarchar](20) NULL,
	[Number] [int] NOT NULL,
	[IsActive] [bit] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
 CONSTRAINT [PK_CostCenter] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [IX_CostCenter] UNIQUE NONCLUSTERED 
(
	[CompanyId] ASC,
	[Number] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CostCenterItem]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CostCenterItem](
	[Id] [uniqueidentifier] NOT NULL,
	[CostCenterId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Name] [nvarchar](50) NULL,
	[ShortName] [nvarchar](9) NULL,
	[IsActive] [bit] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
 CONSTRAINT [PK_CostCenterItem] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Country]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Country](
	[Code] [nvarchar](2) NOT NULL,
 CONSTRAINT [PK_Country] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [UK_Country_Alpha2Code] UNIQUE NONCLUSTERED 
(
	[Code] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Currency]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Currency](
	[Code] [nvarchar](3) NOT NULL,
 CONSTRAINT [PK_Currency] PRIMARY KEY CLUSTERED 
(
	[Code] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Customer]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Customer](
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CorporateIdentityNumber] [nvarchar](20) NULL,
	[ContactPersonEmail] [nvarchar](255) NULL,
	[ContactPersonMobile] [nvarchar](50) NULL,
	[ContactPersonName] [nvarchar](100) NULL,
	[ContactPersonPhone] [nvarchar](50) NULL,
	[CurrencyCode] [nvarchar](3) NOT NULL,
	[CustomerId] [uniqueidentifier] NOT NULL,
	[CustomerNumber] [nvarchar](16) NOT NULL,
	[EanLocationNumber] [nvarchar](50) NULL,
	[EmailAddress] [nvarchar](255) NULL,
	[InvoiceAddress1] [nvarchar](50) NULL,
	[InvoiceAddress2] [nvarchar](50) NULL,
	[InvoicePostalCode] [nvarchar](10) NULL,
	[InvoiceCity] [nvarchar](50) NULL,
	[IsDeleted] [bit] NOT NULL,
	[Mobile] [nvarchar](50) NULL,
	[Name] [nvarchar](100) NULL,
	[Note] [nvarchar](4000) NULL,
	[ReverseChargeOnConstructionServices] [bit] NOT NULL,
	[Telephone] [nvarchar](50) NULL,
	[TermsOfPaymentId] [uniqueidentifier] NOT NULL,
	[VatNumber] [nvarchar](20) NULL,
	[WwwAddress] [nvarchar](255) NULL,
	[CreatedUtc] [datetime2](7) NULL,
	[InvoiceCountryCode] [nvarchar](2) NOT NULL,
	[WebShopCustomerNumber] [int] NULL,
	[InvoicePrintSetting] [int] NOT NULL,
	[ElectronicAddress] [nvarchar](255) NULL,
	[EdiServiceDelivererId] [nvarchar](255) NULL,
	[EdiGlnNumber] [nvarchar](255) NULL,
	[ForceBookkeepVat] [bit] NOT NULL,
	[ElectronicReference] [nvarchar](35) NULL,
	[ModifiedUtc] [datetime2](7) NULL,
	[LastInvoiceDate] [datetime2](7) NULL,
	[MobilePhone] [nvarchar](50) NULL,
	[DeliveryCustomerName] [nvarchar](100) NULL,
	[DeliveryAddress1] [nvarchar](50) NULL,
	[DeliveryAddress2] [nvarchar](50) NULL,
	[DeliveryPostalCode] [nvarchar](10) NULL,
	[DeliveryCity] [nvarchar](50) NULL,
	[DeliveryCountryCode] [nvarchar](2) NULL,
	[DeliveryMethodId] [uniqueidentifier] NULL,
	[DeliveryTermId] [uniqueidentifier] NULL,
	[IsPrivatePerson] [bit] NULL,
	[AutoInvoiceActivationEmailSentDate] [datetime2](7) NULL,
	[AutoInvoiceRegistrationRequestSentDate] [datetime2](7) NULL,
	[MdsSyncState] [int] NOT NULL,
	[UsesAutoInvoiceB2C] [bit] NOT NULL,
	[RequiresReferenceNumber] [bit] NOT NULL,
	[CompanyBankAccountId] [uniqueidentifier] NULL,
	[UsesAutoInvoiceB2B] [bit] NOT NULL,
	[InvoiceInEnglish] [bit] NOT NULL,
	[DiscountPercentage] [decimal](5, 4) NOT NULL,
	[SalesDocumentLanguage] [nvarchar](4) NULL,
 CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED 
(
	[CustomerId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [UK_Customer_CustomerNumber] UNIQUE NONCLUSTERED 
(
	[CustomerNumber] ASC,
	[CompanyId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CustomerEmailAddress]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CustomerEmailAddress](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CustomerId] [uniqueidentifier] NOT NULL,
	[EmailAddress] [nvarchar](255) NOT NULL,
 CONSTRAINT [PK_CustomerEmailAddress] PRIMARY KEY NONCLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CustomerInvoice]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CustomerInvoice](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[InvoiceNumber] [int] NOT NULL,
	[ReferringId] [uniqueidentifier] NULL,
	[ReferringInvoiceNumber] [nvarchar](50) NULL,
	[ReferringInvoiceDate] [datetime2](7) NULL,
	[CustomerId] [uniqueidentifier] NOT NULL,
	[CustomerNumber] [nvarchar](50) NOT NULL,
	[InvoiceCustomerName] [nvarchar](100) NULL,
	[InvoiceAddress1] [nvarchar](50) NULL,
	[InvoiceAddress2] [nvarchar](50) NULL,
	[InvoicePostalCode] [nvarchar](50) NULL,
	[InvoiceCity] [nvarchar](50) NULL,
	[CustomerCountry] [nvarchar](50) NULL,
	[CustomerVatNumber] [nvarchar](50) NULL,
	[CustomerReference] [nvarchar](100) NULL,
	[OcrNumber] [nvarchar](50) NULL,
	[TermsOfPaymentId] [uniqueidentifier] NOT NULL,
	[TotalAmount] [money] NOT NULL,
	[TotalAmountRoundings] [money] NOT NULL,
	[TotalAmountBaseCurrency] [money] NULL,
	[InvoiceDate] [datetime2](7) NULL,
	[DueDate] [datetime2](7) NULL,
	[PaymentDate] [datetime2](7) NULL,
	[Status] [int] NOT NULL,
	[RotReducedInvoicingAmount] [money] NOT NULL,
	[RotReducedInvoicingMaxAmount] [money] NOT NULL,
	[RotReducedInvoicingPercent] [money] NOT NULL,
	[RotReducedInvoicingNumber] [int] NOT NULL,
	[RotReducedInvoicingSSN] [nvarchar](100) NULL,
	[RotReducedInvoicingPropertyName] [nvarchar](100) NULL,
	[CurrencyCode] [nvarchar](3) NOT NULL,
	[CurrencyRate] [decimal](10, 4) NOT NULL,
	[CreatedByUserId] [uniqueidentifier] NULL,
	[EuThirdParty] [bit] NOT NULL,
	[LossStatus] [int] NOT NULL,
	[UsedCreditAmount] [money] NOT NULL,
	[ReversedConstructionVatInvoicing] [bit] NOT NULL,
	[IsDomestic] [bit] NOT NULL,
	[CompanyAddress] [nvarchar](50) NULL,
	[CompanyAddress2] [nvarchar](50) NULL,
	[CompanyCity] [nvarchar](50) NULL,
	[CompanyPostalCode] [nvarchar](50) NULL,
	[CompanyPhone] [nvarchar](50) NULL,
	[CompanyFax] [nvarchar](50) NULL,
	[CompanyVatCode] [nvarchar](50) NULL,
	[CompanyResidence] [nvarchar](80) NULL,
	[CompanyWeb] [nvarchar](255) NULL,
	[CompanyEmail] [nvarchar](255) NULL,
	[CompanyBankgiroNumber] [nvarchar](50) NULL,
	[CompanyPlusgiroNumber] [nvarchar](50) NULL,
	[CompanyBankName] [nvarchar](50) NULL,
	[CompanyIban] [nvarchar](50) NULL,
	[CompanyBIC] [nvarchar](50) NULL,
	[CompanyBban] [nvarchar](50) NULL,
	[HasFTaxCard] [bit] NULL,
	[CompanyCountryCode] [nvarchar](2) NOT NULL,
	[InvoiceCountryCode] [nvarchar](2) NOT NULL,
	[CreatedUtc] [datetime2](7) NULL,
	[CreatedFromWebshopOrderId] [uniqueidentifier] NULL,
	[CompanyName] [nvarchar](100) NOT NULL,
	[CorporateIdentityNumber] [nvarchar](100) NULL,
	[CustomerEmail] [nvarchar](255) NULL,
	[RemainingAmountBaseCurrency] [money] NOT NULL,
	[RemainingAmountInvoiceCurrency] [money] NOT NULL,
	[VoucherId] [uniqueidentifier] NOT NULL,
	[VatAmountBaseCurrency] [money] NOT NULL,
	[InvoiceText] [nvarchar](180) NULL,
	[ExternalOrderNumber] [int] NULL,
	[ExternalPaymentReference] [nvarchar](50) NULL,
	[EdiSendErrorMessage] [nvarchar](255) NULL,
	[ElectronicAddress] [nvarchar](255) NULL,
	[EdiServiceDelivererId] [nvarchar](255) NULL,
	[ElectronicReference] [nvarchar](255) NULL,
	[EdiLocalisationNumber] [nvarchar](255) NULL,
	[EdiFriendlyErrorMessage] [nvarchar](255) NULL,
	[AllowReSendElectronicInvoice] [bit] NOT NULL,
	[VatAmount] [money] NOT NULL,
	[RotReducedInvoicingType] [tinyint] NOT NULL,
	[RotReducedInvoicingExportId] [uniqueidentifier] NULL,
	[RotReducedInvoicingOrgNumber] [nvarchar](50) NULL,
	[ForceBookkeepVat] [bit] NOT NULL,
	[PrintSetting] [tinyint] NOT NULL,
	[DiscountId] [uniqueidentifier] NULL,
	[Category] [int] NOT NULL,
	[IsCreditInvoice] [bit] NOT NULL,
	[SetOffAmountBaseCurrency] [money] NOT NULL,
	[SetOffAmountInvoiceCurrency] [money] NOT NULL,
	[QuoteId] [uniqueidentifier] NULL,
	[RotReducedInvoicingAutomaticDistribution] [bit] NOT NULL,
	[OurReference] [nvarchar](100) NULL,
	[OrderId] [uniqueidentifier] NULL,
	[DeliveryCustomerName] [nvarchar](100) NULL,
	[DeliveryAddress1] [nvarchar](50) NULL,
	[DeliveryAddress2] [nvarchar](50) NULL,
	[DeliveryPostalCode] [nvarchar](10) NULL,
	[DeliveryCity] [nvarchar](50) NULL,
	[DeliveryCountryCode] [nvarchar](2) NULL,
	[DeliveryMethodName] [nvarchar](100) NULL,
	[DeliveryTermName] [nvarchar](100) NULL,
	[DeliveryMethodCode] [nvarchar](20) NULL,
	[DeliveryTermCode] [nvarchar](20) NULL,
	[CustomerIsPrivatePerson] [bit] NOT NULL,
	[ModifiedUtc] [datetime2](7) NOT NULL,
	[BookkeepingMethod] [int] NOT NULL,
	[RotPropertyType] [int] NULL,
	[WorkHouseOtherCosts] [decimal](9, 2) NULL,
	[IsQuickInvoice] [bit] NOT NULL,
	[CreatedFromDraftId] [uniqueidentifier] NULL,
	[DeliveryDate] [datetime2](7) NULL,
	[InvoiceBasisNumber] [bigint] NULL,
	[InvoiceBasisSource] [int] NOT NULL,
	[IncludesVat] [bit] NOT NULL,
	[EmailStatus] [int] NOT NULL,
	[DomesticCurrencyRounding] [int] NULL,
	[CustomerCcEmails] [varchar](1280) NULL,
	[UsesNewRounding] [bit] NOT NULL,
 CONSTRAINT [PK_CustomerInvoice] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CustomerInvoiceDocument]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CustomerInvoiceDocument](
	[CustomerInvoiceId] [uniqueidentifier] NOT NULL,
	[DocumentId] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_CustomerInvoiceDocument] PRIMARY KEY CLUSTERED 
(
	[CustomerInvoiceId] ASC,
	[DocumentId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CustomerInvoiceDraft]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CustomerInvoiceDraft](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CustomerId] [uniqueidentifier] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[ReferringInvoiceId] [uniqueidentifier] NULL,
	[RotReducedInvoicingType] [int] NOT NULL,
	[RotReducedInvoicingPropertyName] [nvarchar](50) NULL,
	[RotReducedInvoicingOrgNumber] [nvarchar](50) NULL,
	[RotReducedInvoicingAmount] [money] NOT NULL,
	[RotReducedInvoicingAutomaticDistribution] [bit] NOT NULL,
	[OurReference] [nvarchar](100) NULL,
	[CustomerReference] [nvarchar](100) NULL,
	[InvoiceCustomerName] [nvarchar](100) NULL,
	[InvoiceAddress1] [nvarchar](50) NULL,
	[InvoiceAddress2] [nvarchar](50) NULL,
	[InvoicePostalCode] [nvarchar](10) NULL,
	[InvoiceCity] [nvarchar](50) NULL,
	[InvoiceCountryCode] [nvarchar](2) NULL,
	[DeliveryCustomerName] [nvarchar](100) NULL,
	[DeliveryAddress1] [nvarchar](50) NULL,
	[DeliveryAddress2] [nvarchar](50) NULL,
	[DeliveryPostalCode] [nvarchar](10) NULL,
	[DeliveryCity] [nvarchar](50) NULL,
	[DeliveryCountryCode] [nvarchar](2) NULL,
	[DeliveryMethodName] [nvarchar](100) NULL,
	[DeliveryTermName] [nvarchar](100) NULL,
	[DeliveryMethodCode] [nvarchar](20) NULL,
	[DeliveryTermCode] [nvarchar](20) NULL,
	[EuThirdParty] [bit] NOT NULL,
	[CustomerIsPrivatePerson] [bit] NOT NULL,
	[ElectronicReference] [nvarchar](255) NULL,
	[RotPropertyType] [int] NULL,
	[WorkHouseOtherCosts] [decimal](9, 2) NULL,
	[IsCreditInvoice] [bit] NULL,
	[DeliveryDate] [datetime2](7) NULL,
	[InvoiceBasisNumber] [bigint] NULL,
	[InvoiceBasisSource] [int] NOT NULL,
	[IncludesVat] [bit] NOT NULL,
	[TermsOfPaymentId] [uniqueidentifier] NULL,
	[InvoiceDate] [datetime2](7) NULL,
	[UsesNewRounding] [bit] NOT NULL,
 CONSTRAINT [PK_CustomerInvoiceDraft_1] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CustomerInvoiceDraftPerson]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CustomerInvoiceDraftPerson](
	[Id] [uniqueidentifier] NOT NULL,
	[CustomerInvoiceDraftId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Ssn] [nvarchar](50) NOT NULL,
	[Amount] [money] NOT NULL,
 CONSTRAINT [PK_CustomerInvoiceDraftPerson] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CustomerInvoiceDraftRow]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CustomerInvoiceDraftRow](
	[Id] [uniqueidentifier] NOT NULL,
	[CustomerInvoiceDraftId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[ArticleId] [uniqueidentifier] NULL,
	[Text] [nvarchar](2000) NULL,
	[Quantity] [decimal](19, 4) NOT NULL,
	[UnitPrice] [money] NOT NULL,
	[DiscountPercentage] [decimal](5, 4) NOT NULL,
	[WorkCostType] [int] NOT NULL,
	[IsVatFree] [bit] NOT NULL,
	[LineNumber] [int] NOT NULL,
	[CostCenterItemId1] [uniqueidentifier] NULL,
	[CostCenterItemId2] [uniqueidentifier] NULL,
	[CostCenterItemId3] [uniqueidentifier] NULL,
	[IsWorkCost] [bit] NOT NULL,
	[WorkHours] [decimal](9, 2) NULL,
	[ProjectId] [uniqueidentifier] NULL,
	[MaterialCosts] [decimal](9, 2) NULL,
 CONSTRAINT [PK_CustomerInvoiceDraftRow_1] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CustomerInvoiceLatePaymentFee]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CustomerInvoiceLatePaymentFee](
	[Id] [uniqueidentifier] NOT NULL,
	[CustomerInvoiceId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Amount] [decimal](10, 4) NOT NULL,
	[Date] [datetime] NOT NULL,
 CONSTRAINT [PK_CustomerInvoiceLatePaymentFee] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CustomerInvoiceLog]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CustomerInvoiceLog](
	[Id] [uniqueidentifier] NOT NULL,
	[CustomerInvoiceId] [uniqueidentifier] NOT NULL,
	[SentEmail] [nvarchar](200) NULL,
	[SentType] [int] NOT NULL,
	[SentDate] [datetime] NOT NULL,
	[ReadCount] [int] NOT NULL,
	[ReadDateUtc] [datetime] NULL,
	[PdfLink] [nvarchar](200) NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[InvoiceDocumentType] [int] NOT NULL,
	[DocumentId] [uniqueidentifier] NULL,
	[LatePaymentFee] [decimal](10, 4) NULL,
	[DueDate] [datetime] NULL,
	[IsNotDelivered] [bit] NULL,
	[EmailStatus] [int] NOT NULL,
	[EmailMessage] [nvarchar](max) NULL,
	[EmailStatusDate] [datetime] NULL,
	[EmailLogId] [uniqueidentifier] NULL,
 CONSTRAINT [PK_CustomerInvoiceLog] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CustomerInvoicePersonRow]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CustomerInvoicePersonRow](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CustomerInvoiceId] [uniqueidentifier] NOT NULL,
	[Ssn] [nvarchar](50) NOT NULL,
	[ReductionAmount] [decimal](9, 4) NOT NULL,
 CONSTRAINT [PK_CustomerInvoicePersonRow] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CustomerInvoiceRow]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CustomerInvoiceRow](
	[Id] [uniqueidentifier] NOT NULL,
	[CustomerInvoiceId] [uniqueidentifier] NOT NULL,
	[LineNumber] [int] NOT NULL,
	[ArticleId] [uniqueidentifier] NULL,
	[ArticleNumber] [nvarchar](50) NULL,
	[ArticleName] [nvarchar](2000) NULL,
	[TotalAmountBaseCurrency] [money] NOT NULL,
	[Quantity] [decimal](19, 4) NOT NULL,
	[PricePerUnit] [money] NOT NULL,
	[PercentVat] [decimal](10, 4) NOT NULL,
	[UnitId] [uniqueidentifier] NULL,
	[UnitAbbreviation] [nvarchar](10) NULL,
	[WorkCostType] [int] NOT NULL,
	[VatFree] [bit] NOT NULL,
	[IsComment] [bit] NOT NULL,
	[DiscountPercentage] [decimal](5, 4) NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[FiscalYearId] [uniqueidentifier] NOT NULL,
	[SalesAccountNumber] [bigint] NULL,
	[UnitCode] [nvarchar](255) NULL,
	[IsCreatedFromOrder] [bit] NOT NULL,
	[VatAmountTransactionCurrency] [money] NOT NULL,
	[AmountNoVatTransactionCurrency] [money] NOT NULL,
	[CostCenterItemId1] [uniqueidentifier] NULL,
	[CostCenterItemId2] [uniqueidentifier] NULL,
	[CostCenterItemId3] [uniqueidentifier] NULL,
	[MossCode] [int] NULL,
	[IsWorkCost] [bit] NOT NULL,
	[WorkHours] [decimal](9, 2) NULL,
	[ProjectId] [uniqueidentifier] NULL,
	[MaterialCosts] [decimal](9, 2) NULL,
	[UnitAbbreviationEnglish] [nvarchar](500) NULL,
	[IsServiceArticle] [bit] NOT NULL,
 CONSTRAINT [PK_CustomerInvoiceRow] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CustomerInvoiceValuationHistory]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CustomerInvoiceValuationHistory](
	[Id] [uniqueidentifier] NOT NULL,
	[CustomerInvoiceId] [uniqueidentifier] NOT NULL,
	[VoucherId] [uniqueidentifier] NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[ValueDate] [datetime2](7) NOT NULL,
	[InvoiceCurrencyCode] [nvarchar](3) NOT NULL,
	[BaseCurrencyCode] [nvarchar](3) NOT NULL,
	[ValueChangeInvoiceCurrency] [money] NOT NULL,
	[ValueChangeBaseCurrency] [money] NOT NULL,
	[RemainingAmountInvoiceCurrency] [money] NOT NULL,
	[RemainingAmountBaseCurrency] [money] NULL,
	[ValuationType] [int] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[BankTransactionId] [uniqueidentifier] NULL,
	[ReverseVoucherId] [uniqueidentifier] SPARSE  NULL,
	[BankBusinessTransactionId] [uniqueidentifier] SPARSE  NULL,
 CONSTRAINT [PK_CustomerInvoiceValuationHistory] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CustomerLabel]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CustomerLabel](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
	[Description] [nvarchar](400) NULL,
 CONSTRAINT [PK_CustomerLabel] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CustomerToCustomerLabel]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CustomerToCustomerLabel](
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CustomerId] [uniqueidentifier] NOT NULL,
	[CustomerLabelId] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_CustomerToCustomerLabel] PRIMARY KEY CLUSTERED 
(
	[CompanyId] ASC,
	[CustomerId] ASC,
	[CustomerLabelId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[DeliveryMethod]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DeliveryMethod](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Code] [nvarchar](20) NULL,
	[Name] [nvarchar](100) NULL,
	[NameEnglish] [varchar](200) NULL,
 CONSTRAINT [PK_DeliveryMethod] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[DeliveryTerm]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DeliveryTerm](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Code] [nvarchar](20) NULL,
	[Name] [nvarchar](100) NULL,
	[Editable] [bit] NOT NULL,
	[NameEnglish] [varchar](200) NULL,
 CONSTRAINT [PK_DeliveryTerm] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[DevPhotoMetadataDto]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DevPhotoMetadataDto](
	[PhotoServiceId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[UserId] [uniqueidentifier] NOT NULL,
	[ImageData] [varbinary](max) NULL,
	[ImageMimeType] [nvarchar](50) NULL,
	[PhotoStatus] [int] NULL,
	[PhotoType] [int] NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[UserDate] [datetime2](7) NOT NULL,
	[FileName] [nvarchar](100) NULL,
	[Currency] [nvarchar](6) NULL,
 CONSTRAINT [PK_DevPhotoMetadataDto] PRIMARY KEY CLUSTERED 
(
	[PhotoServiceId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Discount]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Discount](
	[Id] [uniqueidentifier] NOT NULL,
	[Amount] [money] NOT NULL,
	[VatAmount] [money] NOT NULL,
	[Percentage] [decimal](10, 4) NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_DiscountSpecification] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[DiscountLine]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DiscountLine](
	[Id] [uniqueidentifier] NOT NULL,
	[DiscountId] [uniqueidentifier] NOT NULL,
	[Amount] [money] NOT NULL,
	[VatAmount] [money] NOT NULL,
	[Text] [nvarchar](150) NULL,
	[VatPercentage] [decimal](10, 4) NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_DiscountLine] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Document]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Document](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Uri] [nvarchar](512) NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[Name] [nvarchar](256) NULL,
	[Size] [int] NULL,
	[Type] [int] NOT NULL,
	[Format] [int] NOT NULL,
	[VismaStorageId] [uniqueidentifier] NULL,
	[ContentType] [varchar](100) NULL,
 CONSTRAINT [PK_Document] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[DocumentApprovalEvent]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DocumentApprovalEvent](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[DocumentId] [uniqueidentifier] NOT NULL,
	[DocumentApprovalStatus] [int] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[CreatedByUserId] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_DocumentApprovalEvent] PRIMARY KEY CLUSTERED 
(
	[CompanyId] ASC,
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[EmployerReport]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EmployerReport](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[ReportYear] [int] NOT NULL,
	[ReportMonth] [int] NOT NULL,
	[Name] [nvarchar](100) NOT NULL,
	[CountryCode] [nvarchar](2) NULL,
	[IsRegretted] [bit] NOT NULL,
	[VoucherId] [uniqueidentifier] NULL,
	[LatestFileCreated] [datetime2](7) NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[PeriodEndDate] [datetime2](7) NOT NULL,
	[PeriodStartDate] [datetime2](7) NOT NULL,
	[NameEnglish] [varchar](200) NULL,
	[UsesNewTaxReport] [bit] NOT NULL,
	[Firstname] [nvarchar](100) NULL,
	[Lastname] [nvarchar](100) NULL,
	[PhoneNumber] [nvarchar](50) NULL,
	[Email] [nvarchar](50) NULL,
 CONSTRAINT [PK_EmployerReport] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[EntityAssociation]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EntityAssociation](
	[Entity1Id] [uniqueidentifier] NOT NULL,
	[Entity2Id] [uniqueidentifier] NOT NULL,
	[Entity1Type] [int] NOT NULL,
	[Entity2Type] [int] NOT NULL,
	[AssociationType] [int] NOT NULL,
	[Date] [datetime2](7) NULL,
 CONSTRAINT [PK_EntityAssociation] PRIMARY KEY CLUSTERED 
(
	[Entity1Id] ASC,
	[Entity2Id] ASC,
	[AssociationType] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[ExportJOU]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ExportJOU](
	[CompanyID] [uniqueidentifier] NOT NULL,
	[LastExportDateUtc] [datetime2](7) NULL,
	[LastInvoiceNumber] [int] NOT NULL,
	[VatFile] [nvarchar](max) NULL,
	[VatFileDescription] [nvarchar](100) NULL,
	[VismaBusinessClientId] [int] NULL,
	[Format] [nvarchar](20) NOT NULL,
 CONSTRAINT [PK_ExportJOU] PRIMARY KEY CLUSTERED 
(
	[CompanyID] ASC,
	[Format] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[ExportRotRut]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ExportRotRut](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[ExportNumber] [int] NOT NULL,
	[ExportFile] [nvarchar](max) NOT NULL,
	[CreatedUTC] [datetime2](7) NOT NULL,
	[FileType] [int] NOT NULL,
 CONSTRAINT [PK_ExportRotRut] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [UC_ExportNumber_CompanyId] UNIQUE NONCLUSTERED 
(
	[CompanyId] ASC,
	[ExportNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[FiscalYear]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FiscalYear](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[StartDate] [datetime2](7) NOT NULL,
	[EndDate] [datetime2](7) NOT NULL,
	[ChartOfAccountsInfoId] [uniqueidentifier] NOT NULL,
	[CreatedByUserId] [uniqueidentifier] NOT NULL,
	[CreatedUtc] [datetime2](7) NULL,
	[AccountsModifiedTicksUtc] [bigint] NOT NULL,
	[IsChecklistCompleted] [bit] NOT NULL,
	[BookkeepingMethod] [int] NOT NULL,
	[IsLockedForAccounting] [bit] NOT NULL,
 CONSTRAINT [PK_FiscalYear] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[FiscalYearCheckListItem]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FiscalYearCheckListItem](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[FiscalYearId] [uniqueidentifier] NOT NULL,
	[CheckListItemType] [int] NOT NULL,
	[CheckListItemGroup] [int] NOT NULL,
	[Completed] [bit] NOT NULL,
	[DependentOnId] [uniqueidentifier] NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[CreatedByUserId] [uniqueidentifier] NOT NULL,
	[ModifiedUtc] [datetime2](7) NOT NULL,
	[ModifiedByUserId] [uniqueidentifier] NOT NULL,
	[SubGroupName] [nvarchar](200) NULL,
	[Hash] [char](32) NULL,
	[ModifiedByUserName] [nvarchar](256) NULL,
 CONSTRAINT [PK_FiscalYearCheckListItem] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[FiscalYearNumberSeries]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FiscalYearNumberSeries](
	[FiscalYearId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[VoucherNumberA] [int] NOT NULL,
	[VoucherNumberB] [int] NOT NULL,
	[VoucherNumberC] [int] NOT NULL,
	[VoucherNumberD] [int] NOT NULL,
	[VoucherNumberE] [int] NOT NULL,
	[VoucherNumberF] [int] NOT NULL,
	[VoucherNumberG] [int] NOT NULL,
	[VoucherNumberH] [int] NOT NULL,
	[VoucherNumberI] [int] NOT NULL,
	[VoucherNumberJ] [int] NOT NULL,
	[VoucherNumberK] [int] NOT NULL,
	[VoucherNumberL] [int] NOT NULL,
	[VoucherNumberM] [int] NOT NULL,
	[VoucherNumberN] [int] NOT NULL,
	[VoucherNumberO] [int] NOT NULL,
	[VoucherNumberP] [int] NOT NULL,
	[VoucherNumberQ] [int] NOT NULL,
	[VoucherNumberR] [int] NOT NULL,
	[VoucherNumberS] [int] NOT NULL,
	[VoucherNumberT] [int] NOT NULL,
	[VoucherNumberU] [int] NOT NULL,
	[VoucherNumberV] [int] NOT NULL,
	[VoucherNumberW] [int] NOT NULL,
	[VoucherNumberX] [int] NOT NULL,
	[VoucherNumberY] [int] NOT NULL,
	[VoucherNumberZ] [int] NOT NULL,
 CONSTRAINT [PK_FiscalYearNumberSeries] PRIMARY KEY CLUSTERED 
(
	[FiscalYearId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[ForeignPaymentCode]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ForeignPaymentCode](
	[Id] [uniqueidentifier] NOT NULL,
	[Code] [int] NOT NULL,
	[Description] [nvarchar](400) NOT NULL,
	[CountryCode] [nvarchar](2) NOT NULL,
 CONSTRAINT [PK_ForeignPaymentCode] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[ImportStatus]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ImportStatus](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Type] [int] NOT NULL,
 CONSTRAINT [PK_ImportStatus_1] PRIMARY KEY CLUSTERED 
(
	[CompanyId] ASC,
	[Type] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[InventoryAccountingTemplate]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[InventoryAccountingTemplate](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Active] [bit] NOT NULL,
	[Name] [varchar](200) NOT NULL,
	[InventoryAccountNumber] [bigint] NOT NULL,
	[DepreciationAssetAccountNumber] [bigint] NULL,
	[DepreciationResultAccountNumber] [bigint] NULL,
	[CapitalGainAccountNumber] [bigint] NOT NULL,
	[CapitalLossAccountNumber] [bigint] NOT NULL,
	[NoDepreciations] [bit] NOT NULL,
	[TaxationDepreciation] [varchar](50) NULL,
	[IsCustom] [bit] NOT NULL,
	[NameEnglish] [varchar](200) NULL,
 CONSTRAINT [PK_InventoryAccoutingTemplate] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[InventoryEvent]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[InventoryEvent](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[VoucherId] [uniqueidentifier] NULL,
	[UndoVoucherId] [uniqueidentifier] NULL,
	[InventoryItemId] [uniqueidentifier] NOT NULL,
	[Type] [int] NOT NULL,
	[Amount] [money] NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[Undone] [bit] NOT NULL,
	[BookkeepingDate] [datetime2](7) NULL,
	[UndoBookkeepingDate] [datetime2](7) NULL,
	[CurrentValueBeforeEvent] [money] NOT NULL,
 CONSTRAINT [PK_InventoryEvent] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[InventoryItem]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[InventoryItem](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Number] [int] NOT NULL,
	[Name] [varchar](200) NOT NULL,
	[PurchasePrice] [money] NOT NULL,
	[PurchaseDate] [datetime] NOT NULL,
	[InventoryItemStatus] [int] NOT NULL,
	[Depreciate] [bit] NULL,
	[LifeSpanInMonths] [int] NULL,
	[FirstDepreciationDate] [datetime] NULL,
	[LatestDepreciationDate] [datetime] NULL,
	[ResidualValue] [money] NULL,
	[CostCenterItemId1] [uniqueidentifier] NULL,
	[CostCenterItemId2] [uniqueidentifier] NULL,
	[CostCenterItemId3] [uniqueidentifier] NULL,
	[InventoryAccountingTemplateId] [uniqueidentifier] NOT NULL,
	[CurrentValue] [money] NOT NULL,
	[DepreciationStartType] [int] NOT NULL,
	[ProjectId] [uniqueidentifier] NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[ModifiedUtc] [datetime2](7) NOT NULL,
 CONSTRAINT [PK_InventoryItem] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[IZettleFinanceTransaction]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IZettleFinanceTransaction](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Amount] [money] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[IZettleTimestamp] [datetime2](7) NOT NULL,
	[TransactionType] [int] NOT NULL,
	[OriginatingPurchaseId] [uniqueidentifier] NOT NULL,
	[VoucherId] [uniqueidentifier] NULL,
 CONSTRAINT [PK_IZettleFinanceTransaction] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[IZettleIntegration]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IZettleIntegration](
	[CompanyId] [uniqueidentifier] NOT NULL,
	[AuthorizationState] [uniqueidentifier] NOT NULL,
	[AuthorizationStateCreatedUtc] [datetime2](7) NOT NULL,
	[AuthorizationStateConfirmedUtc] [datetime2](7) NULL,
	[LastPurchaseHash] [nvarchar](200) NULL,
	[LastFinanceTransactionSyncDate] [datetime2](7) NULL,
	[RefreshToken] [nvarchar](200) NULL,
	[AccessToken] [nvarchar](2000) NULL,
	[AccessTokenExpireTime] [datetime2](7) NULL,
	[IsActive] [bit] NOT NULL,
	[LastPurchaseSyncUtc] [datetime2](7) NULL,
	[IZettleSalesGlAccountHighVat] [bigint] NULL,
	[IZettleSalesGlAccountMiddleVat] [bigint] NULL,
	[IZettleSalesGlAccountLowVat] [bigint] NULL,
	[IZettleClaimOnCardAcquiererGlAccount] [bigint] NULL,
	[IZettleSalesGlAccountNoVat] [bigint] NULL,
	[IZettleCardTransactionFeeGlAccount] [bigint] NULL,
	[ModifiedUtc] [datetime2](7) NULL,
	[ReActivateIntegration] [bit] NOT NULL,
	[IZettleCardTransactionGratuityAmountAccount] [bigint] NULL,
 CONSTRAINT [PK_IZettleIntegration] PRIMARY KEY CLUSTERED 
(
	[CompanyId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[IZettlePurchase]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IZettlePurchase](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[TotalAmount] [money] NOT NULL,
	[VatAmount] [money] NOT NULL,
	[CurrencyCode] [nvarchar](3) NOT NULL,
	[CardPaymentAmount] [money] NOT NULL,
	[CashPaymentAmount] [money] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[IZettleTimestamp] [datetime2](7) NOT NULL,
	[VoucherId] [uniqueidentifier] NULL,
	[PurchaseNumber] [int] NULL,
	[Refunded] [bit] NOT NULL,
	[Refund] [bit] NOT NULL,
	[IZettlePurchaseId] [uniqueidentifier] NULL,
	[SwishPaymentAmount] [money] NOT NULL,
	[VippsPaymentAmount] [money] NOT NULL,
	[IZettleInvoicePaymentAmount] [money] NOT NULL,
	[GratuityAmount] [money] NOT NULL,
 CONSTRAINT [PK_IZettlePurchase] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[IZettlePurchaseRow]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IZettlePurchaseRow](
	[Id] [uniqueidentifier] NOT NULL,
	[IZettleProductId] [bigint] NOT NULL,
	[IZettlePurchaseId] [uniqueidentifier] NOT NULL,
	[Quantity] [decimal](19, 4) NOT NULL,
	[UnitPrice] [money] NOT NULL,
	[VatPercent] [decimal](19, 4) NOT NULL,
	[TransactionText] [nvarchar](100) NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_IZettlePurchaseRow] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[JournalEntry]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[JournalEntry](
	[Id] [uniqueidentifier] NOT NULL,
	[CreatedUtc] [datetime2](7) NULL,
	[Message] [nvarchar](512) NOT NULL,
	[Username] [nvarchar](256) NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Number] [int] NOT NULL,
	[JournalEntryType] [int] NOT NULL,
 CONSTRAINT [PK_JournalEntry] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Message]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Message](
	[Id] [uniqueidentifier] NOT NULL,
	[MessageThreadId] [uniqueidentifier] NOT NULL,
	[CreatedByUserId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[MessageText] [nvarchar](256) NOT NULL,
	[Type] [int] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[StartDate] [datetime2](7) NULL,
	[EndDate] [datetime2](7) NULL,
	[IsEditByOther] [bit] NOT NULL,
	[ModifiedUtc] [datetime2](7) NOT NULL,
	[Created] [datetime] NULL,
	[ModifiedByUserId] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_Message] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[MessageReceiver]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MessageReceiver](
	[Id] [uniqueidentifier] NOT NULL,
	[MessageThreadId] [uniqueidentifier] NOT NULL,
	[UserId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Status] [int] NOT NULL,
 CONSTRAINT [PK_MessageReceiver] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[MessageThread]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MessageThread](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[DocumentType] [int] NULL,
	[DocumentId] [uniqueidentifier] NULL,
	[DocumentNumber] [nvarchar](200) NULL,
	[Subject] [varchar](40) NOT NULL,
	[ModifiedUtc] [datetime2](7) NOT NULL,
	[CreatedByAppUtc] [bigint] NOT NULL,
	[ModifiedByAppUtc] [bigint] NOT NULL,
	[ShowInMainList] [bit] NOT NULL,
	[IsDeleted] [bit] NOT NULL,
	[IsConvertedFromOldApp] [bit] NOT NULL,
	[Created] [datetime] NULL,
	[Modified] [datetime2](7) NOT NULL,
	[IsClose] [bit] NOT NULL,
 CONSTRAINT [PK_MessageThread] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[MobileDevice]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MobileDevice](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[UserId] [uniqueidentifier] NOT NULL,
	[DeviceTokenApple] [varchar](128) NOT NULL,
	[DisabledForPush] [varchar](256) NULL,
	[LastMessageCheckUtc] [datetime2](7) NULL,
	[ModifiedUtc] [datetime2](7) NOT NULL,
 CONSTRAINT [PK_MobileDevice] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[MobileEmployeePendingUpdate]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MobileEmployeePendingUpdate](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[OnlineEmployeeId] [uniqueidentifier] NOT NULL,
	[EmpManEmployeeId] [uniqueidentifier] NOT NULL,
	[Firstname] [nvarchar](50) NOT NULL,
	[Lastname] [nvarchar](50) NOT NULL,
	[Email] [nvarchar](255) NOT NULL,
	[IsSynced] [bit] NOT NULL,
 CONSTRAINT [PK_MobileEmployeePendingUpdate] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[MossCode]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MossCode](
	[Id] [uniqueidentifier] NOT NULL,
	[CountryCode] [nvarchar](2) NOT NULL,
	[Code] [int] NULL,
 CONSTRAINT [PK_MossCode] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[NifImportHistory]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NifImportHistory](
	[Id] [uniqueidentifier] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[FiscalYearId] [uniqueidentifier] NOT NULL,
	[VoucherId] [uniqueidentifier] NOT NULL,
	[ExternalId] [int] NOT NULL,
 CONSTRAINT [PK_NifImportHistory] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[NifImportSettings]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NifImportSettings](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[NifOrganisationId] [int] NOT NULL,
	[NifOrganisationName] [nvarchar](50) NULL,
	[CostCenterItemId1] [uniqueidentifier] NULL,
	[CostCenterItemId2] [uniqueidentifier] NULL,
	[CostCenterItemId3] [uniqueidentifier] NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[ModifiedUtc] [datetime2](7) NOT NULL,
	[FetchPayment] [bit] NOT NULL,
	[IsClub] [bit] NOT NULL,
 CONSTRAINT [PK_NifImportSettings] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[NifIntegration]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NifIntegration](
	[CompanyId] [uniqueidentifier] NOT NULL,
	[NifOrganisationId] [int] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[ModifiedUtc] [datetime2](7) NOT NULL,
	[ActivationKey] [nvarchar](50) NOT NULL,
	[ActivationEmail] [nvarchar](255) NOT NULL,
	[IsConfirmed] [bit] NOT NULL,
	[ConfirmedUtc] [datetime2](7) NULL,
	[ActivationRequestedByUserId] [uniqueidentifier] NOT NULL,
	[Username] [nvarchar](32) NULL,
	[Password] [nvarchar](32) NULL,
	[FunctionId] [int] NULL,
 CONSTRAINT [PK_NifIntegration] PRIMARY KEY CLUSTERED 
(
	[CompanyId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Note]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Note](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[UserId] [uniqueidentifier] NOT NULL,
	[AttachedTo] [uniqueidentifier] NULL,
	[Text] [nvarchar](256) NOT NULL,
	[IsDeleted] [bit] NOT NULL,
	[CreatedByAppUtc] [bigint] NOT NULL,
	[ModifiedByAppUtc] [bigint] NOT NULL,
	[ShowInMainList] [bit] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[ModifiedUtc] [datetime2](7) NOT NULL,
 CONSTRAINT [PK_Note] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Notification]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Notification](
	[Id] [uniqueidentifier] NOT NULL,
	[UserId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Type] [int] NOT NULL,
	[Created] [datetime] NOT NULL,
	[Sent] [datetime] NULL,
 CONSTRAINT [PK_Notification] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[NotificationArgument]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NotificationArgument](
	[Id] [uniqueidentifier] NOT NULL,
	[NotificationId] [uniqueidentifier] NOT NULL,
	[Value] [nvarchar](50) NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Type] [nvarchar](50) NULL,
	[IsDate] [bit] NOT NULL,
 CONSTRAINT [PK_NotificationArgument] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[OcrGiroAmountRecord]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[OcrGiroAmountRecord](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CompanyBankAccountId] [uniqueidentifier] NOT NULL,
	[BankTransactionId] [uniqueidentifier] NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[Type] [int] NOT NULL,
	[Amount] [money] NOT NULL,
	[Date] [datetime2](7) NOT NULL,
	[Kid] [nvarchar](25) NULL,
	[Message] [nvarchar](40) NULL,
	[ArkReference] [nvarchar](10) NOT NULL,
	[Status] [int] NOT NULL,
 CONSTRAINT [PK_OcrGiroAmountRecord] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Order]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Order](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CustomerId] [uniqueidentifier] NOT NULL,
	[DeliveryMethodName] [nvarchar](100) NULL,
	[DeliveryTermName] [nvarchar](100) NULL,
	[Status] [int] NOT NULL,
	[Number] [int] NULL,
	[OrderDate] [datetime2](7) NOT NULL,
	[DeliveryDate] [datetime2](7) NULL,
	[ShippedDateTime] [datetime2](7) NULL,
	[Amount] [money] NOT NULL,
	[VatAmount] [money] NOT NULL,
	[RoundingsAmount] [money] NOT NULL,
	[DeliveredAmount] [money] NOT NULL,
	[DeliveredVatAmount] [money] NOT NULL,
	[DeliveredRoundingsAmount] [money] NOT NULL,
	[CurrencyCode] [nvarchar](3) NOT NULL,
	[CurrencyRate] [decimal](10, 4) NOT NULL,
	[CustomerReference] [nvarchar](100) NULL,
	[CompanyReference] [nvarchar](100) NULL,
	[HouseWorkType] [int] NULL,
	[HouseWorkPropertyName] [nvarchar](100) NULL,
	[HouseWorkCorporateIdentityNumber] [nvarchar](20) NULL,
	[HouseWorkAmount] [money] NOT NULL,
	[HouseWorkAutomaticDistribution] [bit] NOT NULL,
	[OriginatingOrderId] [uniqueidentifier] NULL,
	[OriginatingQuoteId] [uniqueidentifier] NULL,
	[InvoiceCustomerName] [nvarchar](100) NOT NULL,
	[InvoiceAddress1] [nvarchar](50) NULL,
	[InvoiceAddress2] [nvarchar](50) NULL,
	[InvoicePostalCode] [nvarchar](10) NULL,
	[InvoiceCity] [nvarchar](50) NULL,
	[InvoiceCountryCode] [nvarchar](2) NOT NULL,
	[DeliveryCustomerName] [nvarchar](100) NULL,
	[DeliveryAddress1] [nvarchar](50) NULL,
	[DeliveryAddress2] [nvarchar](50) NULL,
	[DeliveryPostalCode] [nvarchar](10) NULL,
	[DeliveryCity] [nvarchar](50) NULL,
	[DeliveryCountryCode] [nvarchar](2) NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[DeliveryMethodCode] [nvarchar](20) NULL,
	[DeliveryTermCode] [nvarchar](20) NULL,
	[EuThirdParty] [bit] NOT NULL,
	[CustomerIsPrivatePerson] [bit] NOT NULL,
	[PrintSetting] [tinyint] NOT NULL,
	[ForceBookkeepVat] [bit] NOT NULL,
	[CustomerVatNumber] [nvarchar](20) NULL,
	[RotPropertyType] [int] NULL,
	[TermsOfPaymentId] [uniqueidentifier] NOT NULL,
	[IncludesVat] [bit] NOT NULL,
	[EmailStatus] [int] NOT NULL,
	[ModifiedUtc] [datetime2](7) NULL,
	[UsesNewRounding] [bit] NOT NULL,
 CONSTRAINT [PK_Order] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[OrderLog]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[OrderLog](
	[Id] [uniqueidentifier] NOT NULL,
	[OrderId] [uniqueidentifier] NOT NULL,
	[SentEmail] [nvarchar](200) NULL,
	[SentType] [int] NOT NULL,
	[SentDate] [datetime] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[ReadCount] [int] NOT NULL,
	[EmailStatus] [int] NOT NULL,
	[EmailMessage] [nvarchar](max) NULL,
	[EmailStatusDate] [datetime] NULL,
	[IsNotDelivered] [bit] NULL,
	[EventType] [int] NOT NULL,
	[EmailLogId] [uniqueidentifier] NULL,
 CONSTRAINT [PK_OrderLog] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[OrderPerson]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[OrderPerson](
	[Id] [uniqueidentifier] NOT NULL,
	[OrderId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Ssn] [nvarchar](50) NOT NULL,
	[Amount] [money] NOT NULL,
 CONSTRAINT [PK_OrderPerson] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[OrderRow]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[OrderRow](
	[Id] [uniqueidentifier] NOT NULL,
	[OrderId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[LineNumber] [int] NOT NULL,
	[Text] [nvarchar](2000) NULL,
	[Quantity] [decimal](19, 4) NOT NULL,
	[DeliveredQuantity] [decimal](19, 4) NOT NULL,
	[UnitPrice] [money] NOT NULL,
	[DiscountPercentage] [decimal](5, 4) NOT NULL,
	[WorkCostType] [int] NOT NULL,
	[IsVatFree] [bit] NOT NULL,
	[ArticleId] [uniqueidentifier] NULL,
	[CostCenterItemId1] [uniqueidentifier] NULL,
	[CostCenterItemId2] [uniqueidentifier] NULL,
	[CostCenterItemId3] [uniqueidentifier] NULL,
	[IsWorkCost] [bit] NOT NULL,
	[WorkHours] [decimal](9, 2) NULL,
	[ProjectId] [uniqueidentifier] NULL,
	[MaterialCosts] [decimal](9, 2) NULL,
 CONSTRAINT [PK_OrderRow] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[PartnerResourceLink]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PartnerResourceLink](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[ResourceId] [uniqueidentifier] NOT NULL,
	[PartnerSystemName] [nvarchar](100) NULL,
	[PartnerCompanyName] [nvarchar](100) NULL,
	[Href] [nvarchar](256) NULL,
	[OAuth2ClientId] [nvarchar](100) NULL,
	[ResourceType] [int] NOT NULL,
 CONSTRAINT [PK_PartnerResourceLink] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [UQ_ResourceIdOAuthClientId] UNIQUE NONCLUSTERED 
(
	[ResourceId] ASC,
	[OAuth2ClientId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Payment]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Payment](
	[Id] [uniqueidentifier] NOT NULL,
	[SupplierInvoiceId] [uniqueidentifier] NOT NULL,
	[SenderGiroNumber] [nvarchar](10) NULL,
	[SenderGiroType] [int] NOT NULL,
	[SenderBban] [nvarchar](35) NOT NULL,
	[SenderCountryCode] [nvarchar](2) NOT NULL,
	[SenderReference] [nvarchar](20) NULL,
	[SenderBankId] [uniqueidentifier] NOT NULL,
	[Amount] [money] NOT NULL,
	[AmountCurrencyCode] [nvarchar](3) NOT NULL,
	[BeneficiaryBic] [nvarchar](11) NULL,
	[BeneficiaryIban] [nvarchar](35) NULL,
	[BeneficiaryGiroNumber] [nvarchar](10) NULL,
	[BeneficiaryGiroType] [int] NOT NULL,
	[BeneficiaryId] [int] NOT NULL,
	[BeneficiaryName1] [nvarchar](30) NOT NULL,
	[BeneficiaryName2] [nvarchar](35) NULL,
	[BeneficiaryAdress1] [nvarchar](30) NULL,
	[BeneficiaryAdress2] [nvarchar](35) NULL,
	[BeneficiaryCountryCode] [nvarchar](2) NULL,
	[FeeAllocationType] [int] NOT NULL,
	[Reference] [nvarchar](25) NULL,
	[PaymentCode] [int] NULL,
	[Status] [int] NOT NULL,
	[StatusMessage] [nvarchar](256) NULL,
	[CreatedUtc] [datetime2](7) NULL,
	[ModifiedUtc] [datetime2](7) NULL,
	[DateOfPayment] [datetime2](7) NULL,
	[IsDomestic] [bit] NOT NULL,
	[IsCreditNote] [bit] NOT NULL,
	[BeneficiaryBankCode] [nvarchar](24) NULL,
	[BeneficiaryBban] [nvarchar](35) NULL,
	[SenderIban] [nvarchar](35) NULL,
	[PaymentCodeDescription] [nvarchar](400) NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[BeneficiaryPostalCode] [nvarchar](50) NULL,
	[BeneficiaryCity] [nvarchar](50) NULL,
	[PaymentType] [int] NOT NULL,
	[PaymentFileId] [uniqueidentifier] NULL,
	[BankMessageId] [uniqueidentifier] NULL,
	[BankAgreementVariant] [int] NOT NULL,
	[BeneficiaryBankName] [nvarchar](50) NULL,
	[SenderServiceCode] [nvarchar](20) NULL,
	[PaymentBatchId] [uniqueidentifier] NULL,
 CONSTRAINT [PK_Payment] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [UK_Payment_SupplierInvoiceId] UNIQUE NONCLUSTERED 
(
	[SupplierInvoiceId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[PaymentBatch]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PaymentBatch](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[ModifiedUtc] [datetime2](7) NOT NULL,
	[Status] [int] NOT NULL,
	[LatestBankMessageId] [uniqueidentifier] NULL,
 CONSTRAINT [PK_PaymentBatch] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[PaymentFile]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PaymentFile](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[FileNumber] [int] NOT NULL,
	[Content] [nvarchar](max) NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[CreatedByUserId] [uniqueidentifier] NOT NULL,
	[HashType] [nvarchar](20) NULL,
	[HashValue] [varbinary](32) NULL,
 CONSTRAINT [PK_PaymentFile] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[PayrollAnnualTaxReport]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PayrollAnnualTaxReport](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Year] [int] NOT NULL,
	[Firstname] [nvarchar](100) NOT NULL,
	[PhoneNumber] [nvarchar](50) NOT NULL,
	[Email] [nvarchar](50) NOT NULL,
	[CreatedUTC] [datetime2](7) NOT NULL,
	[Status] [int] NOT NULL,
	[Lastname] [nvarchar](100) NOT NULL,
	[PrintedUtc] [datetime2](7) NULL,
 CONSTRAINT [PK_PayrollAnnualTaxReport] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [UQ_CompanyYear] UNIQUE NONCLUSTERED 
(
	[CompanyId] ASC,
	[Year] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[PayslipDraftTransactionRow]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PayslipDraftTransactionRow](
	[Id] [uniqueidentifier] NOT NULL,
	[PayslipTodoId] [uniqueidentifier] NOT NULL,
	[ExternalId] [nvarchar](100) NOT NULL,
	[PaycodeId] [uniqueidentifier] NOT NULL,
	[Quantity] [decimal](19, 4) NULL,
	[Price] [decimal](19, 4) NULL,
	[TotalPrice] [decimal](19, 4) NULL,
	[Description] [nvarchar](2000) NULL,
	[LineNumber] [int] NOT NULL,
 CONSTRAINT [PK_PayslipDraftTransactionRow] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[PayslipTodo]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PayslipTodo](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[EmployeeId] [uniqueidentifier] NOT NULL,
	[PaymentDate] [datetime] NOT NULL,
	[BookedDate] [datetime] NULL,
	[PaidDate] [datetime2](7) NULL,
	[PayslipId] [uniqueidentifier] NULL,
	[VoucherId] [uniqueidentifier] NULL,
	[PayslipType] [int] NOT NULL,
	[CanceledDate] [datetime2](7) NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[CorrectedUTC] [datetime2](7) NULL,
 CONSTRAINT [PK_PayslipTodo] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[PhotoMetadataLink]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PhotoMetadataLink](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[PhotoServiceId] [uniqueidentifier] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[Rotation] [float] NOT NULL,
	[DocumentId] [uniqueidentifier] NULL,
	[DocumentType] [int] NOT NULL,
 CONSTRAINT [PK_PhotoMetadata] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[PrintJob]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PrintJob](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[UserId] [uniqueidentifier] NOT NULL,
	[Type] [int] NOT NULL,
	[Format] [int] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[ModifiedUtc] [datetime2](7) NULL,
	[StartedUtc] [datetime2](7) NULL,
	[CompletedUtc] [datetime2](7) NULL,
	[Status] [int] NOT NULL,
	[Parameters] [nvarchar](max) NULL,
	[Uri] [nvarchar](512) NULL,
 CONSTRAINT [PK_PrintJob] PRIMARY KEY NONCLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[PrintOut]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PrintOut](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[PrintOutType] [int] NOT NULL,
	[LatestPrintOut] [datetime2](7) NULL,
	[Name] [nvarchar](150) NULL,
	[StartDate] [datetime2](7) NULL,
	[EndDate] [datetime2](7) NULL,
	[CountryCode] [nvarchar](50) NULL,
	[PeriodType] [int] NULL,
 CONSTRAINT [PK_PrintOut] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [IX_PrintOut] UNIQUE NONCLUSTERED 
(
	[CompanyId] ASC,
	[PrintOutType] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Project]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Project](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CustomerId] [uniqueidentifier] NULL,
	[Name] [nvarchar](200) NOT NULL,
	[Number] [varchar](150) NOT NULL,
	[StartDate] [datetime2](7) NOT NULL,
	[EndDate] [datetime2](7) NULL,
	[MaximumAmount] [money] NULL,
	[Notes] [nvarchar](500) NULL,
	[Status] [int] NOT NULL,
	[ClosedDate] [datetime2](7) NULL,
	[EarliestDateInBalanceReport] [datetime2](7) NULL,
	[LatestDateInBalanceReport] [datetime2](7) NULL,
	[EarliestDateInIncomeReport] [datetime2](7) NULL,
	[LatestDateInIncomeReport] [datetime2](7) NULL,
	[MdsSyncState] [int] NOT NULL,
	[ModifiedUtc] [datetime2](7) NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[IsDeleted] [bit] NULL,
 CONSTRAINT [PK_Project] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[PurchaseReceipt]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PurchaseReceipt](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Amount] [money] NOT NULL,
	[Date] [datetime2](7) NULL,
	[Description] [nvarchar](100) NULL,
	[BankAccountId] [uniqueidentifier] NULL,
	[BankAccountName] [nvarchar](200) NULL,
	[ReceiptNumber] [nvarchar](20) NULL,
	[VatAmount] [money] NULL,
	[SupplierId] [uniqueidentifier] NULL,
	[SupplierName] [nvarchar](50) NULL,
	[SupplierNumber] [nvarchar](9) NULL,
	[VatHigh] [money] NOT NULL,
	[VatMedium] [money] NOT NULL,
	[VatLow] [money] NOT NULL,
	[IncludeVat] [bit] NOT NULL,
 CONSTRAINT [PK_PurchaseReceipt] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[PurchaseReceiptRow]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PurchaseReceiptRow](
	[Id] [uniqueidentifier] NOT NULL,
	[PurchaseReceiptId] [uniqueidentifier] NOT NULL,
	[AccountNumber] [bigint] NOT NULL,
	[AccountName] [nvarchar](200) NOT NULL,
	[RowNumber] [int] NOT NULL,
	[DebitCredit] [int] NOT NULL,
	[Amount] [money] NOT NULL,
	[VatCodeId] [uniqueidentifier] NULL,
	[Type] [int] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[FiscalYearId] [uniqueidentifier] NOT NULL,
	[CostCenterItemId1] [uniqueidentifier] NULL,
	[CostCenterItemId2] [uniqueidentifier] NULL,
	[CostCenterItemId3] [uniqueidentifier] NULL,
	[ProjectId] [uniqueidentifier] NULL,
	[VatAmount] [money] NULL,
 CONSTRAINT [PK_PurchaseReceiptRow] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[QuickCustomerInvoiceRelation]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[QuickCustomerInvoiceRelation](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CustomerInvoiceId] [uniqueidentifier] NOT NULL,
	[VoucherRelationId] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_QuickCustomerInvoiceRelation] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[QuickSupplierInvoiceRelation]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[QuickSupplierInvoiceRelation](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[SupplierInvoiceId] [uniqueidentifier] NOT NULL,
	[VoucherRelationId] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_QuickSupplierInvoiceRelation] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[QuickVoucherEntryAccount]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[QuickVoucherEntryAccount](
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Number] [bigint] NOT NULL,
 CONSTRAINT [PK_QuickVoucherEntryAccount] PRIMARY KEY CLUSTERED 
(
	[CompanyId] ASC,
	[Number] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[QuickVoucherEntryRow]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[QuickVoucherEntryRow](
	[Id] [uniqueidentifier] NOT NULL,
	[LineNumber] [int] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[VoucherDate] [datetime2](7) NOT NULL,
	[Number] [int] NOT NULL,
	[VoucherText] [nvarchar](50) NOT NULL,
	[Account] [bigint] NOT NULL,
	[ContraAccount] [bigint] NOT NULL,
	[VatCodeId] [uniqueidentifier] NULL,
	[Amount] [money] NOT NULL,
	[OriginalAmount] [money] NOT NULL,
	[DebitCredit] [tinyint] NOT NULL,
	[BusinessTransactionId] [uniqueidentifier] NULL,
	[VoucherSeries] [nchar](1) NOT NULL,
	[CostCenterItemId1] [uniqueidentifier] NULL,
	[CostCenterItemId2] [uniqueidentifier] NULL,
	[CostCenterItemId3] [uniqueidentifier] NULL,
	[ProjectId] [uniqueidentifier] NULL,
 CONSTRAINT [PK_QuickVoucherEntryRow] PRIMARY KEY NONCLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Quote]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Quote](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CustomerId] [uniqueidentifier] NOT NULL,
	[Number] [int] NULL,
	[DueDate] [datetime2](7) NOT NULL,
	[QuoteDate] [datetime2](7) NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[Amount] [money] NOT NULL,
	[VatAmount] [money] NOT NULL,
	[RoundingsAmount] [money] NOT NULL,
	[CurrencyCode] [nvarchar](3) NOT NULL,
	[CurrencyRate] [decimal](10, 4) NOT NULL,
	[Status] [int] NOT NULL,
	[RotReducedInvoicingType] [int] NOT NULL,
	[RotReducedInvoicingPropertyName] [nvarchar](50) NULL,
	[RotReducedInvoicingOrgNumber] [nvarchar](50) NULL,
	[RotReducedInvoicingAmount] [money] NOT NULL,
	[CompanyReference] [nvarchar](100) NULL,
	[RotReducedInvoicingAutomaticDistribution] [bit] NOT NULL,
	[CustomerReference] [nvarchar](100) NULL,
	[InvoiceCustomerName] [nvarchar](100) NULL,
	[InvoiceAddress1] [nvarchar](50) NULL,
	[InvoiceAddress2] [nvarchar](50) NULL,
	[InvoicePostalCode] [nvarchar](10) NULL,
	[InvoiceCity] [nvarchar](50) NULL,
	[InvoiceCountryCode] [nvarchar](2) NULL,
	[DeliveryCustomerName] [nvarchar](100) NULL,
	[DeliveryAddress1] [nvarchar](50) NULL,
	[DeliveryAddress2] [nvarchar](50) NULL,
	[DeliveryPostalCode] [nvarchar](10) NULL,
	[DeliveryCity] [nvarchar](50) NULL,
	[DeliveryCountryCode] [nvarchar](2) NULL,
	[DeliveryMethodName] [nvarchar](100) NULL,
	[DeliveryTermName] [nvarchar](100) NULL,
	[DeliveryMethodCode] [nvarchar](20) NULL,
	[DeliveryTermCode] [nvarchar](20) NULL,
	[EuThirdParty] [bit] NOT NULL,
	[CustomerIsPrivatePerson] [bit] NOT NULL,
	[PrintSetting] [tinyint] NULL,
	[ApprovedDate] [datetime2](7) NULL,
	[ForceBookkeepVat] [bit] NOT NULL,
	[CustomerVatNumber] [nvarchar](20) NULL,
	[RotPropertyType] [int] NULL,
	[TermsOfPaymentId] [uniqueidentifier] NOT NULL,
	[IncludesVat] [bit] NOT NULL,
	[EmailStatus] [int] NOT NULL,
	[UsesNewRounding] [bit] NOT NULL,
 CONSTRAINT [PK_Quote] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[QuoteLog]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[QuoteLog](
	[Id] [uniqueidentifier] NOT NULL,
	[QuoteId] [uniqueidentifier] NOT NULL,
	[SentEmail] [nvarchar](200) NULL,
	[SentType] [int] NOT NULL,
	[SentDate] [datetime] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[ReadCount] [int] NOT NULL,
	[EmailStatus] [int] NOT NULL,
	[EmailMessage] [nvarchar](max) NULL,
	[EmailStatusDate] [datetime] NULL,
	[IsNotDelivered] [bit] NULL,
	[EmailLogId] [uniqueidentifier] NULL,
 CONSTRAINT [PK_QuoteLog] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[QuotePerson]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[QuotePerson](
	[Id] [uniqueidentifier] NOT NULL,
	[QuoteId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Ssn] [nvarchar](50) NOT NULL,
	[Amount] [money] NOT NULL,
 CONSTRAINT [PK_QuotePerson] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[QuoteRow]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[QuoteRow](
	[Id] [uniqueidentifier] NOT NULL,
	[QuoteId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[LineNumber] [int] NOT NULL,
	[Text] [nvarchar](2000) NULL,
	[Quantity] [decimal](19, 4) NOT NULL,
	[UnitPrice] [money] NOT NULL,
	[DiscountPercentage] [decimal](5, 4) NOT NULL,
	[WorkCostType] [int] NOT NULL,
	[IsVatFree] [bit] NOT NULL,
	[ArticleId] [uniqueidentifier] NULL,
	[CostCenterItemId1] [uniqueidentifier] NULL,
	[CostCenterItemId2] [uniqueidentifier] NULL,
	[CostCenterItemId3] [uniqueidentifier] NULL,
	[IsWorkCost] [bit] NOT NULL,
	[WorkHours] [decimal](9, 2) NULL,
	[ProjectId] [uniqueidentifier] NULL,
	[MaterialCosts] [decimal](9, 2) NULL,
 CONSTRAINT [PK_QuoteRow] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[RecurringCustomerInvoiceSettings]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[RecurringCustomerInvoiceSettings](
	[CustomerInvoiceDraftId] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CreatedByUserId] [uniqueidentifier] NOT NULL,
	[Name] [nvarchar](50) NULL,
	[Description] [nvarchar](400) NULL,
	[StartDate] [date] NOT NULL,
	[EndDate] [date] NULL,
	[Interval] [int] NOT NULL,
	[IsActive] [bit] NOT NULL,
	[IsAutomatic] [bit] NOT NULL,
	[ShowPeriodOfContract] [bit] NOT NULL,
	[Number] [int] NOT NULL,
	[InvoiceSentType] [int] NOT NULL,
	[Title] [nvarchar](50) NULL,
 CONSTRAINT [PK_RecurringCustomerInvoiceSettings] PRIMARY KEY CLUSTERED 
(
	[CustomerInvoiceDraftId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [UX_RecurringCustomerInvoiceSettings_CompanyId_Number] UNIQUE NONCLUSTERED 
(
	[CompanyId] ASC,
	[Number] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[RegisterImportReport]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[RegisterImportReport](
	[Id] [uniqueidentifier] NOT NULL,
	[UserId] [uniqueidentifier] NOT NULL,
	[CompanyID] [uniqueidentifier] NOT NULL,
	[ImportReference] [uniqueidentifier] NOT NULL,
	[RegisterType] [int] NOT NULL,
	[UpdatedCount] [int] NOT NULL,
	[CreatedCount] [int] NOT NULL,
	[SkippedCount] [int] NOT NULL,
	[ErrorMessage] [nvarchar](max) NULL,
	[NotifyUser] [bit] NOT NULL,
	[AcknowledgedByUser] [datetime] NULL,
	[Created] [datetime] NOT NULL,
	[ImportedBy] [nvarchar](256) NOT NULL,
 CONSTRAINT [PK_RegisterImportReport] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[SalesDocumentAttachment]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SalesDocumentAttachment](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[DocumentId] [uniqueidentifier] NULL,
	[VismaStorageId] [uniqueidentifier] NOT NULL,
	[DocumentType] [int] NOT NULL,
	[DownloadUrl] [nvarchar](2083) NOT NULL,
	[OriginalFilename] [nvarchar](128) NOT NULL,
	[DocumentSize] [int] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[Thumbnail] [image] NULL,
	[CreatedByUserId] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_SalesDocumentAttachment] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[SalesDocumentAttachmentLog]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SalesDocumentAttachmentLog](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CustomerInvoiceId] [uniqueidentifier] NOT NULL,
	[CustomerInvoiceLogId] [uniqueidentifier] NULL,
	[VismaStorageId] [uniqueidentifier] NOT NULL,
	[CreatedByUserId] [uniqueidentifier] NOT NULL,
	[Filename] [nvarchar](128) NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[DocumentId] [uniqueidentifier] NULL,
	[DocumentLogId] [uniqueidentifier] NULL,
	[DocumentType] [int] NULL,
 CONSTRAINT [PK_SalesDocumentAttachmentLog] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[SchemaVersions]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SchemaVersions](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[ScriptName] [nvarchar](255) NOT NULL,
	[Applied] [datetime] NOT NULL,
 CONSTRAINT [PK_SchemaVersions_Id] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[StandardAccount]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[StandardAccount](
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Type] [int] NOT NULL,
	[AccountNumber] [bigint] NOT NULL,
 CONSTRAINT [PK_StandardAccount] PRIMARY KEY CLUSTERED 
(
	[CompanyId] ASC,
	[Type] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Supplier]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Supplier](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[SupplierNumber] [nvarchar](16) NOT NULL,
	[Name] [nvarchar](50) NULL,
	[Address1] [nvarchar](50) NULL,
	[Address2] [nvarchar](50) NULL,
	[PostalCode] [nvarchar](10) NULL,
	[City] [nvarchar](50) NULL,
	[CurrencyCode] [nvarchar](3) NOT NULL,
	[Telephone] [nvarchar](50) NULL,
	[Note] [nvarchar](4000) NULL,
	[WwwAddress] [nvarchar](255) NULL,
	[EmailAddress] [nvarchar](255) NULL,
	[CorporateIdentityNumber] [nvarchar](20) NULL,
	[BankgiroNumber] [nvarchar](10) NULL,
	[PlusgiroNumber] [nvarchar](10) NULL,
	[TermsOfPaymentId] [uniqueidentifier] NOT NULL,
	[Ocr] [bit] NOT NULL,
	[AutomaticPaymentService] [bit] NOT NULL,
	[ContactPersonName] [nvarchar](50) NULL,
	[ContactPersonPhone] [nvarchar](50) NULL,
	[ContactPersonMobile] [nvarchar](50) NULL,
	[ContactPersonEmail] [nvarchar](255) NULL,
	[BankName] [nvarchar](50) NULL,
	[BankCurrencyCode] [nvarchar](3) NULL,
	[BankBic] [nvarchar](50) NULL,
	[BankBban] [nvarchar](50) NULL,
	[BankIban] [nvarchar](50) NULL,
	[BankCode] [nvarchar](50) NULL,
	[BankAccountNumber] [nvarchar](50) NULL,
	[ForeignPaymentCodeId] [uniqueidentifier] NULL,
	[BankFeeCode] [int] NOT NULL,
	[CompanyBankAccountId] [uniqueidentifier] NULL,
	[CreatedUtc] [datetime2](7) NULL,
	[BankBeneficiaryId] [int] IDENTITY(1,1) NOT NULL,
	[CountryCode] [nvarchar](2) NOT NULL,
	[BankCountryCode] [nvarchar](2) NOT NULL,
	[ModifiedUtc] [datetime2](7) NULL,
	[MobilePhone] [nvarchar](50) NULL,
	[Status] [int] NOT NULL,
	[SelfEmployedWithoutFixedAddress] [bit] NOT NULL,
	[VatNumber] [nvarchar](20) NULL,
 CONSTRAINT [PK_Supplier] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[SupplierInvoice]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SupplierInvoice](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CurrencyCode] [nvarchar](3) NOT NULL,
	[CurrencyRate] [decimal](10, 4) NOT NULL,
	[InvoiceNumber] [nvarchar](50) NOT NULL,
	[SupplierId] [uniqueidentifier] NULL,
	[SupplierName] [nvarchar](50) NOT NULL,
	[SupplierNumber] [nvarchar](50) NULL,
	[SupplierAddress] [nvarchar](50) NULL,
	[SupplierPostalCode] [nvarchar](50) NULL,
	[SupplierCity] [nvarchar](50) NULL,
	[SupplierCountryCode] [nvarchar](2) NOT NULL,
	[TotalAmount] [money] NULL,
	[TotalAmountBaseCurrency] [money] NULL,
	[VAT] [money] NULL,
	[InvoiceDate] [datetime2](7) NULL,
	[DueDate] [datetime2](7) NULL,
	[PaymentDate] [datetime2](7) NULL,
	[CreditNote] [bit] NOT NULL,
	[OcrNumber] [nvarchar](25) NULL,
	[Message] [nvarchar](255) NULL,
	[CompanyBankAccountId] [uniqueidentifier] NULL,
	[BankgiroNumber] [nvarchar](10) NULL,
	[PlusgiroNumber] [nvarchar](10) NULL,
	[CreatedByUserId] [uniqueidentifier] NULL,
	[IsDomestic] [bit] NOT NULL,
	[VATHigh] [money] NOT NULL,
	[VATMedium] [money] NOT NULL,
	[VATLow] [money] NOT NULL,
	[SupplierBankCountryCode] [nvarchar](2) NOT NULL,
	[CreatedUtc] [datetime2](7) NULL,
	[RemainingAmountBaseCurrency] [money] NOT NULL,
	[RemainingAmountInvoiceCurrency] [money] NOT NULL,
	[VoucherId] [uniqueidentifier] NULL,
	[BankAgreementStatus] [int] NOT NULL,
	[CreatedFromDraftId] [uniqueidentifier] NULL,
	[SetOffAmountBaseCurrency] [money] NOT NULL,
	[SetOffAmountInvoiceCurrency] [money] NOT NULL,
	[PaymentFileStatus] [int] NOT NULL,
	[Status] [int] NOT NULL,
	[ApprovedByUserId] [uniqueidentifier] NULL,
	[ApprovedDate] [datetime] NULL,
	[BookkeepingMethod] [int] NOT NULL,
	[SupplierMatchStatus] [int] NULL,
	[AutoInvoiceInboundDocumentId] [uniqueidentifier] NULL,
	[InterimSupplierId] [uniqueidentifier] NULL,
	[Origin] [int] NOT NULL,
	[IsQuickInvoice] [bit] NOT NULL,
	[SelfEmployedWithoutFixedAddress] [bit] NOT NULL,
	[ModifiedUtc] [datetime2](7) NULL,
	[IbanNumber] [nvarchar](50) NULL,
	[RejectionMessageFromBank] [nvarchar](max) NULL,
	[ApprovalStatus] [int] NOT NULL,
 CONSTRAINT [PK_SupplierInvoice] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[SupplierInvoiceApprovalEvent]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SupplierInvoiceApprovalEvent](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[SupplierInvoiceId] [uniqueidentifier] NOT NULL,
	[ApprovalStatus] [int] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[CreatedByUserId] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_SupplierInvoiceApprovalEvent] PRIMARY KEY CLUSTERED 
(
	[SupplierInvoiceId] ASC,
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[SupplierInvoiceDocument]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SupplierInvoiceDocument](
	[SupplierInvoiceId] [uniqueidentifier] NOT NULL,
	[DocumentId] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_SupplierInvoiceDocument] PRIMARY KEY CLUSTERED 
(
	[SupplierInvoiceId] ASC,
	[DocumentId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[SupplierInvoiceRow]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SupplierInvoiceRow](
	[Id] [uniqueidentifier] NOT NULL,
	[SupplierInvoiceId] [uniqueidentifier] NOT NULL,
	[Line] [int] NOT NULL,
	[AccountingType] [int] NOT NULL,
	[Amount] [money] NOT NULL,
	[TotalAmountBaseCurrency] [money] NOT NULL,
	[GridRowType] [int] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[FiscalYearId] [uniqueidentifier] NOT NULL,
	[AccountNumber] [bigint] NOT NULL,
	[CostCenterItemId1] [uniqueidentifier] NULL,
	[CostCenterItemId2] [uniqueidentifier] NULL,
	[CostCenterItemId3] [uniqueidentifier] NULL,
	[VatAmount] [money] NULL,
	[VatCodeId] [uniqueidentifier] NULL,
	[ProjectId] [uniqueidentifier] NULL,
	[TransactionText] [nvarchar](100) NULL,
	[DoNotUseVatCode] [bit] NOT NULL,
	[Quantity] [decimal](19, 4) NULL,
	[Weight] [decimal](19, 4) NULL,
	[DeliveryDate] [datetime] NULL,
	[HarvestYear] [int] NULL,
 CONSTRAINT [PK_SupplierInvoiceRow] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[SupplierInvoiceValuationHistory]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SupplierInvoiceValuationHistory](
	[Id] [uniqueidentifier] NOT NULL,
	[SupplierInvoiceId] [uniqueidentifier] NOT NULL,
	[VoucherId] [uniqueidentifier] NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[ValueDate] [datetime2](7) NOT NULL,
	[InvoiceCurrencyCode] [nvarchar](3) NOT NULL,
	[BaseCurrencyCode] [nvarchar](3) NOT NULL,
	[ValueChangeInvoiceCurrency] [money] NOT NULL,
	[ValueChangeBaseCurrency] [money] NOT NULL,
	[RemainingAmountInvoiceCurrency] [money] NOT NULL,
	[RemainingAmountBaseCurrency] [money] NULL,
	[ValuationType] [int] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[BankTransactionId] [uniqueidentifier] NULL,
	[ReverseVoucherId] [uniqueidentifier] SPARSE  NULL,
	[BankBusinessTransactionId] [uniqueidentifier] SPARSE  NULL,
 CONSTRAINT [PK_SupplierInvoiceValuationHistory] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[sysdiagrams]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[sysdiagrams](
	[name] [sysname] NOT NULL,
	[principal_id] [int] NOT NULL,
	[diagram_id] [int] IDENTITY(1,1) NOT NULL,
	[version] [int] NULL,
	[definition] [varbinary](max) NULL,
PRIMARY KEY CLUSTERED 
(
	[diagram_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [UK_principal_name] UNIQUE NONCLUSTERED 
(
	[principal_id] ASC,
	[name] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TermsOfPayment]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TermsOfPayment](
	[Id] [uniqueidentifier] NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
	[NumberOfDays] [int] NOT NULL,
	[SortOrder] [int] NOT NULL,
	[TermsofPaymentType] [int] NOT NULL,
	[CountryCode] [nvarchar](2) NOT NULL,
	[Changed] [datetime2](7) NOT NULL,
	[IsActive] [bit] NOT NULL,
	[NameEnglish] [nvarchar](50) NULL,
 CONSTRAINT [PK_TermsOfPayment] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TransactionFeedbackFileInformation]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TransactionFeedbackFileInformation](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Filename] [nvarchar](100) NOT NULL,
	[TransactionDate] [datetime2](7) NOT NULL,
	[Amount] [money] NOT NULL,
	[Filecontent] [nvarchar](max) NOT NULL,
	[TransactionType] [int] NOT NULL,
 CONSTRAINT [PK_TransactionFeedbackFileInformation] PRIMARY KEY NONCLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Unit]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Unit](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Name] [nvarchar](20) NOT NULL,
	[Code] [nvarchar](5) NULL,
	[Abbreviation] [nvarchar](5) NOT NULL,
	[IsVisible] [bit] NOT NULL,
	[IsChangeable] [bit] NOT NULL,
	[NameEnglish] [nvarchar](20) NULL,
	[AbbreviationEnglish] [nvarchar](5) NULL,
 CONSTRAINT [PK_Unit] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [UK_UnitAbbreviation] UNIQUE NONCLUSTERED 
(
	[CompanyId] ASC,
	[Abbreviation] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [UK_UnitName] UNIQUE NONCLUSTERED 
(
	[CompanyId] ASC,
	[Name] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[UnpackingInformation]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[UnpackingInformation](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[BankMessageId] [uniqueidentifier] NOT NULL,
	[Status] [int] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[TransacationDate] [datetime2](7) NOT NULL,
	[DisplayReference] [nvarchar](25) NOT NULL,
	[Amount] [money] NOT NULL,
	[Currency] [char](3) NOT NULL,
	[HiddenReference] [nvarchar](20) NOT NULL,
	[UnpackingReference] [nvarchar](10) NOT NULL,
 CONSTRAINT [PK_UnpackingInformation] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[User]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[User](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Email] [nvarchar](256) NOT NULL,
	[FirstName] [nvarchar](100) NULL,
	[LastName] [nvarchar](100) NULL,
	[LastMessageCheckUtc] [datetime2](7) NULL,
	[IsDemoUser] [bit] NOT NULL,
	[CreatedUtc] [datetime2](7) NULL,
	[IsActive] [bit] NOT NULL,
	[VismaUserId] [uniqueidentifier] NULL,
	[PreviousUserId] [uniqueidentifier] NULL,
	[LastLoggedInUtc] [datetime2](7) NULL,
	[LanguageCode] [nvarchar](2) NOT NULL,
	[PermissionLevel] [int] NOT NULL,
	[IsRegisteredForPush] [bit] NOT NULL,
	[LastPushCheckUtc] [datetime2](7) NULL,
	[IsRegisteredForAutoInvoice] [bit] NOT NULL,
	[HasUsedAutoInvoicePrint] [bit] NULL,
	[HasUsedAutoInvoiceElectronic] [bit] NULL,
	[HasUsedAutoInvoiceB2C] [bit] NULL,
	[AccessToPayslip] [bit] NOT NULL,
	[IsConsultant] [bit] NULL,
	[AllowedToSendPayments] [bit] NOT NULL,
	[ApprovalPermissionLevel] [int] NOT NULL,
	[ConsultantType] [int] NULL,
 CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[UserConnection]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[UserConnection](
	[ConnectionId] [nvarchar](255) NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[UserId] [uniqueidentifier] NOT NULL,
	[Connected] [datetime2](7) NOT NULL,
	[Disconnected] [datetime2](7) NULL,
	[IsConnected] [bit] NOT NULL,
	[Reconnects] [int] NOT NULL,
	[IpAddress] [nvarchar](20) NULL,
	[ServerName] [nvarchar](16) NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[ConnectionId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[UserEvent]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[UserEvent](
	[CompanyId] [uniqueidentifier] NOT NULL,
	[Event] [int] NOT NULL,
	[UserId] [uniqueidentifier] NOT NULL,
	[CreatedUtc] [datetime] NOT NULL,
 CONSTRAINT [PK_UserEvent] PRIMARY KEY CLUSTERED 
(
	[CompanyId] ASC,
	[Event] ASC,
	[UserId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[UserSettings]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[UserSettings](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[SuppressBankAccountBookingWarning] [bit] NOT NULL,
	[SuppressStandardAccountBookingWarning] [bit] NOT NULL,
	[SuppressBankAccountAgreementBookingWarning] [bit] NOT NULL,
	[SuppressReceivableBookingWarning] [bit] NOT NULL,
	[SuppressPayableBookingWarning] [bit] NOT NULL,
	[SuppressBadDebtLossBookingWarning] [bit] NOT NULL,
	[SuppressQuoteMailWindow] [bit] NOT NULL,
	[SuppressCustomerInvoiceMailWindow] [bit] NOT NULL,
	[SuppressOrderMailWindow] [bit] NOT NULL,
	[SuppressLimePurchaseAlert] [bit] NOT NULL,
	[SuppressSupplierInvoiceExportInformation] [bit] NOT NULL,
	[SuppressPhotoManagementTip] [bit] NOT NULL,
	[SuppressCustomerAutoInvoiceMessage] [bit] NOT NULL,
	[ShowPostingsIncVatInSupplierInvoice] [bit] NOT NULL,
	[SuppressMultiPdfWarning] [bit] NOT NULL,
	[SuppressHouseworkRules2016DueDate] [bit] NOT NULL,
	[SuppressAutoinvoiceMarketingTip] [bit] NOT NULL,
	[TipShownLastDate] [datetime] NULL,
	[PrintoutsShowLedger] [bit] NOT NULL,
	[ReconciliationPeriodTo] [date] NULL,
	[ReconciliationPeriodFrom] [date] NULL,
	[AccountSelectboxShowActive] [bit] NOT NULL,
	[SuppressAutoinvoicePriceInformation] [bit] NOT NULL,
	[SuppressPostToLedgerInvoiceAlert] [bit] NOT NULL,
	[CheckShowInactiveAccountsCheckbox] [bit] NULL,
	[SuppressNewPayrollTaxReportInformation] [bit] NOT NULL,
 CONSTRAINT [PK_UserSettings] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[VatCode]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[VatCode](
	[Id] [uniqueidentifier] NOT NULL,
	[Code] [nvarchar](10) NULL,
	[Description] [nvarchar](255) NOT NULL,
	[CountryCode] [nvarchar](2) NOT NULL,
	[VatRateId] [uniqueidentifier] NOT NULL,
	[MossCodeType] [tinyint] NULL,
	[DescriptionEnglish] [varchar](200) NULL,
	[IsHidden] [bit] NULL,
 CONSTRAINT [PK_VATCode] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[VatCodeSetting]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[VatCodeSetting](
	[CompanyId] [uniqueidentifier] NOT NULL,
	[VatCodeId] [uniqueidentifier] NOT NULL,
	[Account1] [bigint] NULL,
	[Account2] [bigint] NULL,
 CONSTRAINT [PK_VatCodeSetting] PRIMARY KEY CLUSTERED 
(
	[CompanyId] ASC,
	[VatCodeId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[VatRate]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[VatRate](
	[Id] [uniqueidentifier] NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
	[CountryCode] [nvarchar](2) NOT NULL,
	[Type] [int] NOT NULL,
 CONSTRAINT [PK_VatRate] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[VatRateValue]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[VatRateValue](
	[Id] [uniqueidentifier] NOT NULL,
	[VatRateId] [uniqueidentifier] NOT NULL,
	[Value] [decimal](10, 4) NOT NULL,
	[ValidFromDate] [datetime2](7) NOT NULL,
 CONSTRAINT [PK_VatRateValue] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[VatReport]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[VatReport](
	[Id] [uniqueidentifier] NOT NULL,
	[Name] [nvarchar](100) NOT NULL,
	[StartDate] [datetime2](7) NULL,
	[EndDate] [datetime2](7) NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[PeriodType] [int] NOT NULL,
	[Approved] [datetime2](7) NULL,
	[LatestFileCreated] [datetime2](7) NULL,
	[VoucherId] [uniqueidentifier] NULL,
	[DeviationCount] [int] NOT NULL,
	[IsRegretted] [bit] NOT NULL,
	[CountryCode] [nvarchar](2) NOT NULL,
	[SentToAuthorityDate] [datetime2](7) NULL,
	[NoVatFromMonth] [datetime2](7) NULL,
	[NoVatToMonth] [datetime2](7) NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[FiCorrectReason] [int] NOT NULL,
	[ContactPhone] [nvarchar](20) NULL,
	[SendToAuthorityStatus] [int] NOT NULL,
	[DocumentApprovalStatus] [int] NOT NULL,
	[AttachmentId] [uniqueidentifier] NULL,
	[SentForApprovalByUserId] [uniqueidentifier] NULL,
	[ModifiedUtc] [datetime2](7) NOT NULL,
	[RegrettedByUserId] [uniqueidentifier] NULL,
	[SentToAuthorityByUserId] [uniqueidentifier] NULL,
	[RegrettedDate] [datetime2](7) NULL,
 CONSTRAINT [PK_VatReport] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[VatReportField]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[VatReportField](
	[Id] [uniqueidentifier] NOT NULL,
	[VatReportId] [uniqueidentifier] NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
	[Amount] [money] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_VatReportField] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [IX_VatReportField] UNIQUE NONCLUSTERED 
(
	[Name] ASC,
	[VatReportId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[VipVanUnpackingInformation]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[VipVanUnpackingInformation](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyBankAccountId] [uniqueidentifier] NOT NULL,
	[ReferenceId] [nvarchar](20) NOT NULL,
	[EntryTransactionAmount] [money] NOT NULL,
	[CreatedUtc] [datetime2](7) NOT NULL,
	[BookingDate] [datetime2](7) NOT NULL,
	[HiddenReference] [nvarchar](50) NULL,
	[DisplayReference] [nvarchar](50) NULL,
 CONSTRAINT [PK_VipVanUnpackingInformation] PRIMARY KEY CLUSTERED 
(
	[Id] ASC,
	[CompanyBankAccountId] ASC,
	[ReferenceId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Voucher]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Voucher](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[FiscalYearId] [uniqueidentifier] NOT NULL,
	[Number] [int] NULL,
	[VoucherDate] [datetime2](7) NULL,
	[CreatedUtc] [datetime2](7) NULL,
	[VoucherText] [nvarchar](1000) NOT NULL,
	[SourceId] [uniqueidentifier] NULL,
	[VoucherType] [int] NOT NULL,
	[HasVatAmountDeviation] [bit] NOT NULL,
	[CreatedByUserId] [uniqueidentifier] NULL,
	[CorrectsVoucherId] [uniqueidentifier] NULL,
	[ImportedVoucherNumber] [nvarchar](50) NULL,
	[VoucherSum] [money] NOT NULL,
	[CorrectionType] [int] NOT NULL,
	[ModifiedUtc] [datetime2](7) NOT NULL,
	[QuickVoucherEntryNumber] [int] NULL,
	[HasInvoices] [bit] NOT NULL,
	[NumberSeries] [nchar](1) NOT NULL,
	[BookkeepingMethod] [int] NOT NULL,
	[HasQuickInvoices] [bit] NOT NULL,
 CONSTRAINT [PK_Voucher] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[VoucherRelation]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[VoucherRelation](
	[Id] [uniqueidentifier] NOT NULL,
	[VoucherId] [uniqueidentifier] NOT NULL,
	[RelatedVoucherId] [uniqueidentifier] NOT NULL,
	[RelationType] [int] NOT NULL,
	[Created] [datetime2](7) NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_VoucherRelation] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [IX_VoucherRelation] UNIQUE NONCLUSTERED 
(
	[VoucherId] ASC,
	[RelatedVoucherId] ASC,
	[RelationType] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[VoucherRow]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[VoucherRow](
	[VoucherId] [uniqueidentifier] NOT NULL,
	[Line] [int] NOT NULL,
	[Amount] [money] NOT NULL,
	[DebitCredit] [int] NOT NULL,
	[VatCodeId] [uniqueidentifier] NULL,
	[IsDeclaredOnVatReportId] [uniqueidentifier] NULL,
	[IsCorrected] [bit] NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[FiscalYearId] [uniqueidentifier] NOT NULL,
	[AccountNumber] [bigint] NOT NULL,
	[TransactionText] [nvarchar](300) NULL,
	[CostCenterItemId1] [uniqueidentifier] NULL,
	[CostCenterItemId2] [uniqueidentifier] NULL,
	[CostCenterItemId3] [uniqueidentifier] NULL,
	[VatAmount] [money] NULL,
	[ProjectId] [uniqueidentifier] NULL,
	[Quantity] [decimal](19, 4) SPARSE  NULL,
	[Weight] [decimal](19, 4) SPARSE  NULL,
	[DeliveryDate] [datetime] SPARSE  NULL,
	[HarvestYear] [int] SPARSE  NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[WebshopOrder]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[WebshopOrder](
	[Id] [uniqueidentifier] NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
	[CorporateIdentityNumber] [nvarchar](50) NOT NULL,
	[CustomerId] [uniqueidentifier] NULL,
	[CustomerName] [nvarchar](100) NULL,
	[CustomerContactName] [nvarchar](100) NULL,
	[CustomerAddress1] [nvarchar](50) NULL,
	[CustomerAddress2] [nvarchar](50) NULL,
	[CustomerPostalCode] [nvarchar](50) NULL,
	[CustomerCity] [nvarchar](50) NULL,
	[CustomerCountry] [nvarchar](50) NULL,
	[CustomerCountryCode] [nvarchar](2) NULL,
	[CustomerNameDelivery] [nvarchar](50) NULL,
	[CustomerAddress1Delivery] [nvarchar](50) NULL,
	[CustomerAddress2Delivery] [nvarchar](50) NULL,
	[CustomerPostalCodeDelivery] [nvarchar](50) NULL,
	[CustomerCityDelivery] [nvarchar](50) NULL,
	[CustomerCountryDelivery] [nvarchar](50) NULL,
	[CustomerCountryCodeDelivery] [nvarchar](2) NULL,
	[Telephone] [nvarchar](50) NULL,
	[ContactPersonMobile] [nvarchar](50) NULL,
	[EmailAddress] [nvarchar](255) NULL,
	[CurrencyCode] [nvarchar](3) NOT NULL,
	[CurrencyRate] [decimal](10, 4) NOT NULL,
	[Category] [int] NOT NULL,
	[VatIncluded] [bit] NOT NULL,
	[ExternalCustomerNumber] [int] NOT NULL,
	[ExternalOrderNumber] [int] NOT NULL,
	[ExternalOrderDate] [datetime2](7) NOT NULL,
	[TermsOfPaymentId] [uniqueidentifier] NOT NULL,
	[TotalAmountBaseCurrency] [money] NULL,
	[TotalAmountRoundings] [money] NULL,
	[Status] [int] NOT NULL,
	[Created] [datetime2](7) NOT NULL,
	[ExternalPaymentReference] [nvarchar](50) NULL,
	[DiscountId] [uniqueidentifier] NULL,
	[CustomerIsPrivatePerson] [bit] NOT NULL,
	[FeeAmount] [money] NULL,
	[Note] [nvarchar](120) NULL,
	[CustomerVatNo] [nvarchar](20) NULL,
	[StatusMessage] [nvarchar](max) NULL,
	[ModifiedUtc] [datetime2](7) NULL,
 CONSTRAINT [PK_CustomerInvoiceDraft] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[WebshopOrderRow]    Script Date: 2018-08-23 13:17:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[WebshopOrderRow](
	[Id] [uniqueidentifier] NOT NULL,
	[WebshopOrderId] [uniqueidentifier] NOT NULL,
	[ArticleId] [uniqueidentifier] NULL,
	[ArticleNumber] [nvarchar](40) NULL,
	[ArticleName] [nvarchar](200) NULL,
	[ArticleGroup] [int] NOT NULL,
	[ArticleAccountCodingId] [uniqueidentifier] NULL,
	[Quantity] [decimal](19, 4) NOT NULL,
	[PricePerUnitNet] [money] NOT NULL,
	[PricePerUnitGross] [money] NOT NULL,
	[PercentVat] [decimal](10, 4) NOT NULL,
	[UnitId] [uniqueidentifier] NULL,
	[UnitAbbreviation] [nvarchar](5) NOT NULL,
	[CompanyId] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_CustomerInvoiceDraftRow] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
ALTER TABLE [dbo].[Account] ADD  CONSTRAINT [DF_Account_Created]  DEFAULT (getdate()) FOR [CreatedUtc]
GO
ALTER TABLE [dbo].[Account] ADD  DEFAULT ((0)) FOR [IsBlockedForManualBooking]
GO
ALTER TABLE [dbo].[Account] ADD  DEFAULT (getutcdate()) FOR [ModifiedUtc]
GO
ALTER TABLE [dbo].[Account] ADD  DEFAULT ('') FOR [ReferenceCode]
GO
ALTER TABLE [dbo].[AllocationPeriod] ADD  DEFAULT ((0)) FOR [Status]
GO
ALTER TABLE [dbo].[Article] ADD  CONSTRAINT [DF_Article_Created]  DEFAULT (getdate()) FOR [CreatedUtc]
GO
ALTER TABLE [dbo].[Article] ADD  DEFAULT ('0001-01-02') FOR [ChangedUtc]
GO
ALTER TABLE [dbo].[Article] ADD  DEFAULT ((0)) FOR [Group]
GO
ALTER TABLE [dbo].[Article] ADD  DEFAULT ((0)) FOR [StockBalance]
GO
ALTER TABLE [dbo].[Article] ADD  DEFAULT ((0)) FOR [StockBalanceReserved]
GO
ALTER TABLE [dbo].[Article] ADD  DEFAULT ((0)) FOR [UsesMoss]
GO
ALTER TABLE [dbo].[Article] ADD  DEFAULT ((1)) FOR [SendToWebshop]
GO
ALTER TABLE [dbo].[Article] ADD  CONSTRAINT [DF_PurchasePrice]  DEFAULT ((0)) FOR [PurchasePrice]
GO
ALTER TABLE [dbo].[ArticleAccountCoding] ADD  DEFAULT ('0001-01-02') FOR [ChangedUtc]
GO
ALTER TABLE [dbo].[Bank] ADD  DEFAULT ((0)) FOR [Type]
GO
ALTER TABLE [dbo].[Bank] ADD  DEFAULT ((0)) FOR [EikaGroup]
GO
ALTER TABLE [dbo].[Bank] ADD  DEFAULT ((0)) FOR [SpareBankenGroup]
GO
ALTER TABLE [dbo].[BankTransaction] ADD  DEFAULT ((0)) FOR [ValidForAutomaticReconciliation]
GO
ALTER TABLE [dbo].[BankTransaction] ADD  DEFAULT ((0)) FOR [IsUnpacked]
GO
ALTER TABLE [dbo].[BankTransaction] ADD  DEFAULT ((0)) FOR [IsWaitingForUnpackingInformation]
GO
ALTER TABLE [dbo].[BankTransaction] ADD  DEFAULT ((0)) FOR [SuggestedMatchSourceType]
GO
ALTER TABLE [dbo].[BankTransaction] ADD  DEFAULT ((0)) FOR [SuggestedMatchVoucherType]
GO
ALTER TABLE [dbo].[BankTransaction] ADD  DEFAULT ((0)) FOR [SuggestedMatchAmount]
GO
ALTER TABLE [dbo].[BankTransaction] ADD  DEFAULT ((0)) FOR [IsSuspectedDuplicate]
GO
ALTER TABLE [dbo].[BankTransaction] ADD  DEFAULT ((0)) FOR [IsMasterBankTransaction]
GO
ALTER TABLE [dbo].[BusinessTransaction] ADD  DEFAULT ((0)) FOR [DeductionAmountInBaseCurrency]
GO
ALTER TABLE [dbo].[ChartOfAccountsTemplate] ADD  DEFAULT ((0)) FOR [IsActiveWhenCooperatives]
GO
ALTER TABLE [dbo].[ChartOfAccountsTemplate] ADD  DEFAULT ((0)) FOR [IsActiveWhenLimitedPartnership]
GO
ALTER TABLE [dbo].[ChartOfAccountsTemplate] ADD  DEFAULT ((0)) FOR [IsBlockedForManualBooking]
GO
ALTER TABLE [dbo].[ChartOfAccountsTemplate] ADD  DEFAULT ('') FOR [ReferenceCode]
GO
ALTER TABLE [dbo].[Company] ADD  CONSTRAINT [DF_Company_Created]  DEFAULT (getdate()) FOR [CreatedUtc]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((1)) FOR [CompanyStatus]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [VismaWebshopStatus]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [VismaWebshopLatestOrderNumber]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ('0001-01-01') FOR [VismaWebshopLatestReceiveTimeUtc]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [CompanySystemType]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ('false') FOR [VismaWebshopSyncIsRequired]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [AutoInvoiceLatestReceivedErrorNumber]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [LastEdiSupplierInvoiceNumber]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((1)) FOR [UsesOcr]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [PrintTheme]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [LatePaymentFee]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [FirstPaymentReminderWithoutFee]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((2)) FOR [CollectionThreshold]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((1)) FOR [UsesQr]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [PaymentFileActivated]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [UsesSupplierinvoiceApproval]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [AutoInvoiceStatus]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [CompanyDepreciation]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [ShowPayroll]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [UsesMoss]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((25)) FOR [DefaultSalaryPaymentDay]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [AccountingPeriodLockSettingsType]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [UsesProject]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [UsesTransactionText]
GO
ALTER TABLE [dbo].[Company] ADD  CONSTRAINT [DF_Company_InvoicePrintSettingsType]  DEFAULT ((1)) FOR [InvoicePrintSettingsType]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [UsesQuickInvoice]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [MigrationGuideState]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [AutoInvoiceB2CStatusSyncRetryCount]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [AutoInvoiceOutboundStatusSyncRetryCount]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [AutoInvoiceInboundSyncRetryCount]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [RutMaxAmountForPersBelow65Year]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [RutMaxAmountForPersOver65Year]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [RutReducedInvoicingPercent]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((0)) FOR [AutoInvoiceScanningStatus]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((1)) FOR [UsesArticle]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((1)) FOR [UsesUnit]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((1)) FOR [UsesQuantity]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((1)) FOR [UsesPrice]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((1)) FOR [EnvelopeType]
GO
ALTER TABLE [dbo].[Company] ADD  CONSTRAINT [DF_Company_ShowPricesExclVatPC]  DEFAULT ((0)) FOR [ShowPricesExclVatPC]
GO
ALTER TABLE [dbo].[Company] ADD  CONSTRAINT [DF_Company_AltinnCredentials]  DEFAULT ((0)) FOR [HasAltinnCredentialsSet]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((1)) FOR [ShowOrder]
GO
ALTER TABLE [dbo].[Company] ADD  DEFAULT ((1)) FOR [ShowQuote]
GO
ALTER TABLE [dbo].[Company] ADD  CONSTRAINT [DF_UsesUnrestrictedInvoicePayments]  DEFAULT ((0)) FOR [UsesUnrestrictedInvoicePayments]
GO
ALTER TABLE [dbo].[Company] ADD  CONSTRAINT [DF_ShowProject]  DEFAULT ((0)) FOR [ShowProject]
GO
ALTER TABLE [dbo].[Company] ADD  CONSTRAINT [DF_HasDigipoortCertificateEnabled]  DEFAULT ((0)) FOR [HasDigipoortCertificateEnabled]
GO
ALTER TABLE [dbo].[Company] ADD  CONSTRAINT [DF_InvoiceRoundingType]  DEFAULT ((0)) FOR [DomesticCurrencyRounding]
GO
ALTER TABLE [dbo].[Company] ADD  CONSTRAINT [DF_SendVatReportToAuthority]  DEFAULT ((0)) FOR [SendVatReportToAuthority]
GO
ALTER TABLE [dbo].[Company] ADD  CONSTRAINT [DF_UsesDeferredPaymentSending]  DEFAULT ((0)) FOR [UsesDeferredPaymentSending]
GO
ALTER TABLE [dbo].[Company] ADD  CONSTRAINT [DF_AutoinvoiceSIStatus]  DEFAULT ((0)) FOR [AutoinvoiceSIStatus]
GO
ALTER TABLE [dbo].[Company] ADD  CONSTRAINT [DF_LastEdiReceiverInfoNumber]  DEFAULT ((0)) FOR [LastEdiReceiverInfoNumber]
GO
ALTER TABLE [dbo].[Company] ADD  CONSTRAINT [DF_UsesSupplierInvoiceEdit]  DEFAULT ((0)) FOR [UsesSupplierInvoiceEdit]
GO
ALTER TABLE [dbo].[Company] ADD  CONSTRAINT [DF_UsesVatReportApproval]  DEFAULT ((0)) FOR [UsesVatReportApproval]
GO
ALTER TABLE [dbo].[Company] ADD  CONSTRAINT [DF_IsInCollaboration]  DEFAULT ((0)) FOR [IsInCollaboration]
GO
ALTER TABLE [dbo].[Company] ADD  CONSTRAINT [DF_AllowEndUserToRecordPayment]  DEFAULT ((0)) FOR [AllowEndUserToRecordPayment]
GO
ALTER TABLE [dbo].[Company] ADD  CONSTRAINT [DF_UsesNewTaxReport]  DEFAULT ((0)) FOR [UsesNewTaxReport]
GO
ALTER TABLE [dbo].[CompanyBankAccount] ADD  CONSTRAINT [DF_CompanyBankAccount_LastUpdatedDate]  DEFAULT (getutcdate()) FOR [ModifiedUtc]
GO
ALTER TABLE [dbo].[CompanyBankAccount] ADD  CONSTRAINT [DF_CompanyBankAccount_Created]  DEFAULT (getdate()) FOR [CreatedUtc]
GO
ALTER TABLE [dbo].[CompanyBankAccount] ADD  DEFAULT ((0)) FOR [IsDefaultChequeAccount]
GO
ALTER TABLE [dbo].[CompanyBankAccount] ADD  DEFAULT ('Account holder name') FOR [BankAccountHolderName]
GO
ALTER TABLE [dbo].[CompanyBankAccount] ADD  CONSTRAINT [DF_UsesAutopay]  DEFAULT ((0)) FOR [UsesAutopay]
GO
ALTER TABLE [dbo].[CompanyBankAccount] ADD  CONSTRAINT [DF_NextAutopayMessageOutId]  DEFAULT ((0)) FOR [NextAutopayMessageOutId]
GO
ALTER TABLE [dbo].[CompanyBankAccount] ADD  CONSTRAINT [DF_ForceAddNewAutopayAgreement]  DEFAULT ((0)) FOR [ForceAddNewAutopayAgreement]
GO
ALTER TABLE [dbo].[CompanyBankAccount] ADD  CONSTRAINT [DF_ManualServicesAddedAutopay]  DEFAULT ((0)) FOR [ManualServicesAddedAutopay]
GO
ALTER TABLE [dbo].[CompanyBankAccount] ADD  CONSTRAINT [DF_UseManualPayments]  DEFAULT ((0)) FOR [UseManualPayments]
GO
ALTER TABLE [dbo].[CompanyBankAccount] ADD  CONSTRAINT [DF_ShowOnInvoicePrintout]  DEFAULT ((0)) FOR [ShowOnInvoicePrintout]
GO
ALTER TABLE [dbo].[CompanyBankAccount] ADD  CONSTRAINT [DF_AutopayMigrationStatus]  DEFAULT ((0)) FOR [AutopayMigrationStatus]
GO
ALTER TABLE [dbo].[CompanyBankAccount] ADD  CONSTRAINT [DF_AutopayMigrationErrors]  DEFAULT ((0)) FOR [AutopayMigrationErrors]
GO
ALTER TABLE [dbo].[CompanyNumberSeries] ADD  DEFAULT ((0)) FOR [OrderNumber]
GO
ALTER TABLE [dbo].[CompanyNumberSeries] ADD  DEFAULT ((0)) FOR [QuoteNumber]
GO
ALTER TABLE [dbo].[CompanyNumberSeries] ADD  DEFAULT ((0)) FOR [IsQuoteNumberLocked]
GO
ALTER TABLE [dbo].[CompanyNumberSeries] ADD  DEFAULT ((1)) FOR [QuickVoucherEntryNumber]
GO
ALTER TABLE [dbo].[CompanyNumberSeries] ADD  DEFAULT ((0)) FOR [IsOrderNumberLocked]
GO
ALTER TABLE [dbo].[CompanyNumberSeries] ADD  DEFAULT ((1)) FOR [PaymentFileNumber]
GO
ALTER TABLE [dbo].[CompanyNumberSeries] ADD  DEFAULT ((0)) FOR [EmployeeNumber]
GO
ALTER TABLE [dbo].[CompanyVoucherSeries] ADD  DEFAULT ('A') FOR [Inventory]
GO
ALTER TABLE [dbo].[Customer] ADD  DEFAULT (getdate()) FOR [CreatedUtc]
GO
ALTER TABLE [dbo].[Customer] ADD  DEFAULT ('MAVENTA') FOR [EdiServiceDelivererId]
GO
ALTER TABLE [dbo].[Customer] ADD  DEFAULT ((0)) FOR [ForceBookkeepVat]
GO
ALTER TABLE [dbo].[Customer] ADD  DEFAULT (NULL) FOR [LastInvoiceDate]
GO
ALTER TABLE [dbo].[Customer] ADD  DEFAULT ((0)) FOR [UsesAutoInvoiceB2C]
GO
ALTER TABLE [dbo].[Customer] ADD  DEFAULT ((0)) FOR [RequiresReferenceNumber]
GO
ALTER TABLE [dbo].[Customer] ADD  CONSTRAINT [DF_InvoiceInEnglish]  DEFAULT ((0)) FOR [InvoiceInEnglish]
GO
ALTER TABLE [dbo].[Customer] ADD  CONSTRAINT [DF_DiscountPercentage]  DEFAULT ((0)) FOR [DiscountPercentage]
GO
ALTER TABLE [dbo].[CustomerInvoice] ADD  CONSTRAINT [DF_CustomerInvoice_Created]  DEFAULT (getdate()) FOR [CreatedUtc]
GO
ALTER TABLE [dbo].[CustomerInvoice] ADD  DEFAULT ((0)) FOR [AllowReSendElectronicInvoice]
GO
ALTER TABLE [dbo].[CustomerInvoice] ADD  DEFAULT ((0)) FOR [VatAmount]
GO
ALTER TABLE [dbo].[CustomerInvoice] ADD  DEFAULT ((0)) FOR [RotReducedInvoicingType]
GO
ALTER TABLE [dbo].[CustomerInvoice] ADD  DEFAULT ((0)) FOR [ForceBookkeepVat]
GO
ALTER TABLE [dbo].[CustomerInvoice] ADD  DEFAULT ((0)) FOR [PrintSetting]
GO
ALTER TABLE [dbo].[CustomerInvoice] ADD  DEFAULT ((0)) FOR [Category]
GO
ALTER TABLE [dbo].[CustomerInvoice] ADD  DEFAULT ((0)) FOR [IsCreditInvoice]
GO
ALTER TABLE [dbo].[CustomerInvoice] ADD  CONSTRAINT [DF_CustomerInvoice_SetOffAmountBaseCurrency]  DEFAULT ((0)) FOR [SetOffAmountBaseCurrency]
GO
ALTER TABLE [dbo].[CustomerInvoice] ADD  CONSTRAINT [DF_CustomerInvoice_SetOffAmountInvoiceCurrency]  DEFAULT ((0)) FOR [SetOffAmountInvoiceCurrency]
GO
ALTER TABLE [dbo].[CustomerInvoice] ADD  DEFAULT ((0)) FOR [RotReducedInvoicingAutomaticDistribution]
GO
ALTER TABLE [dbo].[CustomerInvoice] ADD  DEFAULT ((0)) FOR [IsQuickInvoice]
GO
ALTER TABLE [dbo].[CustomerInvoice] ADD  CONSTRAINT [DF_CustomerInvoice_InvoiceBasisSource]  DEFAULT ((0)) FOR [InvoiceBasisSource]
GO
ALTER TABLE [dbo].[CustomerInvoice] ADD  CONSTRAINT [DF_CustomerInvoice_IncludesVat]  DEFAULT ((1)) FOR [IncludesVat]
GO
ALTER TABLE [dbo].[CustomerInvoice] ADD  DEFAULT ((0)) FOR [EmailStatus]
GO
ALTER TABLE [dbo].[CustomerInvoice] ADD  DEFAULT ((0)) FOR [UsesNewRounding]
GO
ALTER TABLE [dbo].[CustomerInvoiceDraft] ADD  DEFAULT ((0)) FOR [RotReducedInvoicingAutomaticDistribution]
GO
ALTER TABLE [dbo].[CustomerInvoiceDraft] ADD  DEFAULT ((0)) FOR [EuThirdParty]
GO
ALTER TABLE [dbo].[CustomerInvoiceDraft] ADD  DEFAULT ((0)) FOR [IsCreditInvoice]
GO
ALTER TABLE [dbo].[CustomerInvoiceDraft] ADD  CONSTRAINT [DF_CustomerInvoiceDraft_InvoiceBasisSource]  DEFAULT ((0)) FOR [InvoiceBasisSource]
GO
ALTER TABLE [dbo].[CustomerInvoiceDraft] ADD  CONSTRAINT [DF_CustomerInvoiceDraft_IncludesVat]  DEFAULT ((1)) FOR [IncludesVat]
GO
ALTER TABLE [dbo].[CustomerInvoiceDraft] ADD  DEFAULT ((0)) FOR [UsesNewRounding]
GO
ALTER TABLE [dbo].[CustomerInvoiceDraftRow] ADD  DEFAULT ((0)) FOR [IsWorkCost]
GO
ALTER TABLE [dbo].[CustomerInvoiceLog] ADD  DEFAULT ((0)) FOR [ReadCount]
GO
ALTER TABLE [dbo].[CustomerInvoiceLog] ADD  DEFAULT ((0)) FOR [InvoiceDocumentType]
GO
ALTER TABLE [dbo].[CustomerInvoiceLog] ADD  DEFAULT ((0)) FOR [EmailStatus]
GO
ALTER TABLE [dbo].[CustomerInvoiceRow] ADD  CONSTRAINT [DF_CustomerInvoiceRow_IsCreatedFromOrder]  DEFAULT ((0)) FOR [IsCreatedFromOrder]
GO
ALTER TABLE [dbo].[CustomerInvoiceRow] ADD  DEFAULT ((0)) FOR [IsWorkCost]
GO
ALTER TABLE [dbo].[CustomerInvoiceRow] ADD  DEFAULT ((0)) FOR [IsServiceArticle]
GO
ALTER TABLE [dbo].[Document] ADD  CONSTRAINT [DF_Document_Created]  DEFAULT (getdate()) FOR [CreatedUtc]
GO
ALTER TABLE [dbo].[EmployerReport] ADD  CONSTRAINT [DF_UsesNewEmployerTaxReport]  DEFAULT ((0)) FOR [UsesNewTaxReport]
GO
ALTER TABLE [dbo].[FiscalYear] ADD  CONSTRAINT [DF_FiscalYear_Created]  DEFAULT (getdate()) FOR [CreatedUtc]
GO
ALTER TABLE [dbo].[FiscalYear] ADD  DEFAULT ((0)) FOR [AccountsModifiedTicksUtc]
GO
ALTER TABLE [dbo].[FiscalYear] ADD  DEFAULT ((0)) FOR [IsChecklistCompleted]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] ADD  DEFAULT ((0)) FOR [VoucherNumberB]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] ADD  DEFAULT ((0)) FOR [VoucherNumberC]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] ADD  DEFAULT ((0)) FOR [VoucherNumberD]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] ADD  DEFAULT ((0)) FOR [VoucherNumberE]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] ADD  DEFAULT ((0)) FOR [VoucherNumberF]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] ADD  DEFAULT ((0)) FOR [VoucherNumberG]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] ADD  DEFAULT ((0)) FOR [VoucherNumberH]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] ADD  DEFAULT ((0)) FOR [VoucherNumberI]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] ADD  CONSTRAINT [DF_VoucherNumberL]  DEFAULT ((0)) FOR [VoucherNumberL]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] ADD  CONSTRAINT [DF_VoucherNumberM]  DEFAULT ((0)) FOR [VoucherNumberM]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] ADD  CONSTRAINT [DF_VoucherNumberN]  DEFAULT ((0)) FOR [VoucherNumberN]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] ADD  CONSTRAINT [DF_VoucherNumberO]  DEFAULT ((0)) FOR [VoucherNumberO]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] ADD  CONSTRAINT [DF_VoucherNumberP]  DEFAULT ((0)) FOR [VoucherNumberP]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] ADD  CONSTRAINT [DF_VoucherNumberQ]  DEFAULT ((0)) FOR [VoucherNumberQ]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] ADD  CONSTRAINT [DF_VoucherNumberR]  DEFAULT ((0)) FOR [VoucherNumberR]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] ADD  CONSTRAINT [DF_VoucherNumberS]  DEFAULT ((0)) FOR [VoucherNumberS]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] ADD  CONSTRAINT [DF_VoucherNumberT]  DEFAULT ((0)) FOR [VoucherNumberT]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] ADD  CONSTRAINT [DF_VoucherNumberU]  DEFAULT ((0)) FOR [VoucherNumberU]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] ADD  CONSTRAINT [DF_VoucherNumberV]  DEFAULT ((0)) FOR [VoucherNumberV]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] ADD  CONSTRAINT [DF_VoucherNumberW]  DEFAULT ((0)) FOR [VoucherNumberW]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] ADD  CONSTRAINT [DF_VoucherNumberX]  DEFAULT ((0)) FOR [VoucherNumberX]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] ADD  CONSTRAINT [DF_VoucherNumberY]  DEFAULT ((0)) FOR [VoucherNumberY]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] ADD  CONSTRAINT [DF_VoucherNumberZ]  DEFAULT ((0)) FOR [VoucherNumberZ]
GO
ALTER TABLE [dbo].[InventoryAccountingTemplate] ADD  DEFAULT ((0)) FOR [NoDepreciations]
GO
ALTER TABLE [dbo].[InventoryAccountingTemplate] ADD  DEFAULT ((0)) FOR [IsCustom]
GO
ALTER TABLE [dbo].[InventoryEvent] ADD  DEFAULT ((0)) FOR [CurrentValueBeforeEvent]
GO
ALTER TABLE [dbo].[InventoryItem] ADD  CONSTRAINT [DF_InventoryItem_CurrentValue]  DEFAULT ((0)) FOR [CurrentValue]
GO
ALTER TABLE [dbo].[InventoryItem] ADD  DEFAULT ((1)) FOR [DepreciationStartType]
GO
ALTER TABLE [dbo].[InventoryItem] ADD  CONSTRAINT [DF_InventoryItemCreatedUtcDefault]  DEFAULT (getutcdate()) FOR [CreatedUtc]
GO
ALTER TABLE [dbo].[InventoryItem] ADD  CONSTRAINT [DF_InventoryItemModifiedUtcDefault]  DEFAULT (getutcdate()) FOR [ModifiedUtc]
GO
ALTER TABLE [dbo].[IZettleIntegration] ADD  DEFAULT ((0)) FOR [IsActive]
GO
ALTER TABLE [dbo].[IZettleIntegration] ADD  DEFAULT ((0)) FOR [ReActivateIntegration]
GO
ALTER TABLE [dbo].[IZettlePurchase] ADD  DEFAULT ((0)) FOR [SwishPaymentAmount]
GO
ALTER TABLE [dbo].[IZettlePurchase] ADD  DEFAULT ((0)) FOR [VippsPaymentAmount]
GO
ALTER TABLE [dbo].[IZettlePurchase] ADD  DEFAULT ((0)) FOR [IZettleInvoicePaymentAmount]
GO
ALTER TABLE [dbo].[IZettlePurchase] ADD  CONSTRAINT [DF_GratuityAmount]  DEFAULT ((0)) FOR [GratuityAmount]
GO
ALTER TABLE [dbo].[JournalEntry] ADD  DEFAULT ((0)) FOR [JournalEntryType]
GO
ALTER TABLE [dbo].[Message] ADD  DEFAULT ((1)) FOR [IsEditByOther]
GO
ALTER TABLE [dbo].[MessageReceiver] ADD  DEFAULT ((1)) FOR [Status]
GO
ALTER TABLE [dbo].[MessageThread] ADD  DEFAULT ('') FOR [Subject]
GO
ALTER TABLE [dbo].[NifImportSettings] ADD  DEFAULT ((0)) FOR [FetchPayment]
GO
ALTER TABLE [dbo].[NifImportSettings] ADD  DEFAULT ((1)) FOR [IsClub]
GO
ALTER TABLE [dbo].[Order] ADD  DEFAULT ((0)) FOR [EuThirdParty]
GO
ALTER TABLE [dbo].[Order] ADD  CONSTRAINT [DF_Order_IncludesVat]  DEFAULT ((1)) FOR [IncludesVat]
GO
ALTER TABLE [dbo].[Order] ADD  CONSTRAINT [DF_OrderEmailStatus]  DEFAULT ((0)) FOR [EmailStatus]
GO
ALTER TABLE [dbo].[Order] ADD  DEFAULT ((0)) FOR [UsesNewRounding]
GO
ALTER TABLE [dbo].[OrderLog] ADD  CONSTRAINT [DF_ReadCountOrderId]  DEFAULT ((0)) FOR [ReadCount]
GO
ALTER TABLE [dbo].[OrderLog] ADD  CONSTRAINT [DF_OrderLogEmailStatus]  DEFAULT ((0)) FOR [EmailStatus]
GO
ALTER TABLE [dbo].[OrderLog] ADD  CONSTRAINT [DF_OrderLogEventType]  DEFAULT ((0)) FOR [EventType]
GO
ALTER TABLE [dbo].[OrderRow] ADD  DEFAULT ((0)) FOR [IsWorkCost]
GO
ALTER TABLE [dbo].[PaymentBatch] ADD  DEFAULT ((12)) FOR [Status]
GO
ALTER TABLE [dbo].[PayslipTodo] ADD  DEFAULT ((0)) FOR [PayslipType]
GO
ALTER TABLE [dbo].[Project] ADD  CONSTRAINT [DF_Project_Created]  DEFAULT (getdate()) FOR [CreatedUtc]
GO
ALTER TABLE [dbo].[Project] ADD  CONSTRAINT [DF_Project_IsDeleted]  DEFAULT ((0)) FOR [IsDeleted]
GO
ALTER TABLE [dbo].[PurchaseReceipt] ADD  DEFAULT ((0)) FOR [VatHigh]
GO
ALTER TABLE [dbo].[PurchaseReceipt] ADD  DEFAULT ((0)) FOR [VatMedium]
GO
ALTER TABLE [dbo].[PurchaseReceipt] ADD  DEFAULT ((0)) FOR [VatLow]
GO
ALTER TABLE [dbo].[PurchaseReceipt] ADD  CONSTRAINT [DF_IncludeVat]  DEFAULT ((0)) FOR [IncludeVat]
GO
ALTER TABLE [dbo].[Quote] ADD  DEFAULT ((0)) FOR [RotReducedInvoicingAutomaticDistribution]
GO
ALTER TABLE [dbo].[Quote] ADD  DEFAULT ((0)) FOR [EuThirdParty]
GO
ALTER TABLE [dbo].[Quote] ADD  CONSTRAINT [DF_Quote_IncludesVat]  DEFAULT ((1)) FOR [IncludesVat]
GO
ALTER TABLE [dbo].[Quote] ADD  CONSTRAINT [DF_QuoteEmailStatus]  DEFAULT ((0)) FOR [EmailStatus]
GO
ALTER TABLE [dbo].[Quote] ADD  DEFAULT ((0)) FOR [UsesNewRounding]
GO
ALTER TABLE [dbo].[QuoteLog] ADD  CONSTRAINT [DF_ReadCountQuoteId]  DEFAULT ((0)) FOR [ReadCount]
GO
ALTER TABLE [dbo].[QuoteLog] ADD  CONSTRAINT [DF_QuoteLogEmailStatus]  DEFAULT ((0)) FOR [EmailStatus]
GO
ALTER TABLE [dbo].[QuoteRow] ADD  DEFAULT ((0)) FOR [IsWorkCost]
GO
ALTER TABLE [dbo].[Supplier] ADD  DEFAULT (getdate()) FOR [CreatedUtc]
GO
ALTER TABLE [dbo].[Supplier] ADD  DEFAULT ((1)) FOR [Status]
GO
ALTER TABLE [dbo].[Supplier] ADD  DEFAULT ((0)) FOR [SelfEmployedWithoutFixedAddress]
GO
ALTER TABLE [dbo].[SupplierInvoice] ADD  DEFAULT ((0)) FOR [VATHigh]
GO
ALTER TABLE [dbo].[SupplierInvoice] ADD  DEFAULT ((0)) FOR [VATMedium]
GO
ALTER TABLE [dbo].[SupplierInvoice] ADD  DEFAULT ((0)) FOR [VATLow]
GO
ALTER TABLE [dbo].[SupplierInvoice] ADD  CONSTRAINT [DF_SupplierInvoice_Created]  DEFAULT (getutcdate()) FOR [CreatedUtc]
GO
ALTER TABLE [dbo].[SupplierInvoice] ADD  CONSTRAINT [DF_SupplierInvoice_SetOffAmountBaseCurrency]  DEFAULT ((0)) FOR [SetOffAmountBaseCurrency]
GO
ALTER TABLE [dbo].[SupplierInvoice] ADD  CONSTRAINT [DF_SupplierInvoice_SetOffAmountInvoiceCurrency]  DEFAULT ((0)) FOR [SetOffAmountInvoiceCurrency]
GO
ALTER TABLE [dbo].[SupplierInvoice] ADD  DEFAULT ((1)) FOR [Status]
GO
ALTER TABLE [dbo].[SupplierInvoice] ADD  DEFAULT ((0)) FOR [Origin]
GO
ALTER TABLE [dbo].[SupplierInvoice] ADD  DEFAULT ((0)) FOR [IsQuickInvoice]
GO
ALTER TABLE [dbo].[SupplierInvoice] ADD  DEFAULT ((0)) FOR [SelfEmployedWithoutFixedAddress]
GO
ALTER TABLE [dbo].[SupplierInvoice] ADD  CONSTRAINT [DF_ApprovalStatus]  DEFAULT ((0)) FOR [ApprovalStatus]
GO
ALTER TABLE [dbo].[SupplierInvoiceRow] ADD  CONSTRAINT [DF_SupplierInvoiceRowDoNoUseVatCode]  DEFAULT ((0)) FOR [DoNotUseVatCode]
GO
ALTER TABLE [dbo].[TermsOfPayment] ADD  DEFAULT ((0)) FOR [TermsofPaymentType]
GO
ALTER TABLE [dbo].[TermsOfPayment] ADD  DEFAULT ('0001-01-02') FOR [Changed]
GO
ALTER TABLE [dbo].[TermsOfPayment] ADD  DEFAULT ((1)) FOR [IsActive]
GO
ALTER TABLE [dbo].[TransactionFeedbackFileInformation] ADD  DEFAULT ((0)) FOR [TransactionType]
GO
ALTER TABLE [dbo].[User] ADD  CONSTRAINT [DF_User_IsDemoUser]  DEFAULT ((0)) FOR [IsDemoUser]
GO
ALTER TABLE [dbo].[User] ADD  CONSTRAINT [DF_User_Created]  DEFAULT (getdate()) FOR [CreatedUtc]
GO
ALTER TABLE [dbo].[User] ADD  DEFAULT ((1)) FOR [IsActive]
GO
ALTER TABLE [dbo].[User] ADD  DEFAULT ((2)) FOR [PermissionLevel]
GO
ALTER TABLE [dbo].[User] ADD  DEFAULT ((0)) FOR [IsRegisteredForAutoInvoice]
GO
ALTER TABLE [dbo].[User] ADD  DEFAULT ((1)) FOR [AccessToPayslip]
GO
ALTER TABLE [dbo].[User] ADD  CONSTRAINT [DF_AllowedToSendPayments]  DEFAULT ((1)) FOR [AllowedToSendPayments]
GO
ALTER TABLE [dbo].[User] ADD  CONSTRAINT [DF_ApprovalPermissionLevel]  DEFAULT ((0)) FOR [ApprovalPermissionLevel]
GO
ALTER TABLE [dbo].[UserConnection] ADD  DEFAULT (NULL) FOR [Disconnected]
GO
ALTER TABLE [dbo].[UserConnection] ADD  DEFAULT ((1)) FOR [IsConnected]
GO
ALTER TABLE [dbo].[UserConnection] ADD  DEFAULT ((0)) FOR [Reconnects]
GO
ALTER TABLE [dbo].[UserSettings] ADD  DEFAULT ((0)) FOR [SuppressQuoteMailWindow]
GO
ALTER TABLE [dbo].[UserSettings] ADD  DEFAULT ((0)) FOR [SuppressCustomerInvoiceMailWindow]
GO
ALTER TABLE [dbo].[UserSettings] ADD  DEFAULT ((0)) FOR [SuppressOrderMailWindow]
GO
ALTER TABLE [dbo].[UserSettings] ADD  DEFAULT ((0)) FOR [SuppressLimePurchaseAlert]
GO
ALTER TABLE [dbo].[UserSettings] ADD  DEFAULT ((0)) FOR [SuppressSupplierInvoiceExportInformation]
GO
ALTER TABLE [dbo].[UserSettings] ADD  DEFAULT ((0)) FOR [SuppressPhotoManagementTip]
GO
ALTER TABLE [dbo].[UserSettings] ADD  DEFAULT ((0)) FOR [SuppressCustomerAutoInvoiceMessage]
GO
ALTER TABLE [dbo].[UserSettings] ADD  DEFAULT ((0)) FOR [ShowPostingsIncVatInSupplierInvoice]
GO
ALTER TABLE [dbo].[UserSettings] ADD  DEFAULT ((0)) FOR [SuppressMultiPdfWarning]
GO
ALTER TABLE [dbo].[UserSettings] ADD  DEFAULT ((0)) FOR [SuppressHouseworkRules2016DueDate]
GO
ALTER TABLE [dbo].[UserSettings] ADD  DEFAULT ((0)) FOR [SuppressAutoinvoiceMarketingTip]
GO
ALTER TABLE [dbo].[UserSettings] ADD  DEFAULT ((0)) FOR [PrintoutsShowLedger]
GO
ALTER TABLE [dbo].[UserSettings] ADD  DEFAULT (NULL) FOR [ReconciliationPeriodTo]
GO
ALTER TABLE [dbo].[UserSettings] ADD  DEFAULT (NULL) FOR [ReconciliationPeriodFrom]
GO
ALTER TABLE [dbo].[UserSettings] ADD  DEFAULT ((0)) FOR [AccountSelectboxShowActive]
GO
ALTER TABLE [dbo].[UserSettings] ADD  CONSTRAINT [DF_SuppressAutoinvoicePriceInformation]  DEFAULT ((0)) FOR [SuppressAutoinvoicePriceInformation]
GO
ALTER TABLE [dbo].[UserSettings] ADD  CONSTRAINT [DF_SuppressPostToLedgerInvoiceAlert]  DEFAULT ((0)) FOR [SuppressPostToLedgerInvoiceAlert]
GO
ALTER TABLE [dbo].[UserSettings] ADD  CONSTRAINT [DF_SuppressNewPayrollTaxReportInformation]  DEFAULT ((0)) FOR [SuppressNewPayrollTaxReportInformation]
GO
ALTER TABLE [dbo].[VatReport] ADD  CONSTRAINT [DF_FiCorrectReason]  DEFAULT ((0)) FOR [FiCorrectReason]
GO
ALTER TABLE [dbo].[VatReport] ADD  CONSTRAINT [DF_SendToAuthorityStatus]  DEFAULT ((0)) FOR [SendToAuthorityStatus]
GO
ALTER TABLE [dbo].[VatReport] ADD  CONSTRAINT [DF_DocumentApprovalStatus]  DEFAULT ((0)) FOR [DocumentApprovalStatus]
GO
ALTER TABLE [dbo].[Voucher] ADD  DEFAULT ((0)) FOR [CorrectionType]
GO
ALTER TABLE [dbo].[Voucher] ADD  DEFAULT ((0)) FOR [HasInvoices]
GO
ALTER TABLE [dbo].[Voucher] ADD  DEFAULT ((0)) FOR [HasQuickInvoices]
GO
ALTER TABLE [dbo].[WebshopOrder] ADD  CONSTRAINT [DF_CustomerInvoiceDraft_Created]  DEFAULT (getdate()) FOR [Created]
GO
ALTER TABLE [dbo].[WebshopOrder] ADD  DEFAULT ((0)) FOR [CustomerIsPrivatePerson]
GO
ALTER TABLE [dbo].[Account]  WITH CHECK ADD  CONSTRAINT [FK_Account_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[Account] CHECK CONSTRAINT [FK_Account_Company]
GO
ALTER TABLE [dbo].[Account]  WITH CHECK ADD  CONSTRAINT [FK_Account_FiscalYear] FOREIGN KEY([FiscalYearId])
REFERENCES [dbo].[FiscalYear] ([Id])
GO
ALTER TABLE [dbo].[Account] CHECK CONSTRAINT [FK_Account_FiscalYear]
GO
ALTER TABLE [dbo].[Account]  WITH CHECK ADD  CONSTRAINT [FK_Account_User] FOREIGN KEY([ModifiedByUserId])
REFERENCES [dbo].[User] ([Id])
GO
ALTER TABLE [dbo].[Account] CHECK CONSTRAINT [FK_Account_User]
GO
ALTER TABLE [dbo].[Account]  WITH CHECK ADD  CONSTRAINT [FK_Account_VatCode] FOREIGN KEY([VatCodeId])
REFERENCES [dbo].[VatCode] ([Id])
GO
ALTER TABLE [dbo].[Account] CHECK CONSTRAINT [FK_Account_VatCode]
GO
ALTER TABLE [dbo].[AccountingPeriodLock]  WITH CHECK ADD  CONSTRAINT [FK_AccountingPeriodLock_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[AccountingPeriodLock] CHECK CONSTRAINT [FK_AccountingPeriodLock_Company]
GO
ALTER TABLE [dbo].[AccountingTemplate]  WITH CHECK ADD  CONSTRAINT [FK_AccountingTemplate_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[AccountingTemplate] CHECK CONSTRAINT [FK_AccountingTemplate_Company]
GO
ALTER TABLE [dbo].[AccountingTemplateRow]  WITH CHECK ADD  CONSTRAINT [FK_AccountingTemplateRow_AccountingTemplate] FOREIGN KEY([AccountingTemplateId])
REFERENCES [dbo].[AccountingTemplate] ([Id])
GO
ALTER TABLE [dbo].[AccountingTemplateRow] CHECK CONSTRAINT [FK_AccountingTemplateRow_AccountingTemplate]
GO
ALTER TABLE [dbo].[AccountingTemplateRow]  WITH CHECK ADD  CONSTRAINT [FK_AccountingTemplateRow_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[AccountingTemplateRow] CHECK CONSTRAINT [FK_AccountingTemplateRow_Company]
GO
ALTER TABLE [dbo].[AccountRange]  WITH CHECK ADD  CONSTRAINT [FK_AccountRange_ChartOfAccountsTemplate] FOREIGN KEY([ChartOfAccountsInfoId])
REFERENCES [dbo].[ChartOfAccountsInfo] ([Id])
GO
ALTER TABLE [dbo].[AccountRange] CHECK CONSTRAINT [FK_AccountRange_ChartOfAccountsTemplate]
GO
ALTER TABLE [dbo].[AccountReceivableTermsOfPaymentRelation]  WITH CHECK ADD  CONSTRAINT [FK_AccountPaymentService_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[AccountReceivableTermsOfPaymentRelation] CHECK CONSTRAINT [FK_AccountPaymentService_Company]
GO
ALTER TABLE [dbo].[AccountReceivableTermsOfPaymentRelation]  WITH CHECK ADD  CONSTRAINT [FK_AccountTermsOfPaymentRelation_TermsOfPayment] FOREIGN KEY([TermsOfPaymentId])
REFERENCES [dbo].[TermsOfPayment] ([Id])
GO
ALTER TABLE [dbo].[AccountReceivableTermsOfPaymentRelation] CHECK CONSTRAINT [FK_AccountTermsOfPaymentRelation_TermsOfPayment]
GO
ALTER TABLE [dbo].[AccountValuationHistory]  WITH CHECK ADD  CONSTRAINT [FK_AccountValuationHistory_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[AccountValuationHistory] CHECK CONSTRAINT [FK_AccountValuationHistory_Company]
GO
ALTER TABLE [dbo].[AccountValuationHistory]  WITH CHECK ADD  CONSTRAINT [FK_AccountValuationHistory_CostCenterItem] FOREIGN KEY([CostCenterItemId])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[AccountValuationHistory] CHECK CONSTRAINT [FK_AccountValuationHistory_CostCenterItem]
GO
ALTER TABLE [dbo].[AccountValuationHistory]  WITH CHECK ADD  CONSTRAINT [FK_AccountValuationHistory_FiscalYear] FOREIGN KEY([FiscalYearId])
REFERENCES [dbo].[FiscalYear] ([Id])
GO
ALTER TABLE [dbo].[AccountValuationHistory] CHECK CONSTRAINT [FK_AccountValuationHistory_FiscalYear]
GO
ALTER TABLE [dbo].[AllocationPeriod]  WITH CHECK ADD  CONSTRAINT [FK_AllocationPeriod_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[AllocationPeriod] CHECK CONSTRAINT [FK_AllocationPeriod_Company]
GO
ALTER TABLE [dbo].[AllocationPeriod]  WITH CHECK ADD  CONSTRAINT [FK_AllocationPeriod_SupplierInvoice] FOREIGN KEY([SupplierInvoiceId])
REFERENCES [dbo].[SupplierInvoice] ([Id])
GO
ALTER TABLE [dbo].[AllocationPeriod] CHECK CONSTRAINT [FK_AllocationPeriod_SupplierInvoice]
GO
ALTER TABLE [dbo].[AllocationPeriod]  WITH CHECK ADD  CONSTRAINT [FK_AllocationPeriod_SupplierInvoiceRow] FOREIGN KEY([SupplierInvoiceRowId])
REFERENCES [dbo].[SupplierInvoiceRow] ([Id])
GO
ALTER TABLE [dbo].[AllocationPeriod] CHECK CONSTRAINT [FK_AllocationPeriod_SupplierInvoiceRow]
GO
ALTER TABLE [dbo].[AllocationPeriod]  WITH CHECK ADD  CONSTRAINT [FK_AllocationPeriod_Voucher] FOREIGN KEY([VoucherId])
REFERENCES [dbo].[Voucher] ([Id])
GO
ALTER TABLE [dbo].[AllocationPeriod] CHECK CONSTRAINT [FK_AllocationPeriod_Voucher]
GO
ALTER TABLE [dbo].[AllocationPeriod]  WITH CHECK ADD  CONSTRAINT [FK_AllocationPeriod_Voucher_Manual] FOREIGN KEY([ManualVoucherId])
REFERENCES [dbo].[Voucher] ([Id])
GO
ALTER TABLE [dbo].[AllocationPeriod] CHECK CONSTRAINT [FK_AllocationPeriod_Voucher_Manual]
GO
ALTER TABLE [dbo].[AllocationPeriod]  WITH CHECK ADD  CONSTRAINT [FK_AllocationPeriod_VoucherRow] FOREIGN KEY([CompanyId], [ManualVoucherId], [ManualVoucherRowLine])
REFERENCES [dbo].[VoucherRow] ([CompanyId], [VoucherId], [Line])
GO
ALTER TABLE [dbo].[AllocationPeriod] CHECK CONSTRAINT [FK_AllocationPeriod_VoucherRow]
GO
ALTER TABLE [dbo].[AllocationPeriodRow]  WITH CHECK ADD  CONSTRAINT [FK_AllocationPeriodRow_AllocationPeriod] FOREIGN KEY([CompanyId], [AllocationPeriodId])
REFERENCES [dbo].[AllocationPeriod] ([CompanyId], [Id])
GO
ALTER TABLE [dbo].[AllocationPeriodRow] CHECK CONSTRAINT [FK_AllocationPeriodRow_AllocationPeriod]
GO
ALTER TABLE [dbo].[AllocationPeriodRow]  WITH CHECK ADD  CONSTRAINT [FK_AllocationPeriodRow_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[AllocationPeriodRow] CHECK CONSTRAINT [FK_AllocationPeriodRow_Company]
GO
ALTER TABLE [dbo].[Article]  WITH CHECK ADD  CONSTRAINT [FK_Article_ArticleAccountCoding] FOREIGN KEY([ArticleAccountCodingId])
REFERENCES [dbo].[ArticleAccountCoding] ([Id])
GO
ALTER TABLE [dbo].[Article] CHECK CONSTRAINT [FK_Article_ArticleAccountCoding]
GO
ALTER TABLE [dbo].[Article]  WITH CHECK ADD  CONSTRAINT [FK_Article_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[Article] CHECK CONSTRAINT [FK_Article_Company]
GO
ALTER TABLE [dbo].[Article]  WITH CHECK ADD  CONSTRAINT [FK_Article_Unit] FOREIGN KEY([UnitId])
REFERENCES [dbo].[Unit] ([Id])
GO
ALTER TABLE [dbo].[Article] CHECK CONSTRAINT [FK_Article_Unit]
GO
ALTER TABLE [dbo].[ArticleAccountCoding]  WITH CHECK ADD  CONSTRAINT [FK_ArticleAccountCoding_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[ArticleAccountCoding] CHECK CONSTRAINT [FK_ArticleAccountCoding_Company]
GO
ALTER TABLE [dbo].[ArticleAccountCoding]  WITH CHECK ADD  CONSTRAINT [FK_ArticleAccountCoding_VatRate] FOREIGN KEY([VatRateId])
REFERENCES [dbo].[VatRate] ([Id])
GO
ALTER TABLE [dbo].[ArticleAccountCoding] CHECK CONSTRAINT [FK_ArticleAccountCoding_VatRate]
GO
ALTER TABLE [dbo].[ArticleLabel]  WITH CHECK ADD  CONSTRAINT [FK_ArticleLabel_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[ArticleLabel] CHECK CONSTRAINT [FK_ArticleLabel_Company]
GO
ALTER TABLE [dbo].[ArticlePriceHistory]  WITH CHECK ADD  CONSTRAINT [FK_ArticlePriceHistory_Article] FOREIGN KEY([ArticleId])
REFERENCES [dbo].[Article] ([Id])
GO
ALTER TABLE [dbo].[ArticlePriceHistory] CHECK CONSTRAINT [FK_ArticlePriceHistory_Article]
GO
ALTER TABLE [dbo].[ArticlePriceHistory]  WITH CHECK ADD  CONSTRAINT [FK_ArticlePriceHistory_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[ArticlePriceHistory] CHECK CONSTRAINT [FK_ArticlePriceHistory_Company]
GO
ALTER TABLE [dbo].[AutoInvoiceInboundDocument]  WITH CHECK ADD  CONSTRAINT [FK_AutoInvoiceInboundDocument_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[AutoInvoiceInboundDocument] CHECK CONSTRAINT [FK_AutoInvoiceInboundDocument_Company]
GO
ALTER TABLE [dbo].[AutoInvoiceInboundDocument]  WITH CHECK ADD  CONSTRAINT [FK_AutoInvoiceInboundDocument_Document] FOREIGN KEY([DocumentId])
REFERENCES [dbo].[Document] ([Id])
GO
ALTER TABLE [dbo].[AutoInvoiceInboundDocument] CHECK CONSTRAINT [FK_AutoInvoiceInboundDocument_Document]
GO
ALTER TABLE [dbo].[AutoInvoiceInboundDocument]  WITH CHECK ADD  CONSTRAINT [FK_AutoInvoiceInboundDocument_SupplierInvoice] FOREIGN KEY([SupplierInvoiceId])
REFERENCES [dbo].[SupplierInvoice] ([Id])
GO
ALTER TABLE [dbo].[AutoInvoiceInboundDocument] CHECK CONSTRAINT [FK_AutoInvoiceInboundDocument_SupplierInvoice]
GO
ALTER TABLE [dbo].[AutoInvoiceInboundDocumentAttachment]  WITH CHECK ADD  CONSTRAINT [FK_AutoInvoiceInboundDocumentAttachment_AutoInvoiceInboundDocument] FOREIGN KEY([AutoInvoiceInboundDocumentId])
REFERENCES [dbo].[AutoInvoiceInboundDocument] ([Id])
GO
ALTER TABLE [dbo].[AutoInvoiceInboundDocumentAttachment] CHECK CONSTRAINT [FK_AutoInvoiceInboundDocumentAttachment_AutoInvoiceInboundDocument]
GO
ALTER TABLE [dbo].[AutoInvoiceInboundDocumentAttachment]  WITH CHECK ADD  CONSTRAINT [FK_AutoInvoiceInboundDocumentAttachment_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[AutoInvoiceInboundDocumentAttachment] CHECK CONSTRAINT [FK_AutoInvoiceInboundDocumentAttachment_Company]
GO
ALTER TABLE [dbo].[AutoInvoiceInboundDocumentAttachment]  WITH CHECK ADD  CONSTRAINT [FK_AutoInvoiceInboundDocumentAttachment_Document] FOREIGN KEY([DocumentId])
REFERENCES [dbo].[Document] ([Id])
GO
ALTER TABLE [dbo].[AutoInvoiceInboundDocumentAttachment] CHECK CONSTRAINT [FK_AutoInvoiceInboundDocumentAttachment_Document]
GO
ALTER TABLE [dbo].[AutoInvoiceInterimSupplier]  WITH CHECK ADD  CONSTRAINT [FK_AutoInvoiceInterimSupplier_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[AutoInvoiceInterimSupplier] CHECK CONSTRAINT [FK_AutoInvoiceInterimSupplier_Company]
GO
ALTER TABLE [dbo].[AutoInvoiceInterimSupplier]  WITH CHECK ADD  CONSTRAINT [FK_AutoInvoiceInterimSupplier_CompanyBankAccount] FOREIGN KEY([CompanyBankAccountId])
REFERENCES [dbo].[CompanyBankAccount] ([Id])
GO
ALTER TABLE [dbo].[AutoInvoiceInterimSupplier] CHECK CONSTRAINT [FK_AutoInvoiceInterimSupplier_CompanyBankAccount]
GO
ALTER TABLE [dbo].[AutoInvoiceInterimSupplier]  WITH CHECK ADD  CONSTRAINT [FK_AutoInvoiceInterimSupplier_TermsOfPayment] FOREIGN KEY([TermsOfPaymentId])
REFERENCES [dbo].[TermsOfPayment] ([Id])
GO
ALTER TABLE [dbo].[AutoInvoiceInterimSupplier] CHECK CONSTRAINT [FK_AutoInvoiceInterimSupplier_TermsOfPayment]
GO
ALTER TABLE [dbo].[AutoInvoiceOutboundStatus]  WITH CHECK ADD  CONSTRAINT [FK_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[AutoInvoiceOutboundStatus] CHECK CONSTRAINT [FK_Company]
GO
ALTER TABLE [dbo].[AutoInvoiceOutboundStatus]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoice] FOREIGN KEY([CustomerInvoiceId])
REFERENCES [dbo].[CustomerInvoice] ([Id])
GO
ALTER TABLE [dbo].[AutoInvoiceOutboundStatus] CHECK CONSTRAINT [FK_CustomerInvoice]
GO
ALTER TABLE [dbo].[AutoInvoiceSIMessage]  WITH CHECK ADD  CONSTRAINT [FK_AutoInvoiceSIMessage_BankAccount] FOREIGN KEY([BankAccountId])
REFERENCES [dbo].[CompanyBankAccount] ([Id])
GO
ALTER TABLE [dbo].[AutoInvoiceSIMessage] CHECK CONSTRAINT [FK_AutoInvoiceSIMessage_BankAccount]
GO
ALTER TABLE [dbo].[AutoInvoiceSIMessage]  WITH CHECK ADD  CONSTRAINT [FK_AutoInvoiceSIMessage_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[AutoInvoiceSIMessage] CHECK CONSTRAINT [FK_AutoInvoiceSIMessage_Company]
GO
ALTER TABLE [dbo].[Bank]  WITH CHECK ADD  CONSTRAINT [FK_Bank_Country] FOREIGN KEY([CountryCode])
REFERENCES [dbo].[Country] ([Code])
GO
ALTER TABLE [dbo].[Bank] CHECK CONSTRAINT [FK_Bank_Country]
GO
ALTER TABLE [dbo].[BankAccountTransfer]  WITH CHECK ADD  CONSTRAINT [FK_BankAccountTransfer_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[BankAccountTransfer] CHECK CONSTRAINT [FK_BankAccountTransfer_Company]
GO
ALTER TABLE [dbo].[BankAccountTransfer]  WITH CHECK ADD  CONSTRAINT [FK_BankAccountTransfer_CompanyBankAccount] FOREIGN KEY([BankAccountId])
REFERENCES [dbo].[CompanyBankAccount] ([Id])
GO
ALTER TABLE [dbo].[BankAccountTransfer] CHECK CONSTRAINT [FK_BankAccountTransfer_CompanyBankAccount]
GO
ALTER TABLE [dbo].[BankAccountTransferRow]  WITH CHECK ADD  CONSTRAINT [FK_BankAccountTransferRow_BankAccountTransfer] FOREIGN KEY([BankAccountTransferId])
REFERENCES [dbo].[BankAccountTransfer] ([Id])
GO
ALTER TABLE [dbo].[BankAccountTransferRow] CHECK CONSTRAINT [FK_BankAccountTransferRow_BankAccountTransfer]
GO
ALTER TABLE [dbo].[BankAccountTransferRow]  WITH CHECK ADD  CONSTRAINT [FK_BankAccountTransferRow_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[BankAccountTransferRow] CHECK CONSTRAINT [FK_BankAccountTransferRow_Company]
GO
ALTER TABLE [dbo].[BankAccountTransferRow]  WITH CHECK ADD  CONSTRAINT [FK_BankAccountTransferRow_Project] FOREIGN KEY([ProjectId])
REFERENCES [dbo].[Project] ([Id])
GO
ALTER TABLE [dbo].[BankAccountTransferRow] CHECK CONSTRAINT [FK_BankAccountTransferRow_Project]
GO
ALTER TABLE [dbo].[BankAccountTransferRow]  WITH CHECK ADD  CONSTRAINT [FK_BankAccountTransferRow_VatCode] FOREIGN KEY([VatCodeId])
REFERENCES [dbo].[VatCode] ([Id])
GO
ALTER TABLE [dbo].[BankAccountTransferRow] CHECK CONSTRAINT [FK_BankAccountTransferRow_VatCode]
GO
ALTER TABLE [dbo].[BankIntegrationInformationDnbNor]  WITH CHECK ADD  CONSTRAINT [FK_BankIntegrationInformationDnbNor_Bank] FOREIGN KEY([BankId])
REFERENCES [dbo].[Bank] ([Id])
GO
ALTER TABLE [dbo].[BankIntegrationInformationDnbNor] CHECK CONSTRAINT [FK_BankIntegrationInformationDnbNor_Bank]
GO
ALTER TABLE [dbo].[BankIntegrationInformationDnbNor]  WITH CHECK ADD  CONSTRAINT [FK_BankIntegrationInformationDnbNor_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[BankIntegrationInformationDnbNor] CHECK CONSTRAINT [FK_BankIntegrationInformationDnbNor_Company]
GO
ALTER TABLE [dbo].[BankTransaction]  WITH CHECK ADD  CONSTRAINT [FK_BankTransaction_BankTransactionBatch] FOREIGN KEY([BankTransactionBatchId])
REFERENCES [dbo].[BankTransactionBatch] ([Id])
GO
ALTER TABLE [dbo].[BankTransaction] CHECK CONSTRAINT [FK_BankTransaction_BankTransactionBatch]
GO
ALTER TABLE [dbo].[BankTransaction]  WITH CHECK ADD  CONSTRAINT [FK_BankTransaction_BusinessTransactionId] FOREIGN KEY([BusinessTransactionId])
REFERENCES [dbo].[BusinessTransaction] ([Id])
GO
ALTER TABLE [dbo].[BankTransaction] CHECK CONSTRAINT [FK_BankTransaction_BusinessTransactionId]
GO
ALTER TABLE [dbo].[BankTransaction]  WITH CHECK ADD  CONSTRAINT [FK_BankTransaction_ChargeCurrency] FOREIGN KEY([ChargeCurrency])
REFERENCES [dbo].[Currency] ([Code])
GO
ALTER TABLE [dbo].[BankTransaction] CHECK CONSTRAINT [FK_BankTransaction_ChargeCurrency]
GO
ALTER TABLE [dbo].[BankTransaction]  WITH CHECK ADD  CONSTRAINT [FK_BankTransaction_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[BankTransaction] CHECK CONSTRAINT [FK_BankTransaction_Company]
GO
ALTER TABLE [dbo].[BankTransaction]  WITH CHECK ADD  CONSTRAINT [FK_BankTransaction_CompanyBankAccountId] FOREIGN KEY([CompanyBankAccountId])
REFERENCES [dbo].[CompanyBankAccount] ([Id])
GO
ALTER TABLE [dbo].[BankTransaction] CHECK CONSTRAINT [FK_BankTransaction_CompanyBankAccountId]
GO
ALTER TABLE [dbo].[BankTransaction]  WITH CHECK ADD  CONSTRAINT [FK_BankTransaction_OriginalAmountCurrency] FOREIGN KEY([OriginalAmountCurrency])
REFERENCES [dbo].[Currency] ([Code])
GO
ALTER TABLE [dbo].[BankTransaction] CHECK CONSTRAINT [FK_BankTransaction_OriginalAmountCurrency]
GO
ALTER TABLE [dbo].[BankTransaction]  WITH CHECK ADD  CONSTRAINT [FK_BankTransaction_TransactionFeedbackFileInformation] FOREIGN KEY([TransactionFeedbackFileInformationId])
REFERENCES [dbo].[TransactionFeedbackFileInformation] ([Id])
GO
ALTER TABLE [dbo].[BankTransaction] CHECK CONSTRAINT [FK_BankTransaction_TransactionFeedbackFileInformation]
GO
ALTER TABLE [dbo].[BankTransactionBatch]  WITH CHECK ADD  CONSTRAINT [FK_BankTransactionBatch_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[BankTransactionBatch] CHECK CONSTRAINT [FK_BankTransactionBatch_Company]
GO
ALTER TABLE [dbo].[BankTransactionBatch]  WITH CHECK ADD  CONSTRAINT [FK_BankTransactionBatch_CompanyBankAccount] FOREIGN KEY([CompanyBankAccountId])
REFERENCES [dbo].[CompanyBankAccount] ([Id])
GO
ALTER TABLE [dbo].[BankTransactionBatch] CHECK CONSTRAINT [FK_BankTransactionBatch_CompanyBankAccount]
GO
ALTER TABLE [dbo].[BankTransactionReconciliation]  WITH CHECK ADD  CONSTRAINT [FK_BankTransactionReconciliation_BankTransaction] FOREIGN KEY([BankTransactionId])
REFERENCES [dbo].[BankTransaction] ([Id])
GO
ALTER TABLE [dbo].[BankTransactionReconciliation] CHECK CONSTRAINT [FK_BankTransactionReconciliation_BankTransaction]
GO
ALTER TABLE [dbo].[BankTransactionReconciliation]  WITH CHECK ADD  CONSTRAINT [FK_BankTransactionReconciliation_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[BankTransactionReconciliation] CHECK CONSTRAINT [FK_BankTransactionReconciliation_Company]
GO
ALTER TABLE [dbo].[BankTransactionReconciliation]  WITH CHECK ADD  CONSTRAINT [FK_BankTransactionReconciliation_User] FOREIGN KEY([UserId])
REFERENCES [dbo].[User] ([Id])
GO
ALTER TABLE [dbo].[BankTransactionReconciliation] CHECK CONSTRAINT [FK_BankTransactionReconciliation_User]
GO
ALTER TABLE [dbo].[BankTransactionReconciliationRow]  WITH CHECK ADD  CONSTRAINT [FK_BankTransactionReconciliationRow_BankTransactionReconciliation] FOREIGN KEY([BankTransactionReconciliationId])
REFERENCES [dbo].[BankTransactionReconciliation] ([Id])
GO
ALTER TABLE [dbo].[BankTransactionReconciliationRow] CHECK CONSTRAINT [FK_BankTransactionReconciliationRow_BankTransactionReconciliation]
GO
ALTER TABLE [dbo].[BankTransactionReconciliationRow]  WITH CHECK ADD  CONSTRAINT [FK_BankTransactionReconciliationRow_BusinessTransactionReconciliation] FOREIGN KEY([BusinessTransactionId])
REFERENCES [dbo].[BusinessTransaction] ([Id])
GO
ALTER TABLE [dbo].[BankTransactionReconciliationRow] CHECK CONSTRAINT [FK_BankTransactionReconciliationRow_BusinessTransactionReconciliation]
GO
ALTER TABLE [dbo].[BankTransactionReconciliationRow]  WITH CHECK ADD  CONSTRAINT [FK_BankTransactionReconciliationRow_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[BankTransactionReconciliationRow] CHECK CONSTRAINT [FK_BankTransactionReconciliationRow_Company]
GO
ALTER TABLE [dbo].[BankTransactionReconciliationRow]  WITH CHECK ADD  CONSTRAINT [FK_BankTransactionReconciliationRow_PaymentVoucher] FOREIGN KEY([PaymentVoucherId])
REFERENCES [dbo].[Voucher] ([Id])
GO
ALTER TABLE [dbo].[BankTransactionReconciliationRow] CHECK CONSTRAINT [FK_BankTransactionReconciliationRow_PaymentVoucher]
GO
ALTER TABLE [dbo].[BusinessTransaction]  WITH CHECK ADD  CONSTRAINT [FK_BusinessTransaction_BaseCurrency] FOREIGN KEY([BaseCurrency])
REFERENCES [dbo].[Currency] ([Code])
GO
ALTER TABLE [dbo].[BusinessTransaction] CHECK CONSTRAINT [FK_BusinessTransaction_BaseCurrency]
GO
ALTER TABLE [dbo].[BusinessTransaction]  WITH CHECK ADD  CONSTRAINT [FK_BusinessTransaction_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[BusinessTransaction] CHECK CONSTRAINT [FK_BusinessTransaction_Company]
GO
ALTER TABLE [dbo].[BusinessTransaction]  WITH CHECK ADD  CONSTRAINT [FK_BusinessTransaction_CompanyBankAccount] FOREIGN KEY([CompanyBankAccountId])
REFERENCES [dbo].[CompanyBankAccount] ([Id])
GO
ALTER TABLE [dbo].[BusinessTransaction] CHECK CONSTRAINT [FK_BusinessTransaction_CompanyBankAccount]
GO
ALTER TABLE [dbo].[BusinessTransaction]  WITH CHECK ADD  CONSTRAINT [FK_BusinessTransaction_TransactionCurrency] FOREIGN KEY([TransactionCurrency])
REFERENCES [dbo].[Currency] ([Code])
GO
ALTER TABLE [dbo].[BusinessTransaction] CHECK CONSTRAINT [FK_BusinessTransaction_TransactionCurrency]
GO
ALTER TABLE [dbo].[BusinessTransaction]  WITH CHECK ADD  CONSTRAINT [FK_BusinessTransaction_Voucher] FOREIGN KEY([VoucherId])
REFERENCES [dbo].[Voucher] ([Id])
GO
ALTER TABLE [dbo].[BusinessTransaction] CHECK CONSTRAINT [FK_BusinessTransaction_Voucher]
GO
ALTER TABLE [dbo].[BusinessTransactionReconciliation]  WITH CHECK ADD  CONSTRAINT [FK_BusinessTransactionReconciliation_BankBusinessTransaction] FOREIGN KEY([BankBusinessTransactionId])
REFERENCES [dbo].[BusinessTransaction] ([Id])
GO
ALTER TABLE [dbo].[BusinessTransactionReconciliation] CHECK CONSTRAINT [FK_BusinessTransactionReconciliation_BankBusinessTransaction]
GO
ALTER TABLE [dbo].[BusinessTransactionReconciliationRow]  WITH CHECK ADD  CONSTRAINT [FK_BusinessTransactionReconciliationRow_BankBusinessTransaction] FOREIGN KEY([BankBusinessTransactionId])
REFERENCES [dbo].[BusinessTransaction] ([Id])
GO
ALTER TABLE [dbo].[BusinessTransactionReconciliationRow] CHECK CONSTRAINT [FK_BusinessTransactionReconciliationRow_BankBusinessTransaction]
GO
ALTER TABLE [dbo].[BusinessTransactionReconciliationRow]  WITH CHECK ADD  CONSTRAINT [FK_BusinessTransactionReconciliationRow_EventBusinessTransaction] FOREIGN KEY([EventBusinessTransactionId])
REFERENCES [dbo].[BusinessTransaction] ([Id])
GO
ALTER TABLE [dbo].[BusinessTransactionReconciliationRow] CHECK CONSTRAINT [FK_BusinessTransactionReconciliationRow_EventBusinessTransaction]
GO
ALTER TABLE [dbo].[ChartOfAccountsExtension]  WITH CHECK ADD  CONSTRAINT [FK_ChartOfAccountsExtension_ChartOfAccountsInfo] FOREIGN KEY([ChartOfAccountsInfoId])
REFERENCES [dbo].[ChartOfAccountsInfo] ([Id])
GO
ALTER TABLE [dbo].[ChartOfAccountsExtension] CHECK CONSTRAINT [FK_ChartOfAccountsExtension_ChartOfAccountsInfo]
GO
ALTER TABLE [dbo].[ChartOfAccountsExtension]  WITH CHECK ADD  CONSTRAINT [FK_ChartOfAccountsExtension_VatCode] FOREIGN KEY([VatCodeId])
REFERENCES [dbo].[VatCode] ([Id])
GO
ALTER TABLE [dbo].[ChartOfAccountsExtension] CHECK CONSTRAINT [FK_ChartOfAccountsExtension_VatCode]
GO
ALTER TABLE [dbo].[ChartOfAccountsInfo]  WITH CHECK ADD  CONSTRAINT [FK_ChartOfAccountsInfo_Country] FOREIGN KEY([CountryCode])
REFERENCES [dbo].[Country] ([Code])
GO
ALTER TABLE [dbo].[ChartOfAccountsInfo] CHECK CONSTRAINT [FK_ChartOfAccountsInfo_Country]
GO
ALTER TABLE [dbo].[ChartOfAccountsTemplate]  WITH CHECK ADD  CONSTRAINT [FK_ChartOfAccountsTemplate_ChartOfAccountsInfo] FOREIGN KEY([ChartOfAccountsInfoId])
REFERENCES [dbo].[ChartOfAccountsInfo] ([Id])
GO
ALTER TABLE [dbo].[ChartOfAccountsTemplate] CHECK CONSTRAINT [FK_ChartOfAccountsTemplate_ChartOfAccountsInfo]
GO
ALTER TABLE [dbo].[ChartOfAccountsTemplate]  WITH CHECK ADD  CONSTRAINT [FK_ChartOfAccountsTemplate_VatCode] FOREIGN KEY([VatCodeId])
REFERENCES [dbo].[VatCode] ([Id])
GO
ALTER TABLE [dbo].[ChartOfAccountsTemplate] CHECK CONSTRAINT [FK_ChartOfAccountsTemplate_VatCode]
GO
ALTER TABLE [dbo].[Company]  WITH CHECK ADD  CONSTRAINT [FK_Company_Company] FOREIGN KEY([PreviousCompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[Company] CHECK CONSTRAINT [FK_Company_Company]
GO
ALTER TABLE [dbo].[Company]  WITH CHECK ADD  CONSTRAINT [FK_Company_Country] FOREIGN KEY([CountryCode])
REFERENCES [dbo].[Country] ([Code])
GO
ALTER TABLE [dbo].[Company] CHECK CONSTRAINT [FK_Company_Country]
GO
ALTER TABLE [dbo].[Company]  WITH CHECK ADD  CONSTRAINT [FK_Company_Currency] FOREIGN KEY([BaseCurrencyCode])
REFERENCES [dbo].[Currency] ([Code])
GO
ALTER TABLE [dbo].[Company] CHECK CONSTRAINT [FK_Company_Currency]
GO
ALTER TABLE [dbo].[CompanyBankAccount]  WITH CHECK ADD  CONSTRAINT [FK_CompanyBankAccount_Bank] FOREIGN KEY([BankId])
REFERENCES [dbo].[Bank] ([Id])
GO
ALTER TABLE [dbo].[CompanyBankAccount] CHECK CONSTRAINT [FK_CompanyBankAccount_Bank]
GO
ALTER TABLE [dbo].[CompanyBankAccount]  WITH CHECK ADD  CONSTRAINT [FK_CompanyBankAccount_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[CompanyBankAccount] CHECK CONSTRAINT [FK_CompanyBankAccount_Company]
GO
ALTER TABLE [dbo].[CompanyBankAccount]  WITH CHECK ADD  CONSTRAINT [FK_CompanyBankAccount_Currency] FOREIGN KEY([CurrencyCode])
REFERENCES [dbo].[Currency] ([Code])
GO
ALTER TABLE [dbo].[CompanyBankAccount] CHECK CONSTRAINT [FK_CompanyBankAccount_Currency]
GO
ALTER TABLE [dbo].[CompanyEvent]  WITH CHECK ADD  CONSTRAINT [FK_CompanyEvent_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[CompanyEvent] CHECK CONSTRAINT [FK_CompanyEvent_Company]
GO
ALTER TABLE [dbo].[CompanyExtra]  WITH CHECK ADD  CONSTRAINT [FK_CompanyExtra_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[CompanyExtra] CHECK CONSTRAINT [FK_CompanyExtra_Company]
GO
ALTER TABLE [dbo].[CompanyNumberSeries]  WITH CHECK ADD  CONSTRAINT [FK_CompanyNumberSeries_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[CompanyNumberSeries] CHECK CONSTRAINT [FK_CompanyNumberSeries_Company]
GO
ALTER TABLE [dbo].[CompanyText]  WITH CHECK ADD  CONSTRAINT [FK_CompanyText_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[CompanyText] CHECK CONSTRAINT [FK_CompanyText_Company]
GO
ALTER TABLE [dbo].[CompanyVoucherSeries]  WITH CHECK ADD  CONSTRAINT [FK_CompanyVoucherSeries_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[CompanyVoucherSeries] CHECK CONSTRAINT [FK_CompanyVoucherSeries_Company]
GO
ALTER TABLE [dbo].[CostCenter]  WITH CHECK ADD  CONSTRAINT [FK_CostCenter_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[CostCenter] CHECK CONSTRAINT [FK_CostCenter_Company]
GO
ALTER TABLE [dbo].[CostCenterItem]  WITH CHECK ADD  CONSTRAINT [FK_CostCenterItem_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[CostCenterItem] CHECK CONSTRAINT [FK_CostCenterItem_Company]
GO
ALTER TABLE [dbo].[CostCenterItem]  WITH CHECK ADD  CONSTRAINT [FK_CostCenterItem_CostCenter] FOREIGN KEY([CostCenterId])
REFERENCES [dbo].[CostCenter] ([Id])
GO
ALTER TABLE [dbo].[CostCenterItem] CHECK CONSTRAINT [FK_CostCenterItem_CostCenter]
GO
ALTER TABLE [dbo].[Customer]  WITH CHECK ADD  CONSTRAINT [FK_Customer_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[Customer] CHECK CONSTRAINT [FK_Customer_Company]
GO
ALTER TABLE [dbo].[Customer]  WITH CHECK ADD  CONSTRAINT [FK_Customer_Currency] FOREIGN KEY([CurrencyCode])
REFERENCES [dbo].[Currency] ([Code])
GO
ALTER TABLE [dbo].[Customer] CHECK CONSTRAINT [FK_Customer_Currency]
GO
ALTER TABLE [dbo].[Customer]  WITH CHECK ADD  CONSTRAINT [FK_Customer_InvoiceCountry] FOREIGN KEY([InvoiceCountryCode])
REFERENCES [dbo].[Country] ([Code])
GO
ALTER TABLE [dbo].[Customer] CHECK CONSTRAINT [FK_Customer_InvoiceCountry]
GO
ALTER TABLE [dbo].[Customer]  WITH CHECK ADD  CONSTRAINT [FK_Customer_TermsOfPayment] FOREIGN KEY([TermsOfPaymentId])
REFERENCES [dbo].[TermsOfPayment] ([Id])
GO
ALTER TABLE [dbo].[Customer] CHECK CONSTRAINT [FK_Customer_TermsOfPayment]
GO
ALTER TABLE [dbo].[CustomerEmailAddress]  WITH CHECK ADD  CONSTRAINT [FK_CustomerEmailAddress_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[CustomerEmailAddress] CHECK CONSTRAINT [FK_CustomerEmailAddress_Company]
GO
ALTER TABLE [dbo].[CustomerEmailAddress]  WITH CHECK ADD  CONSTRAINT [FK_CustomerEmailAddress_Customer] FOREIGN KEY([CustomerId])
REFERENCES [dbo].[Customer] ([CustomerId])
GO
ALTER TABLE [dbo].[CustomerEmailAddress] CHECK CONSTRAINT [FK_CustomerEmailAddress_Customer]
GO
ALTER TABLE [dbo].[CustomerInvoice]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoice_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoice] CHECK CONSTRAINT [FK_CustomerInvoice_Company]
GO
ALTER TABLE [dbo].[CustomerInvoice]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoice_Country] FOREIGN KEY([CompanyCountryCode])
REFERENCES [dbo].[Country] ([Code])
GO
ALTER TABLE [dbo].[CustomerInvoice] CHECK CONSTRAINT [FK_CustomerInvoice_Country]
GO
ALTER TABLE [dbo].[CustomerInvoice]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoice_Currency] FOREIGN KEY([CurrencyCode])
REFERENCES [dbo].[Currency] ([Code])
GO
ALTER TABLE [dbo].[CustomerInvoice] CHECK CONSTRAINT [FK_CustomerInvoice_Currency]
GO
ALTER TABLE [dbo].[CustomerInvoice]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoice_Customer] FOREIGN KEY([CustomerId])
REFERENCES [dbo].[Customer] ([CustomerId])
GO
ALTER TABLE [dbo].[CustomerInvoice] CHECK CONSTRAINT [FK_CustomerInvoice_Customer]
GO
ALTER TABLE [dbo].[CustomerInvoice]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoice_CustomerInvoice] FOREIGN KEY([ReferringId])
REFERENCES [dbo].[CustomerInvoice] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoice] CHECK CONSTRAINT [FK_CustomerInvoice_CustomerInvoice]
GO
ALTER TABLE [dbo].[CustomerInvoice]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoice_CustomerInvoiceDraft] FOREIGN KEY([CreatedFromWebshopOrderId])
REFERENCES [dbo].[WebshopOrder] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoice] CHECK CONSTRAINT [FK_CustomerInvoice_CustomerInvoiceDraft]
GO
ALTER TABLE [dbo].[CustomerInvoice]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoice_Discount] FOREIGN KEY([DiscountId])
REFERENCES [dbo].[Discount] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoice] CHECK CONSTRAINT [FK_CustomerInvoice_Discount]
GO
ALTER TABLE [dbo].[CustomerInvoice]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoice_Order] FOREIGN KEY([OrderId])
REFERENCES [dbo].[Order] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoice] CHECK CONSTRAINT [FK_CustomerInvoice_Order]
GO
ALTER TABLE [dbo].[CustomerInvoice]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoice_Quote] FOREIGN KEY([QuoteId])
REFERENCES [dbo].[Quote] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoice] CHECK CONSTRAINT [FK_CustomerInvoice_Quote]
GO
ALTER TABLE [dbo].[CustomerInvoice]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoice_TermsOfPayment] FOREIGN KEY([TermsOfPaymentId])
REFERENCES [dbo].[TermsOfPayment] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoice] CHECK CONSTRAINT [FK_CustomerInvoice_TermsOfPayment]
GO
ALTER TABLE [dbo].[CustomerInvoice]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoice_User] FOREIGN KEY([CreatedByUserId])
REFERENCES [dbo].[User] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoice] CHECK CONSTRAINT [FK_CustomerInvoice_User]
GO
ALTER TABLE [dbo].[CustomerInvoice]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoice_Voucher] FOREIGN KEY([VoucherId])
REFERENCES [dbo].[Voucher] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoice] CHECK CONSTRAINT [FK_CustomerInvoice_Voucher]
GO
ALTER TABLE [dbo].[CustomerInvoice]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceCustomerCountryCode_Country] FOREIGN KEY([InvoiceCountryCode])
REFERENCES [dbo].[Country] ([Code])
GO
ALTER TABLE [dbo].[CustomerInvoice] CHECK CONSTRAINT [FK_CustomerInvoiceCustomerCountryCode_Country]
GO
ALTER TABLE [dbo].[CustomerInvoiceDocument]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDocument_CustomerInvoice] FOREIGN KEY([CustomerInvoiceId])
REFERENCES [dbo].[CustomerInvoice] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceDocument] CHECK CONSTRAINT [FK_CustomerInvoiceDocument_CustomerInvoice]
GO
ALTER TABLE [dbo].[CustomerInvoiceDocument]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDocument_Document] FOREIGN KEY([DocumentId])
REFERENCES [dbo].[Document] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceDocument] CHECK CONSTRAINT [FK_CustomerInvoiceDocument_Document]
GO
ALTER TABLE [dbo].[CustomerInvoiceDraft]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDraft_Company1] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceDraft] CHECK CONSTRAINT [FK_CustomerInvoiceDraft_Company1]
GO
ALTER TABLE [dbo].[CustomerInvoiceDraft]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDraft_Customer1] FOREIGN KEY([CustomerId])
REFERENCES [dbo].[Customer] ([CustomerId])
GO
ALTER TABLE [dbo].[CustomerInvoiceDraft] CHECK CONSTRAINT [FK_CustomerInvoiceDraft_Customer1]
GO
ALTER TABLE [dbo].[CustomerInvoiceDraft]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDraft_TermsOfPayment2] FOREIGN KEY([TermsOfPaymentId])
REFERENCES [dbo].[TermsOfPayment] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceDraft] CHECK CONSTRAINT [FK_CustomerInvoiceDraft_TermsOfPayment2]
GO
ALTER TABLE [dbo].[CustomerInvoiceDraftPerson]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDraftPerson_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceDraftPerson] CHECK CONSTRAINT [FK_CustomerInvoiceDraftPerson_Company]
GO
ALTER TABLE [dbo].[CustomerInvoiceDraftPerson]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDraftPerson_CustomerInvoiceDraft] FOREIGN KEY([CustomerInvoiceDraftId])
REFERENCES [dbo].[CustomerInvoiceDraft] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceDraftPerson] CHECK CONSTRAINT [FK_CustomerInvoiceDraftPerson_CustomerInvoiceDraft]
GO
ALTER TABLE [dbo].[CustomerInvoiceDraftRow]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDraftRow_Article1] FOREIGN KEY([ArticleId])
REFERENCES [dbo].[Article] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceDraftRow] CHECK CONSTRAINT [FK_CustomerInvoiceDraftRow_Article1]
GO
ALTER TABLE [dbo].[CustomerInvoiceDraftRow]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDraftRow_Company1] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceDraftRow] CHECK CONSTRAINT [FK_CustomerInvoiceDraftRow_Company1]
GO
ALTER TABLE [dbo].[CustomerInvoiceDraftRow]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDraftRow_CostCenterItem1] FOREIGN KEY([CostCenterItemId1])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceDraftRow] CHECK CONSTRAINT [FK_CustomerInvoiceDraftRow_CostCenterItem1]
GO
ALTER TABLE [dbo].[CustomerInvoiceDraftRow]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDraftRow_CostCenterItem2] FOREIGN KEY([CostCenterItemId2])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceDraftRow] CHECK CONSTRAINT [FK_CustomerInvoiceDraftRow_CostCenterItem2]
GO
ALTER TABLE [dbo].[CustomerInvoiceDraftRow]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDraftRow_CostCenterItem3] FOREIGN KEY([CostCenterItemId3])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceDraftRow] CHECK CONSTRAINT [FK_CustomerInvoiceDraftRow_CostCenterItem3]
GO
ALTER TABLE [dbo].[CustomerInvoiceDraftRow]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDraftRow_CustomerInvoiceDraft1] FOREIGN KEY([CustomerInvoiceDraftId])
REFERENCES [dbo].[CustomerInvoiceDraft] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceDraftRow] CHECK CONSTRAINT [FK_CustomerInvoiceDraftRow_CustomerInvoiceDraft1]
GO
ALTER TABLE [dbo].[CustomerInvoiceDraftRow]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDraftRow_Project] FOREIGN KEY([ProjectId])
REFERENCES [dbo].[Project] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceDraftRow] CHECK CONSTRAINT [FK_CustomerInvoiceDraftRow_Project]
GO
ALTER TABLE [dbo].[CustomerInvoiceLatePaymentFee]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceLatePaymentFee_CustomerInvoice] FOREIGN KEY([CustomerInvoiceId])
REFERENCES [dbo].[CustomerInvoice] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceLatePaymentFee] CHECK CONSTRAINT [FK_CustomerInvoiceLatePaymentFee_CustomerInvoice]
GO
ALTER TABLE [dbo].[CustomerInvoiceLog]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceLog_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceLog] CHECK CONSTRAINT [FK_CustomerInvoiceLog_Company]
GO
ALTER TABLE [dbo].[CustomerInvoiceLog]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceLog_CustomerInvoice] FOREIGN KEY([CustomerInvoiceId])
REFERENCES [dbo].[CustomerInvoice] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceLog] CHECK CONSTRAINT [FK_CustomerInvoiceLog_CustomerInvoice]
GO
ALTER TABLE [dbo].[CustomerInvoicePersonRow]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoicePersonRow_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoicePersonRow] CHECK CONSTRAINT [FK_CustomerInvoicePersonRow_Company]
GO
ALTER TABLE [dbo].[CustomerInvoicePersonRow]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoicePersonRow_CustomerInvoice] FOREIGN KEY([CustomerInvoiceId])
REFERENCES [dbo].[CustomerInvoice] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoicePersonRow] CHECK CONSTRAINT [FK_CustomerInvoicePersonRow_CustomerInvoice]
GO
ALTER TABLE [dbo].[CustomerInvoiceRow]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceRow_Article] FOREIGN KEY([ArticleId])
REFERENCES [dbo].[Article] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceRow] CHECK CONSTRAINT [FK_CustomerInvoiceRow_Article]
GO
ALTER TABLE [dbo].[CustomerInvoiceRow]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceRow_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceRow] CHECK CONSTRAINT [FK_CustomerInvoiceRow_Company]
GO
ALTER TABLE [dbo].[CustomerInvoiceRow]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceRow_CostCenterItem1] FOREIGN KEY([CostCenterItemId1])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceRow] CHECK CONSTRAINT [FK_CustomerInvoiceRow_CostCenterItem1]
GO
ALTER TABLE [dbo].[CustomerInvoiceRow]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceRow_CostCenterItem2] FOREIGN KEY([CostCenterItemId2])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceRow] CHECK CONSTRAINT [FK_CustomerInvoiceRow_CostCenterItem2]
GO
ALTER TABLE [dbo].[CustomerInvoiceRow]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceRow_CostCenterItem3] FOREIGN KEY([CostCenterItemId3])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceRow] CHECK CONSTRAINT [FK_CustomerInvoiceRow_CostCenterItem3]
GO
ALTER TABLE [dbo].[CustomerInvoiceRow]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceRow_CustomerInvoice] FOREIGN KEY([CustomerInvoiceId])
REFERENCES [dbo].[CustomerInvoice] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceRow] CHECK CONSTRAINT [FK_CustomerInvoiceRow_CustomerInvoice]
GO
ALTER TABLE [dbo].[CustomerInvoiceRow]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceRow_Project] FOREIGN KEY([ProjectId])
REFERENCES [dbo].[Project] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceRow] CHECK CONSTRAINT [FK_CustomerInvoiceRow_Project]
GO
ALTER TABLE [dbo].[CustomerInvoiceRow]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceRow_Unit] FOREIGN KEY([UnitId])
REFERENCES [dbo].[Unit] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceRow] CHECK CONSTRAINT [FK_CustomerInvoiceRow_Unit]
GO
ALTER TABLE [dbo].[CustomerInvoiceValuationHistory]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceValuationHistory_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceValuationHistory] CHECK CONSTRAINT [FK_CustomerInvoiceValuationHistory_Company]
GO
ALTER TABLE [dbo].[CustomerInvoiceValuationHistory]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceValuationHistory_CustomerInvoice] FOREIGN KEY([CustomerInvoiceId])
REFERENCES [dbo].[CustomerInvoice] ([Id])
GO
ALTER TABLE [dbo].[CustomerInvoiceValuationHistory] CHECK CONSTRAINT [FK_CustomerInvoiceValuationHistory_CustomerInvoice]
GO
ALTER TABLE [dbo].[CustomerLabel]  WITH CHECK ADD  CONSTRAINT [FK_CustomerLabel_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[CustomerLabel] CHECK CONSTRAINT [FK_CustomerLabel_Company]
GO
ALTER TABLE [dbo].[DeliveryMethod]  WITH CHECK ADD  CONSTRAINT [FK_DeliveryMethod_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[DeliveryMethod] CHECK CONSTRAINT [FK_DeliveryMethod_Company]
GO
ALTER TABLE [dbo].[DeliveryTerm]  WITH CHECK ADD  CONSTRAINT [FK_DeliveryTerm_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[DeliveryTerm] CHECK CONSTRAINT [FK_DeliveryTerm_Company]
GO
ALTER TABLE [dbo].[Discount]  WITH CHECK ADD  CONSTRAINT [FK_Discount_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[Discount] CHECK CONSTRAINT [FK_Discount_Company]
GO
ALTER TABLE [dbo].[DiscountLine]  WITH CHECK ADD  CONSTRAINT [FK_DiscountLine_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[DiscountLine] CHECK CONSTRAINT [FK_DiscountLine_Company]
GO
ALTER TABLE [dbo].[DiscountLine]  WITH CHECK ADD  CONSTRAINT [FK_DiscountLine_Discount] FOREIGN KEY([DiscountId])
REFERENCES [dbo].[Discount] ([Id])
GO
ALTER TABLE [dbo].[DiscountLine] CHECK CONSTRAINT [FK_DiscountLine_Discount]
GO
ALTER TABLE [dbo].[Document]  WITH CHECK ADD  CONSTRAINT [FK_Document_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[Document] CHECK CONSTRAINT [FK_Document_Company]
GO
ALTER TABLE [dbo].[EmployerReport]  WITH CHECK ADD  CONSTRAINT [FK_EmployerReport_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[EmployerReport] CHECK CONSTRAINT [FK_EmployerReport_Company]
GO
ALTER TABLE [dbo].[EmployerReport]  WITH CHECK ADD  CONSTRAINT [FK_EmployerReport_CountryCode] FOREIGN KEY([CountryCode])
REFERENCES [dbo].[Country] ([Code])
GO
ALTER TABLE [dbo].[EmployerReport] CHECK CONSTRAINT [FK_EmployerReport_CountryCode]
GO
ALTER TABLE [dbo].[EmployerReport]  WITH CHECK ADD  CONSTRAINT [FK_EmployerReport_VoucherId] FOREIGN KEY([VoucherId])
REFERENCES [dbo].[Voucher] ([Id])
GO
ALTER TABLE [dbo].[EmployerReport] CHECK CONSTRAINT [FK_EmployerReport_VoucherId]
GO
ALTER TABLE [dbo].[ExportJOU]  WITH CHECK ADD  CONSTRAINT [FK_ExportJOU_Company] FOREIGN KEY([CompanyID])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[ExportJOU] CHECK CONSTRAINT [FK_ExportJOU_Company]
GO
ALTER TABLE [dbo].[ExportRotRut]  WITH CHECK ADD  CONSTRAINT [FK_ExportRotRut_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[ExportRotRut] CHECK CONSTRAINT [FK_ExportRotRut_Company]
GO
ALTER TABLE [dbo].[FiscalYear]  WITH CHECK ADD  CONSTRAINT [FK_FiscalYear_ChartOfAccountsInfo] FOREIGN KEY([ChartOfAccountsInfoId])
REFERENCES [dbo].[ChartOfAccountsInfo] ([Id])
GO
ALTER TABLE [dbo].[FiscalYear] CHECK CONSTRAINT [FK_FiscalYear_ChartOfAccountsInfo]
GO
ALTER TABLE [dbo].[FiscalYear]  WITH CHECK ADD  CONSTRAINT [FK_FiscalYear_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[FiscalYear] CHECK CONSTRAINT [FK_FiscalYear_Company]
GO
ALTER TABLE [dbo].[FiscalYear]  WITH CHECK ADD  CONSTRAINT [FK_FiscalYear_User] FOREIGN KEY([CreatedByUserId])
REFERENCES [dbo].[User] ([Id])
GO
ALTER TABLE [dbo].[FiscalYear] CHECK CONSTRAINT [FK_FiscalYear_User]
GO
ALTER TABLE [dbo].[FiscalYearCheckListItem]  WITH CHECK ADD  CONSTRAINT [FK_FiscalYearCheckListItems_FiscalYearCheckListItem] FOREIGN KEY([DependentOnId])
REFERENCES [dbo].[FiscalYearCheckListItem] ([Id])
GO
ALTER TABLE [dbo].[FiscalYearCheckListItem] CHECK CONSTRAINT [FK_FiscalYearCheckListItems_FiscalYearCheckListItem]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries]  WITH CHECK ADD  CONSTRAINT [FK_FiscalYearNumberSeries_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] CHECK CONSTRAINT [FK_FiscalYearNumberSeries_Company]
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries]  WITH CHECK ADD  CONSTRAINT [FK_FiscalYearNumberSeries_FiscalYear] FOREIGN KEY([FiscalYearId])
REFERENCES [dbo].[FiscalYear] ([Id])
GO
ALTER TABLE [dbo].[FiscalYearNumberSeries] CHECK CONSTRAINT [FK_FiscalYearNumberSeries_FiscalYear]
GO
ALTER TABLE [dbo].[ForeignPaymentCode]  WITH CHECK ADD  CONSTRAINT [FK_ForeignPaymentCode_Country] FOREIGN KEY([CountryCode])
REFERENCES [dbo].[Country] ([Code])
GO
ALTER TABLE [dbo].[ForeignPaymentCode] CHECK CONSTRAINT [FK_ForeignPaymentCode_Country]
GO
ALTER TABLE [dbo].[ImportStatus]  WITH CHECK ADD  CONSTRAINT [FK_ImportStatus_ImportStatus] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[ImportStatus] CHECK CONSTRAINT [FK_ImportStatus_ImportStatus]
GO
ALTER TABLE [dbo].[InventoryAccountingTemplate]  WITH CHECK ADD  CONSTRAINT [FK_InventoryAccountingTemplate_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[InventoryAccountingTemplate] CHECK CONSTRAINT [FK_InventoryAccountingTemplate_Company]
GO
ALTER TABLE [dbo].[InventoryEvent]  WITH CHECK ADD  CONSTRAINT [FK_InventoryEvent_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[InventoryEvent] CHECK CONSTRAINT [FK_InventoryEvent_Company]
GO
ALTER TABLE [dbo].[InventoryEvent]  WITH CHECK ADD  CONSTRAINT [FK_InventoryEvent_InventoryItem] FOREIGN KEY([InventoryItemId])
REFERENCES [dbo].[InventoryItem] ([Id])
GO
ALTER TABLE [dbo].[InventoryEvent] CHECK CONSTRAINT [FK_InventoryEvent_InventoryItem]
GO
ALTER TABLE [dbo].[InventoryEvent]  WITH CHECK ADD  CONSTRAINT [FK_InventoryEvent_UndoVoucher] FOREIGN KEY([UndoVoucherId])
REFERENCES [dbo].[Voucher] ([Id])
GO
ALTER TABLE [dbo].[InventoryEvent] CHECK CONSTRAINT [FK_InventoryEvent_UndoVoucher]
GO
ALTER TABLE [dbo].[InventoryEvent]  WITH CHECK ADD  CONSTRAINT [FK_InventoryEvent_Voucher] FOREIGN KEY([VoucherId])
REFERENCES [dbo].[Voucher] ([Id])
GO
ALTER TABLE [dbo].[InventoryEvent] CHECK CONSTRAINT [FK_InventoryEvent_Voucher]
GO
ALTER TABLE [dbo].[InventoryItem]  WITH CHECK ADD  CONSTRAINT [FK_InventoryItem_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[InventoryItem] CHECK CONSTRAINT [FK_InventoryItem_Company]
GO
ALTER TABLE [dbo].[InventoryItem]  WITH CHECK ADD  CONSTRAINT [FK_InventoryItem_CostCenterItem1] FOREIGN KEY([CostCenterItemId1])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[InventoryItem] CHECK CONSTRAINT [FK_InventoryItem_CostCenterItem1]
GO
ALTER TABLE [dbo].[InventoryItem]  WITH CHECK ADD  CONSTRAINT [FK_InventoryItem_CostCenterItem2] FOREIGN KEY([CostCenterItemId2])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[InventoryItem] CHECK CONSTRAINT [FK_InventoryItem_CostCenterItem2]
GO
ALTER TABLE [dbo].[InventoryItem]  WITH CHECK ADD  CONSTRAINT [FK_InventoryItem_CostCenterItem3] FOREIGN KEY([CostCenterItemId3])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[InventoryItem] CHECK CONSTRAINT [FK_InventoryItem_CostCenterItem3]
GO
ALTER TABLE [dbo].[InventoryItem]  WITH CHECK ADD  CONSTRAINT [FK_InventoryItem_InventoryAccountingTemplate] FOREIGN KEY([InventoryAccountingTemplateId])
REFERENCES [dbo].[InventoryAccountingTemplate] ([Id])
GO
ALTER TABLE [dbo].[InventoryItem] CHECK CONSTRAINT [FK_InventoryItem_InventoryAccountingTemplate]
GO
ALTER TABLE [dbo].[InventoryItem]  WITH CHECK ADD  CONSTRAINT [FK_InventoryItem_Project] FOREIGN KEY([ProjectId])
REFERENCES [dbo].[Project] ([Id])
GO
ALTER TABLE [dbo].[InventoryItem] CHECK CONSTRAINT [FK_InventoryItem_Project]
GO
ALTER TABLE [dbo].[IZettleFinanceTransaction]  WITH CHECK ADD  CONSTRAINT [FK_IZettleFinanceTransaction_CompanyId] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[IZettleFinanceTransaction] CHECK CONSTRAINT [FK_IZettleFinanceTransaction_CompanyId]
GO
ALTER TABLE [dbo].[IZettleFinanceTransaction]  WITH CHECK ADD  CONSTRAINT [FK_IZettleFinanceTransaction_VoucherId] FOREIGN KEY([VoucherId])
REFERENCES [dbo].[Voucher] ([Id])
GO
ALTER TABLE [dbo].[IZettleFinanceTransaction] CHECK CONSTRAINT [FK_IZettleFinanceTransaction_VoucherId]
GO
ALTER TABLE [dbo].[IZettleIntegration]  WITH CHECK ADD  CONSTRAINT [FK_IZettleIntegration_CompanyId] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[IZettleIntegration] CHECK CONSTRAINT [FK_IZettleIntegration_CompanyId]
GO
ALTER TABLE [dbo].[IZettlePurchase]  WITH CHECK ADD  CONSTRAINT [FK_IZettlePurchase_CompanyId] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[IZettlePurchase] CHECK CONSTRAINT [FK_IZettlePurchase_CompanyId]
GO
ALTER TABLE [dbo].[IZettlePurchase]  WITH CHECK ADD  CONSTRAINT [FK_IZettlePurchase_CurrencyCode] FOREIGN KEY([CurrencyCode])
REFERENCES [dbo].[Currency] ([Code])
GO
ALTER TABLE [dbo].[IZettlePurchase] CHECK CONSTRAINT [FK_IZettlePurchase_CurrencyCode]
GO
ALTER TABLE [dbo].[IZettlePurchase]  WITH CHECK ADD  CONSTRAINT [FK_IZettlePurchase_VoucherId] FOREIGN KEY([VoucherId])
REFERENCES [dbo].[Voucher] ([Id])
GO
ALTER TABLE [dbo].[IZettlePurchase] CHECK CONSTRAINT [FK_IZettlePurchase_VoucherId]
GO
ALTER TABLE [dbo].[IZettlePurchaseRow]  WITH CHECK ADD  CONSTRAINT [FK_IZettlePurchaseRow_CompanyId] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[IZettlePurchaseRow] CHECK CONSTRAINT [FK_IZettlePurchaseRow_CompanyId]
GO
ALTER TABLE [dbo].[IZettlePurchaseRow]  WITH CHECK ADD  CONSTRAINT [FK_IZettlePurchaseRow_IZettlePurchaseId] FOREIGN KEY([IZettlePurchaseId])
REFERENCES [dbo].[IZettlePurchase] ([Id])
GO
ALTER TABLE [dbo].[IZettlePurchaseRow] CHECK CONSTRAINT [FK_IZettlePurchaseRow_IZettlePurchaseId]
GO
ALTER TABLE [dbo].[JournalEntry]  WITH CHECK ADD  CONSTRAINT [FK_JournalEntry_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[JournalEntry] CHECK CONSTRAINT [FK_JournalEntry_Company]
GO
ALTER TABLE [dbo].[Message]  WITH CHECK ADD  CONSTRAINT [FK_Message_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[Message] CHECK CONSTRAINT [FK_Message_Company]
GO
ALTER TABLE [dbo].[Message]  WITH CHECK ADD  CONSTRAINT [FK_Message_MessageThread] FOREIGN KEY([MessageThreadId])
REFERENCES [dbo].[MessageThread] ([Id])
GO
ALTER TABLE [dbo].[Message] CHECK CONSTRAINT [FK_Message_MessageThread]
GO
ALTER TABLE [dbo].[Message]  WITH CHECK ADD  CONSTRAINT [FK_Message_User] FOREIGN KEY([CreatedByUserId])
REFERENCES [dbo].[User] ([Id])
GO
ALTER TABLE [dbo].[Message] CHECK CONSTRAINT [FK_Message_User]
GO
ALTER TABLE [dbo].[MessageReceiver]  WITH CHECK ADD  CONSTRAINT [FK_MessageReceiver_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[MessageReceiver] CHECK CONSTRAINT [FK_MessageReceiver_Company]
GO
ALTER TABLE [dbo].[MessageReceiver]  WITH CHECK ADD  CONSTRAINT [FK_MessageReceiver_MessageThread] FOREIGN KEY([MessageThreadId])
REFERENCES [dbo].[MessageThread] ([Id])
GO
ALTER TABLE [dbo].[MessageReceiver] CHECK CONSTRAINT [FK_MessageReceiver_MessageThread]
GO
ALTER TABLE [dbo].[MessageReceiver]  WITH CHECK ADD  CONSTRAINT [FK_MessageReceiver_User] FOREIGN KEY([UserId])
REFERENCES [dbo].[User] ([Id])
GO
ALTER TABLE [dbo].[MessageReceiver] CHECK CONSTRAINT [FK_MessageReceiver_User]
GO
ALTER TABLE [dbo].[MessageThread]  WITH CHECK ADD  CONSTRAINT [FK_MessageThread_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[MessageThread] CHECK CONSTRAINT [FK_MessageThread_Company]
GO
ALTER TABLE [dbo].[MobileDevice]  WITH CHECK ADD  CONSTRAINT [FK_MobileDevice_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[MobileDevice] CHECK CONSTRAINT [FK_MobileDevice_Company]
GO
ALTER TABLE [dbo].[MobileDevice]  WITH CHECK ADD  CONSTRAINT [FK_MobileDevice_User] FOREIGN KEY([UserId])
REFERENCES [dbo].[User] ([Id])
GO
ALTER TABLE [dbo].[MobileDevice] CHECK CONSTRAINT [FK_MobileDevice_User]
GO
ALTER TABLE [dbo].[MossCode]  WITH CHECK ADD  CONSTRAINT [FK_MossCode_CountryCode] FOREIGN KEY([CountryCode])
REFERENCES [dbo].[Country] ([Code])
GO
ALTER TABLE [dbo].[MossCode] CHECK CONSTRAINT [FK_MossCode_CountryCode]
GO
ALTER TABLE [dbo].[NifImportHistory]  WITH CHECK ADD  CONSTRAINT [FK_NifImportHistory_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[NifImportHistory] CHECK CONSTRAINT [FK_NifImportHistory_Company]
GO
ALTER TABLE [dbo].[NifImportHistory]  WITH CHECK ADD  CONSTRAINT [FK_NifImportHistory_FiscalYear] FOREIGN KEY([FiscalYearId])
REFERENCES [dbo].[FiscalYear] ([Id])
GO
ALTER TABLE [dbo].[NifImportHistory] CHECK CONSTRAINT [FK_NifImportHistory_FiscalYear]
GO
ALTER TABLE [dbo].[NifImportHistory]  WITH CHECK ADD  CONSTRAINT [FK_NifImportHistory_Voucher] FOREIGN KEY([VoucherId])
REFERENCES [dbo].[Voucher] ([Id])
GO
ALTER TABLE [dbo].[NifImportHistory] CHECK CONSTRAINT [FK_NifImportHistory_Voucher]
GO
ALTER TABLE [dbo].[NifImportSettings]  WITH CHECK ADD  CONSTRAINT [FK_NifImportSettings_CompanyId] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[NifIntegration] ([CompanyId])
GO
ALTER TABLE [dbo].[NifImportSettings] CHECK CONSTRAINT [FK_NifImportSettings_CompanyId]
GO
ALTER TABLE [dbo].[NifImportSettings]  WITH CHECK ADD  CONSTRAINT [FK_NifImportSettings_CostCenterItemId1] FOREIGN KEY([CostCenterItemId1])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[NifImportSettings] CHECK CONSTRAINT [FK_NifImportSettings_CostCenterItemId1]
GO
ALTER TABLE [dbo].[NifImportSettings]  WITH CHECK ADD  CONSTRAINT [FK_NifImportSettings_CostCenterItemId2] FOREIGN KEY([CostCenterItemId2])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[NifImportSettings] CHECK CONSTRAINT [FK_NifImportSettings_CostCenterItemId2]
GO
ALTER TABLE [dbo].[NifImportSettings]  WITH CHECK ADD  CONSTRAINT [FK_NifImportSettings_CostCenterItemId3] FOREIGN KEY([CostCenterItemId3])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[NifImportSettings] CHECK CONSTRAINT [FK_NifImportSettings_CostCenterItemId3]
GO
ALTER TABLE [dbo].[NifIntegration]  WITH CHECK ADD  CONSTRAINT [FK_NifIntegration_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[NifIntegration] CHECK CONSTRAINT [FK_NifIntegration_Company]
GO
ALTER TABLE [dbo].[NifIntegration]  WITH CHECK ADD  CONSTRAINT [FK_NifIntegration_User] FOREIGN KEY([ActivationRequestedByUserId])
REFERENCES [dbo].[User] ([Id])
GO
ALTER TABLE [dbo].[NifIntegration] CHECK CONSTRAINT [FK_NifIntegration_User]
GO
ALTER TABLE [dbo].[Notification]  WITH CHECK ADD  CONSTRAINT [FK_Notification_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[Notification] CHECK CONSTRAINT [FK_Notification_Company]
GO
ALTER TABLE [dbo].[Notification]  WITH CHECK ADD  CONSTRAINT [FK_Notification_User] FOREIGN KEY([UserId])
REFERENCES [dbo].[User] ([Id])
GO
ALTER TABLE [dbo].[Notification] CHECK CONSTRAINT [FK_Notification_User]
GO
ALTER TABLE [dbo].[NotificationArgument]  WITH CHECK ADD  CONSTRAINT [FK_NotificationArgument_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[NotificationArgument] CHECK CONSTRAINT [FK_NotificationArgument_Company]
GO
ALTER TABLE [dbo].[NotificationArgument]  WITH CHECK ADD  CONSTRAINT [FK_NotificationArgument_Notification] FOREIGN KEY([NotificationId])
REFERENCES [dbo].[Notification] ([Id])
GO
ALTER TABLE [dbo].[NotificationArgument] CHECK CONSTRAINT [FK_NotificationArgument_Notification]
GO
ALTER TABLE [dbo].[OcrGiroAmountRecord]  WITH CHECK ADD  CONSTRAINT [FK_OcrGiroAmountRecord_BankTransaction] FOREIGN KEY([BankTransactionId])
REFERENCES [dbo].[BankTransaction] ([Id])
GO
ALTER TABLE [dbo].[OcrGiroAmountRecord] CHECK CONSTRAINT [FK_OcrGiroAmountRecord_BankTransaction]
GO
ALTER TABLE [dbo].[OcrGiroAmountRecord]  WITH CHECK ADD  CONSTRAINT [FK_OcrGiroAmountRecord_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[OcrGiroAmountRecord] CHECK CONSTRAINT [FK_OcrGiroAmountRecord_Company]
GO
ALTER TABLE [dbo].[OcrGiroAmountRecord]  WITH CHECK ADD  CONSTRAINT [FK_OcrGiroAmountRecord_CompanyBankAccount] FOREIGN KEY([CompanyBankAccountId])
REFERENCES [dbo].[CompanyBankAccount] ([Id])
GO
ALTER TABLE [dbo].[OcrGiroAmountRecord] CHECK CONSTRAINT [FK_OcrGiroAmountRecord_CompanyBankAccount]
GO
ALTER TABLE [dbo].[Order]  WITH CHECK ADD  CONSTRAINT [FK_Order_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[Order] CHECK CONSTRAINT [FK_Order_Company]
GO
ALTER TABLE [dbo].[Order]  WITH CHECK ADD  CONSTRAINT [FK_Order_Country] FOREIGN KEY([InvoiceCountryCode])
REFERENCES [dbo].[Country] ([Code])
GO
ALTER TABLE [dbo].[Order] CHECK CONSTRAINT [FK_Order_Country]
GO
ALTER TABLE [dbo].[Order]  WITH CHECK ADD  CONSTRAINT [FK_Order_Country1] FOREIGN KEY([DeliveryCountryCode])
REFERENCES [dbo].[Country] ([Code])
GO
ALTER TABLE [dbo].[Order] CHECK CONSTRAINT [FK_Order_Country1]
GO
ALTER TABLE [dbo].[Order]  WITH CHECK ADD  CONSTRAINT [FK_Order_Customer] FOREIGN KEY([CustomerId])
REFERENCES [dbo].[Customer] ([CustomerId])
GO
ALTER TABLE [dbo].[Order] CHECK CONSTRAINT [FK_Order_Customer]
GO
ALTER TABLE [dbo].[Order]  WITH CHECK ADD  CONSTRAINT [FK_Order_Order] FOREIGN KEY([OriginatingOrderId])
REFERENCES [dbo].[Order] ([Id])
GO
ALTER TABLE [dbo].[Order] CHECK CONSTRAINT [FK_Order_Order]
GO
ALTER TABLE [dbo].[Order]  WITH CHECK ADD  CONSTRAINT [FK_Order_Quote] FOREIGN KEY([OriginatingQuoteId])
REFERENCES [dbo].[Quote] ([Id])
GO
ALTER TABLE [dbo].[Order] CHECK CONSTRAINT [FK_Order_Quote]
GO
ALTER TABLE [dbo].[Order]  WITH CHECK ADD  CONSTRAINT [FK_Order_TermsOfPayment] FOREIGN KEY([TermsOfPaymentId])
REFERENCES [dbo].[TermsOfPayment] ([Id])
GO
ALTER TABLE [dbo].[Order] CHECK CONSTRAINT [FK_Order_TermsOfPayment]
GO
ALTER TABLE [dbo].[OrderLog]  WITH CHECK ADD  CONSTRAINT [FK_OrderLog_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[OrderLog] CHECK CONSTRAINT [FK_OrderLog_Company]
GO
ALTER TABLE [dbo].[OrderLog]  WITH CHECK ADD  CONSTRAINT [FK_OrderLog_Order] FOREIGN KEY([OrderId])
REFERENCES [dbo].[Order] ([Id])
GO
ALTER TABLE [dbo].[OrderLog] CHECK CONSTRAINT [FK_OrderLog_Order]
GO
ALTER TABLE [dbo].[OrderPerson]  WITH CHECK ADD  CONSTRAINT [FK_OrderPerson_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[OrderPerson] CHECK CONSTRAINT [FK_OrderPerson_Company]
GO
ALTER TABLE [dbo].[OrderPerson]  WITH CHECK ADD  CONSTRAINT [FK_OrderPerson_Order] FOREIGN KEY([OrderId])
REFERENCES [dbo].[Order] ([Id])
GO
ALTER TABLE [dbo].[OrderPerson] CHECK CONSTRAINT [FK_OrderPerson_Order]
GO
ALTER TABLE [dbo].[OrderRow]  WITH CHECK ADD  CONSTRAINT [FK_OrderRow_Article] FOREIGN KEY([ArticleId])
REFERENCES [dbo].[Article] ([Id])
GO
ALTER TABLE [dbo].[OrderRow] CHECK CONSTRAINT [FK_OrderRow_Article]
GO
ALTER TABLE [dbo].[OrderRow]  WITH CHECK ADD  CONSTRAINT [FK_OrderRow_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[OrderRow] CHECK CONSTRAINT [FK_OrderRow_Company]
GO
ALTER TABLE [dbo].[OrderRow]  WITH CHECK ADD  CONSTRAINT [FK_OrderRow_CostCenterItem1] FOREIGN KEY([CostCenterItemId1])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[OrderRow] CHECK CONSTRAINT [FK_OrderRow_CostCenterItem1]
GO
ALTER TABLE [dbo].[OrderRow]  WITH CHECK ADD  CONSTRAINT [FK_OrderRow_CostCenterItem2] FOREIGN KEY([CostCenterItemId2])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[OrderRow] CHECK CONSTRAINT [FK_OrderRow_CostCenterItem2]
GO
ALTER TABLE [dbo].[OrderRow]  WITH CHECK ADD  CONSTRAINT [FK_OrderRow_CostCenterItem3] FOREIGN KEY([CostCenterItemId3])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[OrderRow] CHECK CONSTRAINT [FK_OrderRow_CostCenterItem3]
GO
ALTER TABLE [dbo].[OrderRow]  WITH CHECK ADD  CONSTRAINT [FK_OrderRow_Order] FOREIGN KEY([OrderId])
REFERENCES [dbo].[Order] ([Id])
GO
ALTER TABLE [dbo].[OrderRow] CHECK CONSTRAINT [FK_OrderRow_Order]
GO
ALTER TABLE [dbo].[OrderRow]  WITH CHECK ADD  CONSTRAINT [FK_OrderRow_Project] FOREIGN KEY([ProjectId])
REFERENCES [dbo].[Project] ([Id])
GO
ALTER TABLE [dbo].[OrderRow] CHECK CONSTRAINT [FK_OrderRow_Project]
GO
ALTER TABLE [dbo].[PartnerResourceLink]  WITH CHECK ADD  CONSTRAINT [FK_PartnerResourceLink_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[PartnerResourceLink] CHECK CONSTRAINT [FK_PartnerResourceLink_Company]
GO
ALTER TABLE [dbo].[Payment]  WITH CHECK ADD  CONSTRAINT [FK_Payment_Bank] FOREIGN KEY([SenderBankId])
REFERENCES [dbo].[Bank] ([Id])
GO
ALTER TABLE [dbo].[Payment] CHECK CONSTRAINT [FK_Payment_Bank]
GO
ALTER TABLE [dbo].[Payment]  WITH CHECK ADD  CONSTRAINT [FK_Payment_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[Payment] CHECK CONSTRAINT [FK_Payment_Company]
GO
ALTER TABLE [dbo].[Payment]  WITH CHECK ADD  CONSTRAINT [FK_Payment_PaymentBatch] FOREIGN KEY([PaymentBatchId])
REFERENCES [dbo].[PaymentBatch] ([Id])
GO
ALTER TABLE [dbo].[Payment] CHECK CONSTRAINT [FK_Payment_PaymentBatch]
GO
ALTER TABLE [dbo].[Payment]  WITH CHECK ADD  CONSTRAINT [FK_Payment_PaymentFile] FOREIGN KEY([PaymentFileId])
REFERENCES [dbo].[PaymentFile] ([Id])
GO
ALTER TABLE [dbo].[Payment] CHECK CONSTRAINT [FK_Payment_PaymentFile]
GO
ALTER TABLE [dbo].[Payment]  WITH CHECK ADD  CONSTRAINT [FK_Payment_SupplierInvoice] FOREIGN KEY([SupplierInvoiceId])
REFERENCES [dbo].[SupplierInvoice] ([Id])
GO
ALTER TABLE [dbo].[Payment] CHECK CONSTRAINT [FK_Payment_SupplierInvoice]
GO
ALTER TABLE [dbo].[PaymentBatch]  WITH CHECK ADD  CONSTRAINT [FK_PaymentBatch_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[PaymentBatch] CHECK CONSTRAINT [FK_PaymentBatch_Company]
GO
ALTER TABLE [dbo].[PaymentFile]  WITH CHECK ADD  CONSTRAINT [FK_PaymentFile_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[PaymentFile] CHECK CONSTRAINT [FK_PaymentFile_Company]
GO
ALTER TABLE [dbo].[PayslipDraftTransactionRow]  WITH CHECK ADD  CONSTRAINT [FK_PayslipDraftTransactionRow_PayslipTodo] FOREIGN KEY([PayslipTodoId])
REFERENCES [dbo].[PayslipTodo] ([Id])
GO
ALTER TABLE [dbo].[PayslipDraftTransactionRow] CHECK CONSTRAINT [FK_PayslipDraftTransactionRow_PayslipTodo]
GO
ALTER TABLE [dbo].[PayslipTodo]  WITH CHECK ADD  CONSTRAINT [FK_PayslipTodo_VoucherId] FOREIGN KEY([VoucherId])
REFERENCES [dbo].[Voucher] ([Id])
GO
ALTER TABLE [dbo].[PayslipTodo] CHECK CONSTRAINT [FK_PayslipTodo_VoucherId]
GO
ALTER TABLE [dbo].[PhotoMetadataLink]  WITH CHECK ADD  CONSTRAINT [FK_PhotoMetadataLink_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[PhotoMetadataLink] CHECK CONSTRAINT [FK_PhotoMetadataLink_Company]
GO
ALTER TABLE [dbo].[PrintJob]  WITH CHECK ADD  CONSTRAINT [FK_PrintJob_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[PrintJob] CHECK CONSTRAINT [FK_PrintJob_Company]
GO
ALTER TABLE [dbo].[PrintJob]  WITH CHECK ADD  CONSTRAINT [FK_PrintJob_User] FOREIGN KEY([UserId])
REFERENCES [dbo].[User] ([Id])
GO
ALTER TABLE [dbo].[PrintJob] CHECK CONSTRAINT [FK_PrintJob_User]
GO
ALTER TABLE [dbo].[PrintOut]  WITH CHECK ADD  CONSTRAINT [FK_PrintOut_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[PrintOut] CHECK CONSTRAINT [FK_PrintOut_Company]
GO
ALTER TABLE [dbo].[Project]  WITH CHECK ADD  CONSTRAINT [FK_Project_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[Project] CHECK CONSTRAINT [FK_Project_Company]
GO
ALTER TABLE [dbo].[Project]  WITH CHECK ADD  CONSTRAINT [FK_Project_Customer] FOREIGN KEY([CustomerId])
REFERENCES [dbo].[Customer] ([CustomerId])
GO
ALTER TABLE [dbo].[Project] CHECK CONSTRAINT [FK_Project_Customer]
GO
ALTER TABLE [dbo].[PurchaseReceipt]  WITH CHECK ADD  CONSTRAINT [FK_PurchaseReceipt_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[PurchaseReceipt] CHECK CONSTRAINT [FK_PurchaseReceipt_Company]
GO
ALTER TABLE [dbo].[PurchaseReceipt]  WITH CHECK ADD  CONSTRAINT [FK_PurchaseReceipt_CompanyBankAccount] FOREIGN KEY([BankAccountId])
REFERENCES [dbo].[CompanyBankAccount] ([Id])
GO
ALTER TABLE [dbo].[PurchaseReceipt] CHECK CONSTRAINT [FK_PurchaseReceipt_CompanyBankAccount]
GO
ALTER TABLE [dbo].[PurchaseReceipt]  WITH CHECK ADD  CONSTRAINT [FK_PurchaseReceipt_Supplier] FOREIGN KEY([SupplierId])
REFERENCES [dbo].[Supplier] ([Id])
GO
ALTER TABLE [dbo].[PurchaseReceipt] CHECK CONSTRAINT [FK_PurchaseReceipt_Supplier]
GO
ALTER TABLE [dbo].[QuickCustomerInvoiceRelation]  WITH CHECK ADD  CONSTRAINT [FK_QuickCustomerInvoiceRelation_CompanyId] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[QuickCustomerInvoiceRelation] CHECK CONSTRAINT [FK_QuickCustomerInvoiceRelation_CompanyId]
GO
ALTER TABLE [dbo].[QuickCustomerInvoiceRelation]  WITH CHECK ADD  CONSTRAINT [FK_QuickCustomerInvoiceRelation_CustomerInvoice] FOREIGN KEY([CustomerInvoiceId])
REFERENCES [dbo].[CustomerInvoice] ([Id])
GO
ALTER TABLE [dbo].[QuickCustomerInvoiceRelation] CHECK CONSTRAINT [FK_QuickCustomerInvoiceRelation_CustomerInvoice]
GO
ALTER TABLE [dbo].[QuickCustomerInvoiceRelation]  WITH CHECK ADD  CONSTRAINT [FK_QuickCustomerInvoiceRelation_VoucherRelation] FOREIGN KEY([VoucherRelationId])
REFERENCES [dbo].[VoucherRelation] ([Id])
GO
ALTER TABLE [dbo].[QuickCustomerInvoiceRelation] CHECK CONSTRAINT [FK_QuickCustomerInvoiceRelation_VoucherRelation]
GO
ALTER TABLE [dbo].[QuickSupplierInvoiceRelation]  WITH CHECK ADD  CONSTRAINT [FK_QuickSupplierInvoiceRelation_CompanyId] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[QuickSupplierInvoiceRelation] CHECK CONSTRAINT [FK_QuickSupplierInvoiceRelation_CompanyId]
GO
ALTER TABLE [dbo].[QuickSupplierInvoiceRelation]  WITH CHECK ADD  CONSTRAINT [FK_QuickSupplierInvoiceRelation_SupplierInvoice] FOREIGN KEY([SupplierInvoiceId])
REFERENCES [dbo].[SupplierInvoice] ([Id])
GO
ALTER TABLE [dbo].[QuickSupplierInvoiceRelation] CHECK CONSTRAINT [FK_QuickSupplierInvoiceRelation_SupplierInvoice]
GO
ALTER TABLE [dbo].[QuickSupplierInvoiceRelation]  WITH CHECK ADD  CONSTRAINT [FK_QuickSupplierInvoiceRelation_VoucherRelation] FOREIGN KEY([VoucherRelationId])
REFERENCES [dbo].[VoucherRelation] ([Id])
GO
ALTER TABLE [dbo].[QuickSupplierInvoiceRelation] CHECK CONSTRAINT [FK_QuickSupplierInvoiceRelation_VoucherRelation]
GO
ALTER TABLE [dbo].[QuickVoucherEntryRow]  WITH CHECK ADD  CONSTRAINT [FK_QuickVoucherEntryRow_CostCenterItem1] FOREIGN KEY([CostCenterItemId1])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[QuickVoucherEntryRow] CHECK CONSTRAINT [FK_QuickVoucherEntryRow_CostCenterItem1]
GO
ALTER TABLE [dbo].[QuickVoucherEntryRow]  WITH CHECK ADD  CONSTRAINT [FK_QuickVoucherEntryRow_CostCenterItem2] FOREIGN KEY([CostCenterItemId2])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[QuickVoucherEntryRow] CHECK CONSTRAINT [FK_QuickVoucherEntryRow_CostCenterItem2]
GO
ALTER TABLE [dbo].[QuickVoucherEntryRow]  WITH CHECK ADD  CONSTRAINT [FK_QuickVoucherEntryRow_CostCenterItem3] FOREIGN KEY([CostCenterItemId3])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[QuickVoucherEntryRow] CHECK CONSTRAINT [FK_QuickVoucherEntryRow_CostCenterItem3]
GO
ALTER TABLE [dbo].[QuickVoucherEntryRow]  WITH CHECK ADD  CONSTRAINT [FK_QuickVoucherEntryRow_Project] FOREIGN KEY([ProjectId])
REFERENCES [dbo].[Project] ([Id])
GO
ALTER TABLE [dbo].[QuickVoucherEntryRow] CHECK CONSTRAINT [FK_QuickVoucherEntryRow_Project]
GO
ALTER TABLE [dbo].[Quote]  WITH CHECK ADD  CONSTRAINT [FK_Quote_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[Quote] CHECK CONSTRAINT [FK_Quote_Company]
GO
ALTER TABLE [dbo].[Quote]  WITH CHECK ADD  CONSTRAINT [FK_Quote_Customer] FOREIGN KEY([CustomerId])
REFERENCES [dbo].[Customer] ([CustomerId])
GO
ALTER TABLE [dbo].[Quote] CHECK CONSTRAINT [FK_Quote_Customer]
GO
ALTER TABLE [dbo].[Quote]  WITH CHECK ADD  CONSTRAINT [FK_Quote_TermsOfPayment] FOREIGN KEY([TermsOfPaymentId])
REFERENCES [dbo].[TermsOfPayment] ([Id])
GO
ALTER TABLE [dbo].[Quote] CHECK CONSTRAINT [FK_Quote_TermsOfPayment]
GO
ALTER TABLE [dbo].[QuoteLog]  WITH CHECK ADD  CONSTRAINT [FK_QuoteLog_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[QuoteLog] CHECK CONSTRAINT [FK_QuoteLog_Company]
GO
ALTER TABLE [dbo].[QuoteLog]  WITH CHECK ADD  CONSTRAINT [FK_QuoteLog_Quote] FOREIGN KEY([QuoteId])
REFERENCES [dbo].[Quote] ([Id])
GO
ALTER TABLE [dbo].[QuoteLog] CHECK CONSTRAINT [FK_QuoteLog_Quote]
GO
ALTER TABLE [dbo].[QuotePerson]  WITH CHECK ADD  CONSTRAINT [FK_QuotePerson_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[QuotePerson] CHECK CONSTRAINT [FK_QuotePerson_Company]
GO
ALTER TABLE [dbo].[QuotePerson]  WITH CHECK ADD  CONSTRAINT [FK_QuotePerson_Quote] FOREIGN KEY([QuoteId])
REFERENCES [dbo].[Quote] ([Id])
GO
ALTER TABLE [dbo].[QuotePerson] CHECK CONSTRAINT [FK_QuotePerson_Quote]
GO
ALTER TABLE [dbo].[QuoteRow]  WITH CHECK ADD  CONSTRAINT [FK_QuoteRow_Article] FOREIGN KEY([ArticleId])
REFERENCES [dbo].[Article] ([Id])
GO
ALTER TABLE [dbo].[QuoteRow] CHECK CONSTRAINT [FK_QuoteRow_Article]
GO
ALTER TABLE [dbo].[QuoteRow]  WITH CHECK ADD  CONSTRAINT [FK_QuoteRow_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[QuoteRow] CHECK CONSTRAINT [FK_QuoteRow_Company]
GO
ALTER TABLE [dbo].[QuoteRow]  WITH CHECK ADD  CONSTRAINT [FK_QuoteRow_CostCenterItem1] FOREIGN KEY([CostCenterItemId1])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[QuoteRow] CHECK CONSTRAINT [FK_QuoteRow_CostCenterItem1]
GO
ALTER TABLE [dbo].[QuoteRow]  WITH CHECK ADD  CONSTRAINT [FK_QuoteRow_CostCenterItem2] FOREIGN KEY([CostCenterItemId2])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[QuoteRow] CHECK CONSTRAINT [FK_QuoteRow_CostCenterItem2]
GO
ALTER TABLE [dbo].[QuoteRow]  WITH CHECK ADD  CONSTRAINT [FK_QuoteRow_CostCenterItem3] FOREIGN KEY([CostCenterItemId3])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[QuoteRow] CHECK CONSTRAINT [FK_QuoteRow_CostCenterItem3]
GO
ALTER TABLE [dbo].[QuoteRow]  WITH CHECK ADD  CONSTRAINT [FK_QuoteRow_Project] FOREIGN KEY([ProjectId])
REFERENCES [dbo].[Project] ([Id])
GO
ALTER TABLE [dbo].[QuoteRow] CHECK CONSTRAINT [FK_QuoteRow_Project]
GO
ALTER TABLE [dbo].[QuoteRow]  WITH CHECK ADD  CONSTRAINT [FK_QuoteRow_Quote] FOREIGN KEY([QuoteId])
REFERENCES [dbo].[Quote] ([Id])
GO
ALTER TABLE [dbo].[QuoteRow] CHECK CONSTRAINT [FK_QuoteRow_Quote]
GO
ALTER TABLE [dbo].[RecurringCustomerInvoiceSettings]  WITH CHECK ADD  CONSTRAINT [FK_RecurringCustomerInvoiceSettings_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[RecurringCustomerInvoiceSettings] CHECK CONSTRAINT [FK_RecurringCustomerInvoiceSettings_Company]
GO
ALTER TABLE [dbo].[RecurringCustomerInvoiceSettings]  WITH CHECK ADD  CONSTRAINT [FK_RecurringCustomerInvoiceSettings_CustomerInvoiceDraft] FOREIGN KEY([CustomerInvoiceDraftId])
REFERENCES [dbo].[CustomerInvoiceDraft] ([Id])
GO
ALTER TABLE [dbo].[RecurringCustomerInvoiceSettings] CHECK CONSTRAINT [FK_RecurringCustomerInvoiceSettings_CustomerInvoiceDraft]
GO
ALTER TABLE [dbo].[RecurringCustomerInvoiceSettings]  WITH CHECK ADD  CONSTRAINT [FK_RecurringCustomerInvoiceSettings_User] FOREIGN KEY([CreatedByUserId])
REFERENCES [dbo].[User] ([Id])
GO
ALTER TABLE [dbo].[RecurringCustomerInvoiceSettings] CHECK CONSTRAINT [FK_RecurringCustomerInvoiceSettings_User]
GO
ALTER TABLE [dbo].[RegisterImportReport]  WITH CHECK ADD  CONSTRAINT [FK_RegisterImportHistory_Company] FOREIGN KEY([CompanyID])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[RegisterImportReport] CHECK CONSTRAINT [FK_RegisterImportHistory_Company]
GO
ALTER TABLE [dbo].[RegisterImportReport]  WITH CHECK ADD  CONSTRAINT [FK_RegisterImportReport_User] FOREIGN KEY([UserId])
REFERENCES [dbo].[User] ([Id])
GO
ALTER TABLE [dbo].[RegisterImportReport] CHECK CONSTRAINT [FK_RegisterImportReport_User]
GO
ALTER TABLE [dbo].[SalesDocumentAttachment]  WITH CHECK ADD  CONSTRAINT [FK_SalesDocumentAttachment_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[SalesDocumentAttachment] CHECK CONSTRAINT [FK_SalesDocumentAttachment_Company]
GO
ALTER TABLE [dbo].[SalesDocumentAttachmentLog]  WITH CHECK ADD  CONSTRAINT [FK_SalesDocumentAttachmentLog_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[SalesDocumentAttachmentLog] CHECK CONSTRAINT [FK_SalesDocumentAttachmentLog_Company]
GO
ALTER TABLE [dbo].[Supplier]  WITH CHECK ADD  CONSTRAINT [FK_Supplier_BankCountry] FOREIGN KEY([BankCountryCode])
REFERENCES [dbo].[Country] ([Code])
GO
ALTER TABLE [dbo].[Supplier] CHECK CONSTRAINT [FK_Supplier_BankCountry]
GO
ALTER TABLE [dbo].[Supplier]  WITH CHECK ADD  CONSTRAINT [FK_Supplier_BankCurrency] FOREIGN KEY([BankCurrencyCode])
REFERENCES [dbo].[Currency] ([Code])
GO
ALTER TABLE [dbo].[Supplier] CHECK CONSTRAINT [FK_Supplier_BankCurrency]
GO
ALTER TABLE [dbo].[Supplier]  WITH CHECK ADD  CONSTRAINT [FK_Supplier_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[Supplier] CHECK CONSTRAINT [FK_Supplier_Company]
GO
ALTER TABLE [dbo].[Supplier]  WITH CHECK ADD  CONSTRAINT [FK_Supplier_CompanyBankAccount] FOREIGN KEY([CompanyBankAccountId])
REFERENCES [dbo].[CompanyBankAccount] ([Id])
GO
ALTER TABLE [dbo].[Supplier] CHECK CONSTRAINT [FK_Supplier_CompanyBankAccount]
GO
ALTER TABLE [dbo].[Supplier]  WITH CHECK ADD  CONSTRAINT [FK_Supplier_Country] FOREIGN KEY([CountryCode])
REFERENCES [dbo].[Country] ([Code])
GO
ALTER TABLE [dbo].[Supplier] CHECK CONSTRAINT [FK_Supplier_Country]
GO
ALTER TABLE [dbo].[Supplier]  WITH CHECK ADD  CONSTRAINT [FK_Supplier_Currency] FOREIGN KEY([CurrencyCode])
REFERENCES [dbo].[Currency] ([Code])
GO
ALTER TABLE [dbo].[Supplier] CHECK CONSTRAINT [FK_Supplier_Currency]
GO
ALTER TABLE [dbo].[Supplier]  WITH CHECK ADD  CONSTRAINT [FK_Supplier_ForeignPaymentCode] FOREIGN KEY([ForeignPaymentCodeId])
REFERENCES [dbo].[ForeignPaymentCode] ([Id])
GO
ALTER TABLE [dbo].[Supplier] CHECK CONSTRAINT [FK_Supplier_ForeignPaymentCode]
GO
ALTER TABLE [dbo].[Supplier]  WITH CHECK ADD  CONSTRAINT [FK_Supplier_Supplier] FOREIGN KEY([Id])
REFERENCES [dbo].[Supplier] ([Id])
GO
ALTER TABLE [dbo].[Supplier] CHECK CONSTRAINT [FK_Supplier_Supplier]
GO
ALTER TABLE [dbo].[Supplier]  WITH CHECK ADD  CONSTRAINT [FK_Supplier_TermsOfPayment] FOREIGN KEY([TermsOfPaymentId])
REFERENCES [dbo].[TermsOfPayment] ([Id])
GO
ALTER TABLE [dbo].[Supplier] CHECK CONSTRAINT [FK_Supplier_TermsOfPayment]
GO
ALTER TABLE [dbo].[SupplierInvoice]  WITH CHECK ADD  CONSTRAINT [FK_SupplierInvoice_AutoInvoiceInboundDocument] FOREIGN KEY([AutoInvoiceInboundDocumentId])
REFERENCES [dbo].[AutoInvoiceInboundDocument] ([Id])
GO
ALTER TABLE [dbo].[SupplierInvoice] CHECK CONSTRAINT [FK_SupplierInvoice_AutoInvoiceInboundDocument]
GO
ALTER TABLE [dbo].[SupplierInvoice]  WITH CHECK ADD  CONSTRAINT [FK_SupplierInvoice_AutoInvoiceInterimSupplier] FOREIGN KEY([InterimSupplierId])
REFERENCES [dbo].[AutoInvoiceInterimSupplier] ([Id])
GO
ALTER TABLE [dbo].[SupplierInvoice] CHECK CONSTRAINT [FK_SupplierInvoice_AutoInvoiceInterimSupplier]
GO
ALTER TABLE [dbo].[SupplierInvoice]  WITH CHECK ADD  CONSTRAINT [FK_SupplierInvoice_BankCountry] FOREIGN KEY([SupplierBankCountryCode])
REFERENCES [dbo].[Country] ([Code])
GO
ALTER TABLE [dbo].[SupplierInvoice] CHECK CONSTRAINT [FK_SupplierInvoice_BankCountry]
GO
ALTER TABLE [dbo].[SupplierInvoice]  WITH CHECK ADD  CONSTRAINT [FK_SupplierInvoice_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[SupplierInvoice] CHECK CONSTRAINT [FK_SupplierInvoice_Company]
GO
ALTER TABLE [dbo].[SupplierInvoice]  WITH CHECK ADD  CONSTRAINT [FK_SupplierInvoice_CompanyBankAccount] FOREIGN KEY([CompanyBankAccountId])
REFERENCES [dbo].[CompanyBankAccount] ([Id])
GO
ALTER TABLE [dbo].[SupplierInvoice] CHECK CONSTRAINT [FK_SupplierInvoice_CompanyBankAccount]
GO
ALTER TABLE [dbo].[SupplierInvoice]  WITH CHECK ADD  CONSTRAINT [FK_SupplierInvoice_Supplier] FOREIGN KEY([SupplierId])
REFERENCES [dbo].[Supplier] ([Id])
GO
ALTER TABLE [dbo].[SupplierInvoice] CHECK CONSTRAINT [FK_SupplierInvoice_Supplier]
GO
ALTER TABLE [dbo].[SupplierInvoice]  WITH CHECK ADD  CONSTRAINT [FK_SupplierInvoice_SupplierCountry] FOREIGN KEY([SupplierCountryCode])
REFERENCES [dbo].[Country] ([Code])
GO
ALTER TABLE [dbo].[SupplierInvoice] CHECK CONSTRAINT [FK_SupplierInvoice_SupplierCountry]
GO
ALTER TABLE [dbo].[SupplierInvoice]  WITH CHECK ADD  CONSTRAINT [FK_SupplierInvoice_User] FOREIGN KEY([CreatedByUserId])
REFERENCES [dbo].[User] ([Id])
GO
ALTER TABLE [dbo].[SupplierInvoice] CHECK CONSTRAINT [FK_SupplierInvoice_User]
GO
ALTER TABLE [dbo].[SupplierInvoice]  WITH CHECK ADD  CONSTRAINT [FK_SupplierInvoice_User2] FOREIGN KEY([ApprovedByUserId])
REFERENCES [dbo].[User] ([Id])
GO
ALTER TABLE [dbo].[SupplierInvoice] CHECK CONSTRAINT [FK_SupplierInvoice_User2]
GO
ALTER TABLE [dbo].[SupplierInvoice]  WITH CHECK ADD  CONSTRAINT [FK_SupplierInvoice_Voucher] FOREIGN KEY([VoucherId])
REFERENCES [dbo].[Voucher] ([Id])
GO
ALTER TABLE [dbo].[SupplierInvoice] CHECK CONSTRAINT [FK_SupplierInvoice_Voucher]
GO
ALTER TABLE [dbo].[SupplierInvoiceApprovalEvent]  WITH CHECK ADD  CONSTRAINT [FK_SupplierInvoice] FOREIGN KEY([SupplierInvoiceId])
REFERENCES [dbo].[SupplierInvoice] ([Id])
GO
ALTER TABLE [dbo].[SupplierInvoiceApprovalEvent] CHECK CONSTRAINT [FK_SupplierInvoice]
GO
ALTER TABLE [dbo].[SupplierInvoiceDocument]  WITH CHECK ADD  CONSTRAINT [FK_SupplierInvoiceDocument_Document] FOREIGN KEY([DocumentId])
REFERENCES [dbo].[Document] ([Id])
GO
ALTER TABLE [dbo].[SupplierInvoiceDocument] CHECK CONSTRAINT [FK_SupplierInvoiceDocument_Document]
GO
ALTER TABLE [dbo].[SupplierInvoiceDocument]  WITH CHECK ADD  CONSTRAINT [FK_SupplierInvoiceDocument_SupplierInvoice] FOREIGN KEY([SupplierInvoiceId])
REFERENCES [dbo].[SupplierInvoice] ([Id])
GO
ALTER TABLE [dbo].[SupplierInvoiceDocument] CHECK CONSTRAINT [FK_SupplierInvoiceDocument_SupplierInvoice]
GO
ALTER TABLE [dbo].[SupplierInvoiceRow]  WITH CHECK ADD  CONSTRAINT [FK_SupplierInvoiceRow_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[SupplierInvoiceRow] CHECK CONSTRAINT [FK_SupplierInvoiceRow_Company]
GO
ALTER TABLE [dbo].[SupplierInvoiceRow]  WITH CHECK ADD  CONSTRAINT [FK_SupplierInvoiceRow_CostCenterItem1] FOREIGN KEY([CostCenterItemId1])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[SupplierInvoiceRow] CHECK CONSTRAINT [FK_SupplierInvoiceRow_CostCenterItem1]
GO
ALTER TABLE [dbo].[SupplierInvoiceRow]  WITH CHECK ADD  CONSTRAINT [FK_SupplierInvoiceRow_CostCenterItem2] FOREIGN KEY([CostCenterItemId2])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[SupplierInvoiceRow] CHECK CONSTRAINT [FK_SupplierInvoiceRow_CostCenterItem2]
GO
ALTER TABLE [dbo].[SupplierInvoiceRow]  WITH CHECK ADD  CONSTRAINT [FK_SupplierInvoiceRow_CostCenterItem3] FOREIGN KEY([CostCenterItemId3])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[SupplierInvoiceRow] CHECK CONSTRAINT [FK_SupplierInvoiceRow_CostCenterItem3]
GO
ALTER TABLE [dbo].[SupplierInvoiceRow]  WITH CHECK ADD  CONSTRAINT [FK_SupplierInvoiceRow_Project] FOREIGN KEY([ProjectId])
REFERENCES [dbo].[Project] ([Id])
GO
ALTER TABLE [dbo].[SupplierInvoiceRow] CHECK CONSTRAINT [FK_SupplierInvoiceRow_Project]
GO
ALTER TABLE [dbo].[SupplierInvoiceRow]  WITH CHECK ADD  CONSTRAINT [FK_SupplierInvoiceRow_SupplierInvoice] FOREIGN KEY([SupplierInvoiceId])
REFERENCES [dbo].[SupplierInvoice] ([Id])
GO
ALTER TABLE [dbo].[SupplierInvoiceRow] CHECK CONSTRAINT [FK_SupplierInvoiceRow_SupplierInvoice]
GO
ALTER TABLE [dbo].[SupplierInvoiceValuationHistory]  WITH CHECK ADD  CONSTRAINT [FK_SupplierInvoiceValuationHistory_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[SupplierInvoiceValuationHistory] CHECK CONSTRAINT [FK_SupplierInvoiceValuationHistory_Company]
GO
ALTER TABLE [dbo].[SupplierInvoiceValuationHistory]  WITH CHECK ADD  CONSTRAINT [FK_SupplierInvoiceValuationHistory_SupplierInvoice] FOREIGN KEY([SupplierInvoiceId])
REFERENCES [dbo].[SupplierInvoice] ([Id])
GO
ALTER TABLE [dbo].[SupplierInvoiceValuationHistory] CHECK CONSTRAINT [FK_SupplierInvoiceValuationHistory_SupplierInvoice]
GO
ALTER TABLE [dbo].[TermsOfPayment]  WITH CHECK ADD  CONSTRAINT [FK_TermsOfPayment_Country] FOREIGN KEY([CountryCode])
REFERENCES [dbo].[Country] ([Code])
GO
ALTER TABLE [dbo].[TermsOfPayment] CHECK CONSTRAINT [FK_TermsOfPayment_Country]
GO
ALTER TABLE [dbo].[Unit]  WITH CHECK ADD  CONSTRAINT [FK_Unit_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[Unit] CHECK CONSTRAINT [FK_Unit_Company]
GO
ALTER TABLE [dbo].[UnpackingInformation]  WITH CHECK ADD  CONSTRAINT [FK_UnpackingInformation_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[UnpackingInformation] CHECK CONSTRAINT [FK_UnpackingInformation_Company]
GO
ALTER TABLE [dbo].[User]  WITH CHECK ADD  CONSTRAINT [FK_User_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[User] CHECK CONSTRAINT [FK_User_Company]
GO
ALTER TABLE [dbo].[UserConnection]  WITH CHECK ADD  CONSTRAINT [FK_UserConnection_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[UserConnection] CHECK CONSTRAINT [FK_UserConnection_Company]
GO
ALTER TABLE [dbo].[UserConnection]  WITH CHECK ADD  CONSTRAINT [FK_UserConnection_User] FOREIGN KEY([UserId])
REFERENCES [dbo].[User] ([Id])
GO
ALTER TABLE [dbo].[UserConnection] CHECK CONSTRAINT [FK_UserConnection_User]
GO
ALTER TABLE [dbo].[UserSettings]  WITH CHECK ADD  CONSTRAINT [FK_UserSettings_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[UserSettings] CHECK CONSTRAINT [FK_UserSettings_Company]
GO
ALTER TABLE [dbo].[UserSettings]  WITH CHECK ADD  CONSTRAINT [FK_UserSettings_User] FOREIGN KEY([Id])
REFERENCES [dbo].[User] ([Id])
GO
ALTER TABLE [dbo].[UserSettings] CHECK CONSTRAINT [FK_UserSettings_User]
GO
ALTER TABLE [dbo].[VatCode]  WITH CHECK ADD  CONSTRAINT [FK_VatCode_Country] FOREIGN KEY([CountryCode])
REFERENCES [dbo].[Country] ([Code])
GO
ALTER TABLE [dbo].[VatCode] CHECK CONSTRAINT [FK_VatCode_Country]
GO
ALTER TABLE [dbo].[VatCode]  WITH CHECK ADD  CONSTRAINT [FK_VatCode_VatRate] FOREIGN KEY([VatRateId])
REFERENCES [dbo].[VatRate] ([Id])
GO
ALTER TABLE [dbo].[VatCode] CHECK CONSTRAINT [FK_VatCode_VatRate]
GO
ALTER TABLE [dbo].[VatRate]  WITH CHECK ADD  CONSTRAINT [FK_VatRate_Country] FOREIGN KEY([CountryCode])
REFERENCES [dbo].[Country] ([Code])
GO
ALTER TABLE [dbo].[VatRate] CHECK CONSTRAINT [FK_VatRate_Country]
GO
ALTER TABLE [dbo].[VatRateValue]  WITH CHECK ADD  CONSTRAINT [FK_VatRateValue_VatRate] FOREIGN KEY([VatRateId])
REFERENCES [dbo].[VatRate] ([Id])
GO
ALTER TABLE [dbo].[VatRateValue] CHECK CONSTRAINT [FK_VatRateValue_VatRate]
GO
ALTER TABLE [dbo].[VatReport]  WITH CHECK ADD  CONSTRAINT [FK_VatReport_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[VatReport] CHECK CONSTRAINT [FK_VatReport_Company]
GO
ALTER TABLE [dbo].[VatReport]  WITH CHECK ADD  CONSTRAINT [FK_VatReport_Country] FOREIGN KEY([CountryCode])
REFERENCES [dbo].[Country] ([Code])
GO
ALTER TABLE [dbo].[VatReport] CHECK CONSTRAINT [FK_VatReport_Country]
GO
ALTER TABLE [dbo].[VatReport]  WITH CHECK ADD  CONSTRAINT [FK_VatReport_VoucherId] FOREIGN KEY([VoucherId])
REFERENCES [dbo].[Voucher] ([Id])
GO
ALTER TABLE [dbo].[VatReport] CHECK CONSTRAINT [FK_VatReport_VoucherId]
GO
ALTER TABLE [dbo].[VatReportField]  WITH CHECK ADD  CONSTRAINT [FK_VatReportField_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[VatReportField] CHECK CONSTRAINT [FK_VatReportField_Company]
GO
ALTER TABLE [dbo].[VatReportField]  WITH CHECK ADD  CONSTRAINT [FK_VatReportField_VatReport] FOREIGN KEY([VatReportId])
REFERENCES [dbo].[VatReport] ([Id])
GO
ALTER TABLE [dbo].[VatReportField] CHECK CONSTRAINT [FK_VatReportField_VatReport]
GO
ALTER TABLE [dbo].[Voucher]  WITH CHECK ADD  CONSTRAINT [FK_Voucher_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[Voucher] CHECK CONSTRAINT [FK_Voucher_Company]
GO
ALTER TABLE [dbo].[Voucher]  WITH CHECK ADD  CONSTRAINT [FK_Voucher_FiscalYear] FOREIGN KEY([FiscalYearId])
REFERENCES [dbo].[FiscalYear] ([Id])
GO
ALTER TABLE [dbo].[Voucher] CHECK CONSTRAINT [FK_Voucher_FiscalYear]
GO
ALTER TABLE [dbo].[Voucher]  WITH CHECK ADD  CONSTRAINT [FK_Voucher_User] FOREIGN KEY([CreatedByUserId])
REFERENCES [dbo].[User] ([Id])
GO
ALTER TABLE [dbo].[Voucher] CHECK CONSTRAINT [FK_Voucher_User]
GO
ALTER TABLE [dbo].[Voucher]  WITH CHECK ADD  CONSTRAINT [FK_Voucher_Voucher] FOREIGN KEY([CorrectsVoucherId])
REFERENCES [dbo].[Voucher] ([Id])
GO
ALTER TABLE [dbo].[Voucher] CHECK CONSTRAINT [FK_Voucher_Voucher]
GO
ALTER TABLE [dbo].[VoucherRelation]  WITH CHECK ADD  CONSTRAINT [FK_VoucherRelation_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[VoucherRelation] CHECK CONSTRAINT [FK_VoucherRelation_Company]
GO
ALTER TABLE [dbo].[VoucherRelation]  WITH CHECK ADD  CONSTRAINT [FK_VoucherRelation_RelatedVoucher] FOREIGN KEY([RelatedVoucherId])
REFERENCES [dbo].[Voucher] ([Id])
GO
ALTER TABLE [dbo].[VoucherRelation] CHECK CONSTRAINT [FK_VoucherRelation_RelatedVoucher]
GO
ALTER TABLE [dbo].[VoucherRelation]  WITH CHECK ADD  CONSTRAINT [FK_VoucherRelation_Voucher] FOREIGN KEY([VoucherId])
REFERENCES [dbo].[Voucher] ([Id])
GO
ALTER TABLE [dbo].[VoucherRelation] CHECK CONSTRAINT [FK_VoucherRelation_Voucher]
GO
ALTER TABLE [dbo].[VoucherRow]  WITH CHECK ADD  CONSTRAINT [FK_VoucherRow_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[VoucherRow] CHECK CONSTRAINT [FK_VoucherRow_Company]
GO
ALTER TABLE [dbo].[VoucherRow]  WITH CHECK ADD  CONSTRAINT [FK_VoucherRow_CostCenterItem1] FOREIGN KEY([CostCenterItemId1])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[VoucherRow] CHECK CONSTRAINT [FK_VoucherRow_CostCenterItem1]
GO
ALTER TABLE [dbo].[VoucherRow]  WITH CHECK ADD  CONSTRAINT [FK_VoucherRow_CostCenterItem2] FOREIGN KEY([CostCenterItemId2])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[VoucherRow] CHECK CONSTRAINT [FK_VoucherRow_CostCenterItem2]
GO
ALTER TABLE [dbo].[VoucherRow]  WITH CHECK ADD  CONSTRAINT [FK_VoucherRow_CostCenterItem3] FOREIGN KEY([CostCenterItemId3])
REFERENCES [dbo].[CostCenterItem] ([Id])
GO
ALTER TABLE [dbo].[VoucherRow] CHECK CONSTRAINT [FK_VoucherRow_CostCenterItem3]
GO
ALTER TABLE [dbo].[VoucherRow]  WITH CHECK ADD  CONSTRAINT [FK_VoucherRow_Project] FOREIGN KEY([ProjectId])
REFERENCES [dbo].[Project] ([Id])
GO
ALTER TABLE [dbo].[VoucherRow] CHECK CONSTRAINT [FK_VoucherRow_Project]
GO
ALTER TABLE [dbo].[VoucherRow]  WITH CHECK ADD  CONSTRAINT [FK_VoucherRow_VatCode] FOREIGN KEY([VatCodeId])
REFERENCES [dbo].[VatCode] ([Id])
GO
ALTER TABLE [dbo].[VoucherRow] CHECK CONSTRAINT [FK_VoucherRow_VatCode]
GO
ALTER TABLE [dbo].[VoucherRow]  WITH CHECK ADD  CONSTRAINT [FK_VoucherRow_VatReport] FOREIGN KEY([IsDeclaredOnVatReportId])
REFERENCES [dbo].[VatReport] ([Id])
GO
ALTER TABLE [dbo].[VoucherRow] CHECK CONSTRAINT [FK_VoucherRow_VatReport]
GO
ALTER TABLE [dbo].[VoucherRow]  WITH CHECK ADD  CONSTRAINT [FK_VoucherRow_Voucher] FOREIGN KEY([VoucherId])
REFERENCES [dbo].[Voucher] ([Id])
GO
ALTER TABLE [dbo].[VoucherRow] CHECK CONSTRAINT [FK_VoucherRow_Voucher]
GO
ALTER TABLE [dbo].[WebshopOrder]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDraft.CustomerCountryCode_Country] FOREIGN KEY([CustomerCountryCode])
REFERENCES [dbo].[Country] ([Code])
GO
ALTER TABLE [dbo].[WebshopOrder] CHECK CONSTRAINT [FK_CustomerInvoiceDraft.CustomerCountryCode_Country]
GO
ALTER TABLE [dbo].[WebshopOrder]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDraft.CustomerCountryCodeDelivery_Country2] FOREIGN KEY([CustomerCountryCodeDelivery])
REFERENCES [dbo].[Country] ([Code])
GO
ALTER TABLE [dbo].[WebshopOrder] CHECK CONSTRAINT [FK_CustomerInvoiceDraft.CustomerCountryCodeDelivery_Country2]
GO
ALTER TABLE [dbo].[WebshopOrder]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDraft_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[WebshopOrder] CHECK CONSTRAINT [FK_CustomerInvoiceDraft_Company]
GO
ALTER TABLE [dbo].[WebshopOrder]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDraft_Currency] FOREIGN KEY([CurrencyCode])
REFERENCES [dbo].[Currency] ([Code])
GO
ALTER TABLE [dbo].[WebshopOrder] CHECK CONSTRAINT [FK_CustomerInvoiceDraft_Currency]
GO
ALTER TABLE [dbo].[WebshopOrder]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDraft_Customer] FOREIGN KEY([CustomerId])
REFERENCES [dbo].[Customer] ([CustomerId])
GO
ALTER TABLE [dbo].[WebshopOrder] CHECK CONSTRAINT [FK_CustomerInvoiceDraft_Customer]
GO
ALTER TABLE [dbo].[WebshopOrder]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDraft_TermsOfPayment] FOREIGN KEY([TermsOfPaymentId])
REFERENCES [dbo].[TermsOfPayment] ([Id])
GO
ALTER TABLE [dbo].[WebshopOrder] CHECK CONSTRAINT [FK_CustomerInvoiceDraft_TermsOfPayment]
GO
ALTER TABLE [dbo].[WebshopOrderRow]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDraftRow_Article] FOREIGN KEY([ArticleId])
REFERENCES [dbo].[Article] ([Id])
GO
ALTER TABLE [dbo].[WebshopOrderRow] CHECK CONSTRAINT [FK_CustomerInvoiceDraftRow_Article]
GO
ALTER TABLE [dbo].[WebshopOrderRow]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDraftRow_ArticleAccountCodingId] FOREIGN KEY([ArticleAccountCodingId])
REFERENCES [dbo].[ArticleAccountCoding] ([Id])
GO
ALTER TABLE [dbo].[WebshopOrderRow] CHECK CONSTRAINT [FK_CustomerInvoiceDraftRow_ArticleAccountCodingId]
GO
ALTER TABLE [dbo].[WebshopOrderRow]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDraftRow_Company] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Company] ([Id])
GO
ALTER TABLE [dbo].[WebshopOrderRow] CHECK CONSTRAINT [FK_CustomerInvoiceDraftRow_Company]
GO
ALTER TABLE [dbo].[WebshopOrderRow]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDraftRow_CustomerInvoiceDraft] FOREIGN KEY([WebshopOrderId])
REFERENCES [dbo].[WebshopOrder] ([Id])
GO
ALTER TABLE [dbo].[WebshopOrderRow] CHECK CONSTRAINT [FK_CustomerInvoiceDraftRow_CustomerInvoiceDraft]
GO
ALTER TABLE [dbo].[WebshopOrderRow]  WITH CHECK ADD  CONSTRAINT [FK_CustomerInvoiceDraftRow_Unit] FOREIGN KEY([UnitId])
REFERENCES [dbo].[Unit] ([Id])
GO
ALTER TABLE [dbo].[WebshopOrderRow] CHECK CONSTRAINT [FK_CustomerInvoiceDraftRow_Unit]
GO
ALTER TABLE [dbo].[QuoteRow]  WITH NOCHECK ADD  CONSTRAINT [CK_QuoteRow_ArticleId_Quantity_UnitPrice] CHECK  (([ArticleId] IS NOT NULL OR [Quantity]=(0) AND [UnitPrice]=(0)))
GO
ALTER TABLE [dbo].[QuoteRow] CHECK CONSTRAINT [CK_QuoteRow_ArticleId_Quantity_UnitPrice]
GO
ALTER TABLE [dbo].[RecurringCustomerInvoiceSettings]  WITH CHECK ADD  CONSTRAINT [CK_RecurringCustomerInvoiceSettings_Number] CHECK  (([Number]>(0)))
GO
ALTER TABLE [dbo].[RecurringCustomerInvoiceSettings] CHECK CONSTRAINT [CK_RecurringCustomerInvoiceSettings_Number]
GO
