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

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[OTAInvCountNotifLog]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
  CREATE TABLE [dbo].[CashBoxReport]
  (
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [ReportId] [int] NOT NULL,
    [FK_CashBoxId] [int] NOT NULL,
    [VersionNumber] [varchar](50) NOT NULL,
    [DateStamp] [datetime] NOT NULL,
    [ReportType] [tinyint] NOT NULL,
    [XML] [nvarchar](max) NOT NULL,
    CONSTRAINT [PK_CashBoxReport] PRIMARY KEY CLUSTERED 
  (
    [Id] ASC
  )
  ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

  ALTER TABLE [dbo].[CashBoxReport]  WITH CHECK ADD  CONSTRAINT [FK_CashBoxReport_CashBox] FOREIGN KEY([FK_CashBoxId])
  REFERENCES [dbo].[CashBox] ([PK_CashBox])

  ALTER TABLE [dbo].[CashBoxReport] CHECK CONSTRAINT [FK_CashBoxReport_CashBox]
END