ALTER TABLE _setup_main ADD COLUMN email_sablon_szamla integer;
ALTER TABLE _setup_main ADD COLUMN email_sablon_proformaszamla integer;
ALTER TABLE _setup_main ADD COLUMN email_sablon_szallito integer;
ALTER TABLE _setup_main ADD COLUMN email_sablon_egyenlegkozlolevel integer;

UPDATE _setup_main SET email_sablon_szamla = 0, email_sablon_proformaszamla = 0, email_sablon_szallito = 0, email_sablon_egyenlegkozlolevel = 0;

UPDATE _setup_main SET email_sablon_szamla = (SELECT kod FROM email_sablon WHERE automata_levelkapcsolat = 1 ORDER BY kod LIMIT 1);
UPDATE _setup_main SET email_sablon_proformaszamla = (SELECT kod FROM email_sablon WHERE automata_levelkapcsolat = 1 ORDER BY kod LIMIT 1);
UPDATE _setup_main SET email_sablon_szallito = (SELECT kod FROM email_sablon WHERE automata_levelkapcsolat = 2 ORDER BY kod LIMIT 1);
UPDATE _setup_main SET email_sablon_egyenlegkozlolevel = (SELECT kod FROM email_sablon WHERE automata_levelkapcsolat = 3 ORDER BY kod LIMIT 1);

UPDATE tulajdonos SET modul = SUBSTRING(SUBSTRING(modul||repeat(' ', 1110) FROM 1 for -1+18)||'1'||SUBSTRING(modul||repeat(' ', 1110) FROM 1+18 for 999) FROM 1 for 200);