IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'BigWareListRowCount'

    WHERE SysObjects.Name = 'DEPARTMENTS'
)
  ALTER TABLE DEPARTMENTS ADD BigWareListRowCount INT NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'BigWareListAsDefault'

    WHERE SysObjects.Name = 'DEPARTMENTS'
)
  ALTER TABLE DEPARTMENTS ADD BigWareListAsDefault Bit NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'PMIDepartment'
    WHERE SysObjects.Name = 'Departments'
)
  ALTER TABLE Departments ADD PMIDepartment BIT
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'QuickUserChangeSelector'
    WHERE SysObjects.Name = 'DEPARTMENTS'
)
  ALTER TABLE dbo.DEPARTMENTS ADD QuickUserChangeSelector BIT
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'BillPrintCorrOnlyTypes'
    WHERE SysObjects.Name = 'Departments'
)
  ALTER TABLE Departments ADD BillPrintCorrOnlyTypes VARCHAR(50) NULL
GO

IF NOT EXISTS (select * from dbo.sysobjects where id = object_id(N'[dbo].[WareCategoryDiscountXTab]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
  CREATE TABLE [dbo].[WareCategoryDiscountXTab](
	[WareNumber] [int] NOT NULL,
	[CategoryNumber] [int] NOT NULL,
	[Discount] [decimal](9, 0) NOT NULL,
	[RuleSet] [int] NULL,
    CONSTRAINT [PK_WareCategoryDiscountXTab] PRIMARY KEY CLUSTERED 
    (
	[WareNumber] ASC,
	[CategoryNumber] ASC
    ) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,       ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  ) ON [PRIMARY]
ELSE IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'RuleSet'
    WHERE SysObjects.Name = 'WareCategoryDiscountXTab'
)
  ALTER TABLE WareCategoryDiscountXTab ADD RuleSet INT
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'CreditorId'
    WHERE SysObjects.Name = 'Invoices'
)
BEGIN
  ALTER TABLE Invoices ADD CreditorId varchar(8) null
END
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'GiroId'
    WHERE SysObjects.Name = 'Invoices'
)
BEGIN
  ALTER TABLE Invoices ADD GiroId varchar(21) null
END
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'OneClickPayment'
    WHERE SysObjects.Name = 'Departments'
)
  ALTER TABLE Departments ADD OneClickPayment BIT null
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'IsTablet'
    WHERE SysObjects.Name = 'Terminals'
)
  ALTER TABLE Terminals ADD IsTablet BIT null
GO
IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'QuickLoginTablet'
    WHERE SysObjects.Name = 'Departments'
)
  ALTER TABLE Departments ADD QuickLoginTablet BIT null
GO
IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'QuickUserChangeTablet'
    WHERE SysObjects.Name = 'Departments'
)
  ALTER TABLE Departments ADD QuickUserChangeTablet BIT null
GO
IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'QuickUserChangeSelectorTablet'
    WHERE SysObjects.Name = 'Departments'
)
  ALTER TABLE Departments ADD QuickUserChangeSelectorTablet BIT null
GO
