﻿/* Bednář Libor    2025-06-05 15:56:11 */

if not exists (select * from lcs.noris_templates where cislo_template = 22592)
 and exists(select * from lcs.noris_classes where cislo_tridy=343)
AND lcs.nf_is_archive() <> 'A'
begin
insert into lcs.noris_templates (cislo_template, cislo_tridy, nazev_dw, nazev_pbl, priznak_ie, ext_appl, typ, zam_id, rozsah_platnosti, seznam_poradacu, vztah, force_async, pouze_net, filter_order_browse) 
values (
22592,
343,
'dw_stitek_kkzm',
'22_acb_r.pbl',
'I',
null,
'F',
0,
'T',
null,
null,
'N',
'N',
'A'
)

IF lcs.nf_is_archive() <> 'A'
insert into lcs.repository_translate (cislo,cislo_tridy,langid,nazev,nazev2,popis,zkratka,code)
select 22592, 20, 'CZ', 'Štítek kmenové karty (GAT)', null, null, null, null
union
select 22592, 20, isnull ((select langid from lcs.repository_languages where isdefault = 'A'), 'CZ'), 'Štítek kmenové karty (GAT)', null, null, null, null
where  not exists (select * from lcs.repository_translate where cislo = 22592 and cislo_tridy = 20)

 if exists (select * from syscolumns where id = object_id('lcs.noris_templates') and name = 'potlacit_dialogove_okno') 
 begin
  exec ('
   update lcs.noris_templates set
    potlacit_dialogove_okno = ''N''
   where cislo_template = 22592
  ')
 end

end
GO

 if exists (select * from syscolumns where id = object_id('lcs.noris_templates') and name = 'kind') 
 exec ('
  update lcs.noris_templates set
    kind = ''O'' 
   where cislo_template = 22592
 ')

 if exists (select * from syscolumns where id = object_id('lcs.noris_templates') and name = 'legislative_validity_until') 
 exec ('
  update lcs.noris_templates set
    legislative_validity_until = null
   where cislo_template = 22592
 ')

 if exists (select * from syscolumns where id = object_id('lcs.noris_templates') and name = 'rozhrani_tridy') 
 exec ('
  update lcs.noris_templates set
    rozhrani_tridy =  0  
   where cislo_template = 22592
 ')
 if exists (select * from syscolumns where id = object_id('lcs.noris_templates') and name = 'namespace') 
 exec ('
  update lcs.noris_templates set
    namespace = '''' 
   where cislo_template = 22592
 ')

 if exists (select * from syscolumns where id = object_id('lcs.noris_templates') and name = 'offer_to_apply') 
 begin
  exec ('
   update lcs.noris_templates set
    offer_to_apply = ''A'' 
   where cislo_template = 22592 and offer_to_apply is null  and (typ = ''T'' or typ = ''S'') and nazev_pbl like ''gsb%'' 
  ')
  exec ('
   update lcs.noris_templates set
    offer_to_apply = case when lze_aplikovat_do_prehledu is not null and lze_aplikovat_do_prehledu = ''A'' then ''A'' else ''N'' end 
   where cislo_template = 22592 and offer_to_apply is null  and (typ = ''T'' or typ = ''S'') and nazev_pbl not like ''gsb%'' 
  ')
  exec ('
   update lcs.noris_templates set
    offer_to_apply = ''N'' 
   where cislo_template = 22592 and offer_to_apply is null  and (typ = ''F'' or typ = ''U'') and ((isnull(priznak_ie,''I'') = ''I'' and (nazev_pbl = ''jasper'' or nazev_pbl like ''%.pbl''))   or (isnull(priznak_ie,''I'') = ''E'' and provider_externi_sablony is not null) ) 
  ')
  exec ('
   update lcs.noris_templates set
    offer_to_apply = ''A'' 
   where cislo_template = 22592 and offer_to_apply is null 
  ')
 end

 if exists (select * from syscolumns where id = object_id('lcs.noris_templates') and name = 'offer_to_print') 
 begin
  exec ('
   update lcs.noris_templates set
    offer_to_print = ''A'' 
   where cislo_template = 22592 and offer_to_print is null  and (typ = ''T'' or typ = ''S'') and nazev_pbl like ''gsb%'' 
  ')
  exec ('
   update lcs.noris_templates set
    offer_to_print = ''A'' 
   where cislo_template = 22592 and offer_to_print is null  and (typ = ''T'' or typ = ''S'') and nazev_pbl not like ''gsb%'' 
  ')
  exec ('
   update lcs.noris_templates set
    offer_to_print = ''A'' 
   where cislo_template = 22592 and offer_to_print is null  and (typ = ''F'' or typ = ''U'') and ((isnull(priznak_ie,''I'') = ''I'' and (nazev_pbl = ''jasper'' or nazev_pbl like ''%.pbl''))   or (isnull(priznak_ie,''I'') = ''E'' and provider_externi_sablony is not null) ) 
  ')
  exec ('
   update lcs.noris_templates set
    offer_to_print = ''A'' 
   where cislo_template = 22592 and offer_to_print is null 
  ')
 end

if exists (select * from syscolumns where id = object_id('lcs.noris_templates') and name = 'origin') 
exec ('
   update lcs.noris_templates 
   set origin=''N''
   where cislo_template=22592
')
GO
if exists (select * from syscolumns where id = object_id('lcs.noris_templates') and name = 'pouziti_sablony_na_databazi') 
exec ('
   update lcs.noris_templates 
   set pouziti_sablony_na_databazi=''M''
   where cislo_template=22592
')
GO
IF lcs.nf_is_archive() <> 'A'
and exists (select * from sys.syscolumns where name = 'urceni' and id = object_id ('lcs.noris_templates'))
AND lcs.nf_is_archive() <> 'A'
exec ('update [lcs].[noris_templates]
set [urceni] = null
where [cislo_template] = 22592')
GO
