IF OBJECT_ID(N'dbo._TabVyroba_Objednavky', N'U') IS NULL
 CREATE TABLE dbo._TabVyroba_Objednavky (
  ID int IDENTITY(1, 1) NOT NULL,
  IDPrijataDataJson int NULL,
  IdPHIdent bigint NULL,
  IdPHIdent2 bigint NULL,
  PHOznaceni nvarchar(50) COLLATE Czech_CI_AS NULL,
--  IDDokladOZ INT,
--  IDPohybOZ INT,
  Poznamka nvarchar(255) COLLATE Czech_CI_AS NULL,
  SkupZbo nvarchar(3) COLLATE Czech_CI_AS NULL,
  RegCis nvarchar(30) COLLATE Czech_CI_AS NULL,
  IDKmenZbozi int NULL,
  Mnozstvi numeric(19, 6) DEFAULT 0.0 NOT NULL,
  MnozVydane numeric(19, 6) DEFAULT 0.0 NOT NULL,
--  MnozKVydeji numeric(19, 6) DEFAULT 0.0 NOT NULL,
  PaletovyList nvarchar(50) COLLATE Czech_CI_AS NULL,
  Sarze nvarchar(30) COLLATE Czech_CI_AS NULL,
  NocniObjednavka BIT NOT NULL DEFAULT 0,
  Storno BIT NOT NULL DEFAULT 0,
  Vratka BIT NOT NULL DEFAULT 0,
  Splneno BIT NOT NULL DEFAULT 0,
  OdmitnutoSkladem BIT NOT NULL DEFAULT 0,
  PocetPohybuOZ SMALLINT NOT NULL DEFAULT 0,
  Blokovano bit DEFAULT 0 NOT NULL,
  DatPorizeni datetime DEFAULT getdate() NOT NULL,
  Autor NVARCHAR(80) NOT NULL DEFAULT SUSER_SNAME(),
  DatZpracovani datetime NULL,
  CONSTRAINT PK__TabVyroba_Objednavky PRIMARY KEY CLUSTERED (ID DESC) WITH ( PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)

DROP INDEX IF EXISTS EI_TabVyroba_Objednavky_IdPrijataDataJson ON dbo._TabVyroba_Objednavky
 CREATE NONCLUSTERED INDEX EI_TabVyroba_Objednavky_IdPrijataDataJson ON dbo._TabVyroba_Objednavky (IDPrijataDataJson)
  WITH ( PAD_INDEX = OFF, DROP_EXISTING = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)

DROP INDEX IF EXISTS EI_TabVyroba_Objednavky_idPH ON dbo._TabVyroba_Objednavky
 CREATE NONCLUSTERED INDEX EI_TabVyroba_Objednavky_idPH ON dbo._TabVyroba_Objednavky (IdPHIdent)
  WITH ( PAD_INDEX = OFF, DROP_EXISTING = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)




/* 10.11.2023 */
--IF COL_LENGTH(N'dbo._TabVyroba_Objednavky', N'IDDokladOZ') IS NULL ALTER TABLE dbo._TabVyroba_Objednavky ADD IDDokladOZ INT NULL
IF COL_LENGTH(N'dbo._TabVyroba_Objednavky', N'IDPohybOZ') IS NOT NULL ALTER TABLE dbo._TabVyroba_Objednavky DROP COLUMN IDPohybOZ
IF COL_LENGTH(N'dbo._TabVyroba_Objednavky', N'DatReportuPH') IS NOT NULL ALTER TABLE dbo._TabVyroba_Objednavky DROP COLUMN DatReportuPH
IF COL_LENGTH(N'dbo._TabVyroba_Objednavky', N'PocetPohybuOZ') IS NULL ALTER TABLE dbo._TabVyroba_Objednavky ADD PocetPohybuOZ SMALLINT NOT NULL DEFAULT 0


/* 12.11.2023 */
IF COL_LENGTH(N'dbo._TabVyroba_Objednavky', N'Storno') IS NULL ALTER TABLE dbo._TabVyroba_Objednavky ADD Storno BIT NOT NULL DEFAULT 0
IF COL_LENGTH(N'dbo._TabVyroba_Objednavky', N'Vratka') IS NULL ALTER TABLE dbo._TabVyroba_Objednavky ADD Vratka BIT NOT NULL DEFAULT 0
IF COL_LENGTH(N'dbo._TabVyroba_Objednavky', N'Autor') IS NULL ALTER TABLE dbo._TabVyroba_Objednavky ADD Autor NVARCHAR(80) NOT NULL DEFAULT SUSER_SNAME()

/* 14.11.2023 */
IF COL_LENGTH(N'dbo._TabVyroba_Objednavky', N'NocniObjednavka') IS NULL ALTER TABLE dbo._TabVyroba_Objednavky ADD NocniObjednavka BIT NOT NULL DEFAULT 0

/* 23.11.2023 */
IF COL_LENGTH(N'dbo._TabVyroba_Objednavky', N'Splneno') IS NULL ALTER TABLE dbo._TabVyroba_Objednavky ADD Splneno BIT NOT NULL DEFAULT 0
--IF COL_LENGTH(N'dbo._TabVyroba_Objednavky', N'MnozKVydeji') IS NULL ALTER TABLE dbo._TabVyroba_Objednavky ADD MnozKVydeji NUMERIC(19,6) NOT NULL DEFAULT 0.0


/*  5.6.2025 */
IF COL_LENGTH(N'dbo._TabVyroba_Objednavky', N'MnozVydane') IS NULL ALTER TABLE dbo._TabVyroba_Objednavky ADD MnozVydane NUMERIC(19,6) NOT NULL DEFAULT 0.0
IF COL_LENGTH(N'dbo._TabVyroba_Objednavky', N'MnozKVydeji') IS NOT NULL ALTER TABLE dbo._TabVyroba_Objednavky DROP COLUMN MnozKVydeji








IF OBJECT_ID(N'dbo._TabVyroba_Objednavky_Pol', N'U') IS NULL
 CREATE TABLE dbo._TabVyroba_Objednavky_Pol (
  ID INT IDENTITY(1, 1) NOT NULL,
  IDHlava INT NULL,
  IDDokladOZ INT NULL,
  IDPohybOZ INT NULL,
  IDVyrCP INT NULL,
  SkupZbo NVARCHAR(3),
  RegCis NVARCHAR(30),
  Mnozstvi numeric(19, 6) DEFAULT 0.0 NOT NULL,
  Sarze NVARCHAR(100) NULL,
  PaletovyList NVARCHAR(100) NULL,
  DatPorizeni datetime DEFAULT getdate() NOT NULL,
  CONSTRAINT PK__TabVyroba_Objednavky_Pol PRIMARY KEY CLUSTERED (ID DESC) WITH ( PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)


DROP INDEX IF EXISTS EI_TabVyroba_Objednavky_Pol_idHlava ON dbo._TabVyroba_Objednavky_Pol
 CREATE NONCLUSTERED INDEX EI_TabVyroba_Objednavky_Pol_idHlava ON dbo._TabVyroba_Objednavky_Pol (IDHlava)
  WITH ( PAD_INDEX = OFF, DROP_EXISTING = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)

DROP INDEX IF EXISTS EI_TabVyroba_Objednavky_Pol_idPZ ON dbo._TabVyroba_Objednavky_Pol
 CREATE NONCLUSTERED INDEX EI_TabVyroba_Objednavky_Pol_idPZ ON dbo._TabVyroba_Objednavky_Pol (IDPohybOZ)
  WITH ( PAD_INDEX = OFF, DROP_EXISTING = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)

DROP INDEX IF EXISTS EI_TabVyroba_Objednavky_Pol_idDZ ON dbo._TabVyroba_Objednavky_Pol
 CREATE NONCLUSTERED INDEX EI_TabVyroba_Objednavky_Pol_idDZ ON dbo._TabVyroba_Objednavky_Pol (IDDokladOZ)
  WITH ( PAD_INDEX = OFF, DROP_EXISTING = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)



/* 13.11.2023 */
IF COL_LENGTH(N'dbo._TabVyroba_Objednavky_Pol', N'IDVyrCP') IS NULL ALTER TABLE dbo._TabVyroba_Objednavky_Pol ADD IDVyrCP INT NULL

/* 9.9.2024 */
IF COL_LENGTH(N'dbo._TabVyroba_Objednavky_Pol', N'Sarze') IS NULL ALTER TABLE dbo._TabVyroba_Objednavky_Pol ADD Sarze NVARCHAR(100) NULL

/* 17.9.2024 */
IF COL_LENGTH(N'dbo._TabVyroba_Objednavky_Pol', N'PaletovyList') IS NULL ALTER TABLE dbo._TabVyroba_Objednavky_Pol ADD PaletovyList NVARCHAR(100) NULL
IF COL_LENGTH(N'dbo._TabVyroba_Objednavky_Pol', N'SkupZbo') IS NULL ALTER TABLE dbo._TabVyroba_Objednavky_Pol ADD SkupZbo NVARCHAR(3) NULL
IF COL_LENGTH(N'dbo._TabVyroba_Objednavky_Pol', N'RegCis') IS NULL ALTER TABLE dbo._TabVyroba_Objednavky_Pol ADD RegCis NVARCHAR(30) NULL
