insert into businessunit_properties 
SELECT tenant_no,company_no,department_no,businessunit_no,'SHOW_SENZERA_POP_UP','0'
FROM businessunits
WHERE NOT EXISTS (
	SELECT * 
     FROM businessunit_properties 
     WHERE property = 'SHOW_SENZERA_POP_UP'
	 
);

CREATE TABLE EMPLOYEE_GROUP_PERMISSIONS_TEMP (tenant_no int,company_no int,employee_group_cd varchar(50),permission_cd varchar(50));
INSERT INTO EMPLOYEE_GROUP_PERMISSIONS_TEMP (tenant_no,company_no,employee_group_cd,permission_cd) select tenant_no,company_no,employee_group_cd,permission_cd from EMPLOYEE_GROUP_PERMISSIONS;
DELETE FROM EMPLOYEE_GROUP_PERMISSIONS;
INSERT INTO POS_PERMISSION_GROUPS (TENANT_NO,COMPANY_NO,PERMISSION_GROUP_CD,PERMISSION_GROUP_NM,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_DAY_CLOSURE_GROUP','Kassenabschluss',1 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_DAY_CLOSURE_ALL','Alles',1,'P_DAY_CLOSURE_GROUP','',0 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_DAY_CLOSURE_1','Kassenabschluss',0,'P_DAY_CLOSURE_GROUP','',1 FROM COMPANIES;
INSERT INTO EMPLOYEE_GROUP_PERMISSIONS (tenant_no,company_no,employee_group_cd,permission_cd) SELECT tenant_no,company_no,employee_group_cd,'P_DAY_CLOSURE_1' FROM EMPLOYEE_GROUP_PERMISSIONS_TEMP WHERE permission_cd = 'P_DO_DAY_CLOSURE';
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_DAY_CLOSURE_2','Kassenabschluss öffnen',0,'P_DAY_CLOSURE_GROUP','Vergangene Tagesabschlüsse erneut öffnen und korrigieren.',2 FROM COMPANIES;
INSERT INTO EMPLOYEE_GROUP_PERMISSIONS (tenant_no,company_no,employee_group_cd,permission_cd) SELECT tenant_no,company_no,employee_group_cd,'P_DAY_CLOSURE_2' FROM EMPLOYEE_GROUP_PERMISSIONS_TEMP WHERE permission_cd = 'P_OPEN_DAY_CLOSURE';
UPDATE POS_PERMISSION_GROUPS SET ALL_PERMISSIONS_CD = 'P_DAY_CLOSURE_ALL' WHERE PERMISSION_GROUP_CD = 'P_DAY_CLOSURE_GROUP';
INSERT INTO POS_PERMISSION_GROUPS (TENANT_NO,COMPANY_NO,PERMISSION_GROUP_CD,PERMISSION_GROUP_NM,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_CASH_IN_GROUP','Kassieren',2 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_CASH_IN_ALL','Alles',1,'P_CASH_IN_GROUP','',0 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_CASH_IN_1','Kassenübersicht',0,'P_CASH_IN_GROUP','',1 FROM COMPANIES;
INSERT INTO EMPLOYEE_GROUP_PERMISSIONS (tenant_no,company_no,employee_group_cd,permission_cd) SELECT tenant_no,company_no,employee_group_cd,'P_CASH_IN_1' FROM EMPLOYEE_GROUP_PERMISSIONS_TEMP WHERE permission_cd = 'P_CASH';
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_CASH_IN_2','Kassieren',0,'P_CASH_IN_GROUP','',2 FROM COMPANIES;
INSERT INTO EMPLOYEE_GROUP_PERMISSIONS (tenant_no,company_no,employee_group_cd,permission_cd) SELECT tenant_no,company_no,employee_group_cd,'P_CASH_IN_2' FROM EMPLOYEE_GROUP_PERMISSIONS_TEMP WHERE permission_cd = 'P_CASH';
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_CASH_IN_3','Kassenlade öffnen',0,'P_CASH_IN_GROUP','Kassenlade ausserhalb eines Zahlvorgangs per Tastenkürzel öffnen (STRG + K).',3 FROM COMPANIES;
INSERT INTO EMPLOYEE_GROUP_PERMISSIONS (tenant_no,company_no,employee_group_cd,permission_cd) SELECT tenant_no,company_no,employee_group_cd,'P_CASH_IN_3' FROM EMPLOYEE_GROUP_PERMISSIONS_TEMP WHERE permission_cd = 'P_OPEN_CASH_DRAWER';
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_CASH_IN_4','Stornieren',0,'P_CASH_IN_GROUP','Gesamtstorno für einen Bon durchführen.',4 FROM COMPANIES;
INSERT INTO EMPLOYEE_GROUP_PERMISSIONS (tenant_no,company_no,employee_group_cd,permission_cd) SELECT tenant_no,company_no,employee_group_cd,'P_CASH_IN_4' FROM EMPLOYEE_GROUP_PERMISSIONS_TEMP WHERE permission_cd = 'P_CANCEL_SALESINV';
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_CASH_IN_5','Gutschrift erstellen',0,'P_CASH_IN_GROUP','Gutschrift für einen oder mehrere Artikel erstellen.',5 FROM COMPANIES;
INSERT INTO EMPLOYEE_GROUP_PERMISSIONS (tenant_no,company_no,employee_group_cd,permission_cd) SELECT tenant_no,company_no,employee_group_cd,'P_CASH_IN_5' FROM EMPLOYEE_GROUP_PERMISSIONS_TEMP WHERE permission_cd = 'P_CREATE_CN';
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_CASH_IN_6','Gutscheine deaktivieren',0,'P_CASH_IN_GROUP','',6 FROM COMPANIES;
INSERT INTO EMPLOYEE_GROUP_PERMISSIONS (tenant_no,company_no,employee_group_cd,permission_cd) SELECT tenant_no,company_no,employee_group_cd,'P_CASH_IN_6' FROM EMPLOYEE_GROUP_PERMISSIONS_TEMP WHERE permission_cd = 'P_DEACTIVATE_VOUCHER';
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_CASH_IN_7','Trinkgeld ändern',0,'P_CASH_IN_GROUP','Das gegebene Trinkgeld ändern. (Nur bei aktivierter Trinkgeld Funktion.)',7 FROM COMPANIES;
INSERT INTO EMPLOYEE_GROUP_PERMISSIONS (tenant_no,company_no,employee_group_cd,permission_cd) SELECT tenant_no,company_no,employee_group_cd,'P_CASH_IN_7' FROM EMPLOYEE_GROUP_PERMISSIONS_TEMP WHERE permission_cd = 'P_CHANGE_TIP';
UPDATE POS_PERMISSION_GROUPS SET ALL_PERMISSIONS_CD = 'P_CASH_IN_ALL' WHERE PERMISSION_GROUP_CD = 'P_CASH_IN_GROUP';
INSERT INTO POS_PERMISSION_GROUPS (TENANT_NO,COMPANY_NO,PERMISSION_GROUP_CD,PERMISSION_GROUP_NM,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_GROUP','Statistiken',3 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_ALL','Alle Statistiken',1,'P_STATISTICS_GROUP','',0 FROM COMPANIES;
INSERT INTO EMPLOYEE_GROUP_PERMISSIONS (tenant_no,company_no,employee_group_cd,permission_cd) SELECT tenant_no,company_no,employee_group_cd,'P_STATISTICS_ALL' FROM EMPLOYEE_GROUP_PERMISSIONS_TEMP WHERE permission_cd = 'P_STATISTICS';
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_POS_1','Kassenbuch',0,'P_STATISTICS_GROUP','',1 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_POS_2','Filialbericht',0,'P_STATISTICS_GROUP','',2 FROM COMPANIES;
INSERT INTO EMPLOYEE_GROUP_PERMISSIONS (tenant_no,company_no,employee_group_cd,permission_cd) SELECT tenant_no,company_no,employee_group_cd,'P_STATISTICS_POS_2' FROM EMPLOYEE_GROUP_PERMISSIONS_TEMP WHERE permission_cd = 'P_POS_REPORT';
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_POS_3','Gutscheine',0,'P_STATISTICS_GROUP','',3 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_POS_4','Offene Gutscheine',0,'P_STATISTICS_GROUP','',4 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_CONTACTS_1','Kundenliste',0,'P_STATISTICS_GROUP','',5 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_CONTACTS_2','Neukundenliste',0,'P_STATISTICS_GROUP','',6 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_CONTACTS_3','Ausgebliebene / Wiederkehrende Kunden',0,'P_STATISTICS_GROUP','',7 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_CONTACTS_4','Geburtstagsliste',0,'P_STATISTICS_GROUP','',8 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_CONTACTS_5','Kundenkaufverhalten',0,'P_STATISTICS_GROUP','',9 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_SALES_1','Umsatz pro Mitarbeiter',0,'P_STATISTICS_GROUP','',10 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_SALES_2','Umsatz pro Tag',0,'P_STATISTICS_GROUP','',11 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_SALES_3','Kurzbericht pro Mitarbeiter',0,'P_STATISTICS_GROUP','',12 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_SALES_4','Umsatzentwicklung',0,'P_STATISTICS_GROUP','',13 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_SALES_5','Umsatzentwicklung VK',0,'P_STATISTICS_GROUP','',14 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_SALES_6','Periodenvergleich Entwicklung',0,'P_STATISTICS_GROUP','',15 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_SALES_7','Periodenvergleich',0,'P_STATISTICS_GROUP','',16 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_SALES_8','Rabattaktionen',0,'P_STATISTICS_GROUP','',17 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_SALES_9','Rabattaktion nach Kunden',0,'P_STATISTICS_GROUP','',18 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_SALES_10','Hitliste Artikelverkauf',0,'P_STATISTICS_GROUP','',19 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_SALES_11','Hitliste Dienstleistungsverkauf',0,'P_STATISTICS_GROUP','',20 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_SALES_12','Periodenvergleich kompakt MA',0,'P_STATISTICS_GROUP','',21 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_SALES_13','Trinkgeld',0,'P_STATISTICS_GROUP','',22 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_STOCKS_1','Lagerbewegungen',0,'P_STATISTICS_GROUP','',23 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_COMPANY_COMPARSION_1','BV kumuliert',0,'P_STATISTICS_GROUP','',24 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_COMPANY_COMPARSION_2','BV Periodenvergleich',0,'P_STATISTICS_GROUP','',25 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_COMPANY_COMPARSION_3','BV Entwicklung',0,'P_STATISTICS_GROUP','',26 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_STATISTIC_EXPORT_1','Statistikexport nach Zöllner',0,'P_STATISTICS_GROUP','',27 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_STATISTICS_EMPLOYEE_1','Anwesenheitsbericht',0,'P_STATISTICS_GROUP','',28 FROM COMPANIES;
UPDATE POS_PERMISSION_GROUPS SET ALL_PERMISSIONS_CD = 'P_STATISTICS_ALL' WHERE PERMISSION_GROUP_CD = 'P_STATISTICS_GROUP';
INSERT INTO POS_PERMISSION_GROUPS (TENANT_NO,COMPANY_NO,PERMISSION_GROUP_CD,PERMISSION_GROUP_NM,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_CONTACTS_GROUP','Kunden',4 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_CONTACTS_ALL','Alles',1,'P_CONTACTS_GROUP','',1 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_CONTACTS_1','Karten',0,'P_CONTACTS_GROUP','Den Menüpunkt ''Karten'' einsehen und Karten stornieren. (Nur bei aktiviertem Planet)',2 FROM COMPANIES;
INSERT INTO EMPLOYEE_GROUP_PERMISSIONS (tenant_no,company_no,employee_group_cd,permission_cd) SELECT tenant_no,company_no,employee_group_cd,'P_CONTACTS_1' FROM EMPLOYEE_GROUP_PERMISSIONS_TEMP WHERE permission_cd = 'P_CENTRAL_CARDS';
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_CONTACTS_2','Kundenpunkte',0,'P_CONTACTS_GROUP','Punktestand eines Kunden manuell anpassen.',3 FROM COMPANIES;
INSERT INTO EMPLOYEE_GROUP_PERMISSIONS (tenant_no,company_no,employee_group_cd,permission_cd) SELECT tenant_no,company_no,employee_group_cd,'P_CONTACTS_2' FROM EMPLOYEE_GROUP_PERMISSIONS_TEMP WHERE permission_cd = 'P_MOD_CCC_POINTS';
UPDATE POS_PERMISSION_GROUPS SET ALL_PERMISSIONS_CD = 'P_CONTACTS_ALL' WHERE PERMISSION_GROUP_CD = 'P_CONTACTS_GROUP';
INSERT INTO POS_PERMISSION_GROUPS (TENANT_NO,COMPANY_NO,PERMISSION_GROUP_CD,PERMISSION_GROUP_NM,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_SETTINGS_GROUP','Einstellungen',5 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_SETTINGS_ALL','Alle',1,'P_SETTINGS_GROUP','',0 FROM COMPANIES;
INSERT INTO EMPLOYEE_GROUP_PERMISSIONS (tenant_no,company_no,employee_group_cd,permission_cd) SELECT tenant_no,company_no,employee_group_cd,'P_SETTINGS_ALL' FROM EMPLOYEE_GROUP_PERMISSIONS_TEMP WHERE permission_cd = 'P_MASTERDATA';
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_SETTINGS_1','Geschäftsstammdaten',0,'P_SETTINGS_GROUP','Geschäftsstammdaten einsehen und ändern.',1 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_SETTINGS_2','Mitarbeiterstammdaten',0,'P_SETTINGS_GROUP','Mitarbeiterstammdaten einsehen und ändern.',2 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_SETTINGS_3','Benutzerrollen',0,'P_SETTINGS_GROUP','Benutzerrollen einsehen und ändern.',3 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_SETTINGS_4','Produktkatalog',0,'P_SETTINGS_GROUP','Produkte, Dienstleistungen, Pakete und Artikelgruppen verwalten.',4 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_SETTINGS_5','Preislisten',0,'P_SETTINGS_GROUP','Preise anpassen und Gültigkeiten von Preislisten ändern.',5 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_SETTINGS_7','Konfiguration',0,'P_SETTINGS_GROUP','Allgemeine Einstellungen der Kasse ändern. (Konten, Drucker, etc.)',6 FROM COMPANIES;
UPDATE POS_PERMISSION_GROUPS SET ALL_PERMISSIONS_CD = 'P_SETTINGS_ALL' WHERE PERMISSION_GROUP_CD = 'P_SETTINGS_GROUP';
INSERT INTO POS_PERMISSION_GROUPS (TENANT_NO,COMPANY_NO,PERMISSION_GROUP_CD,PERMISSION_GROUP_NM,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_DASHBOARD_GROUP','Umsatzbarometer',6 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_DASHBOARD_ALL','Alles',1,'P_DASHBOARD_GROUP','',1 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_DASHBOARD_1','Umsatzbarometer',0,'P_DASHBOARD_GROUP','Umsatzbarometer einsehen.',2 FROM COMPANIES;
INSERT INTO EMPLOYEE_GROUP_PERMISSIONS (tenant_no,company_no,employee_group_cd,permission_cd) SELECT tenant_no,company_no,employee_group_cd,'P_DASHBOARD_1' FROM EMPLOYEE_GROUP_PERMISSIONS_TEMP WHERE permission_cd = 'P_REV_DASHBOARD';
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_DASHBOARD_2','Umsatzbarometer Gesamtumsatz',0,'P_DASHBOARD_GROUP','Gesamtumsatz des Salons innerhalb des gewählten Zeitraums anzeigen.',3 FROM COMPANIES;
INSERT INTO EMPLOYEE_GROUP_PERMISSIONS (tenant_no,company_no,employee_group_cd,permission_cd) SELECT tenant_no,company_no,employee_group_cd,'P_DASHBOARD_2' FROM EMPLOYEE_GROUP_PERMISSIONS_TEMP WHERE permission_cd = 'P_SHOW_DASHBOARD_SUMMARY';
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_DASHBOARD_3','Umsatzbarometer Zeit ändern',0,'P_DASHBOARD_GROUP','Anzeigezeitraum des Umsatzbarometers ändern.',4 FROM COMPANIES;
INSERT INTO EMPLOYEE_GROUP_PERMISSIONS (tenant_no,company_no,employee_group_cd,permission_cd) SELECT tenant_no,company_no,employee_group_cd,'P_DASHBOARD_3' FROM EMPLOYEE_GROUP_PERMISSIONS_TEMP WHERE permission_cd = 'P_CHANGE_DASHBOARD_TIMERANGE';
UPDATE POS_PERMISSION_GROUPS SET ALL_PERMISSIONS_CD = 'P_DASHBOARD_ALL' WHERE PERMISSION_GROUP_CD = 'P_DASHBOARD_GROUP';
INSERT INTO POS_PERMISSION_GROUPS (TENANT_NO,COMPANY_NO,PERMISSION_GROUP_CD,PERMISSION_GROUP_NM,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_EXPORT','Exporte und Archive',7 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_EXPORT_ALL','Alles',1,'P_EXPORT','',1 FROM COMPANIES;
INSERT INTO EMPLOYEE_GROUP_PERMISSIONS (tenant_no,company_no,employee_group_cd,permission_cd) SELECT tenant_no,company_no,employee_group_cd,'P_EXPORT_ALL' FROM EMPLOYEE_GROUP_PERMISSIONS_TEMP WHERE permission_cd = 'P_STATISTICS';
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_EXPORT_1','Exporte',0,'P_EXPORT','',2 FROM COMPANIES;
INSERT INTO POS_PERMISSIONS (TENANT_NO,COMPANY_NO,PERMISSION_CD,PERMISSION_NM,INVISIBLE,PERMISSION_GROUP_CD,permission_desc,ORDER_NO) SELECT TENANT_NO,COMPANY_NO,'P_EXPORT_2','Archiv',0,'P_EXPORT','',3 FROM COMPANIES;
UPDATE POS_PERMISSION_GROUPS SET ALL_PERMISSIONS_CD = 'P_EXPORT_ALL' WHERE PERMISSION_GROUP_CD = 'P_EXPORT';
DROP TABLE EMPLOYEE_GROUP_PERMISSIONS_TEMP;


-- schneide die Millisekunden bei den Konditionen ab -- aufräumen 

 CREATE TABLE customer_contract_conditions_tmp
(
   TENANT_NO int NOT NULL,
   CONTACT_NO int NOT NULL,
   COMPANY_NO int NOT NULL,
   DEPARTMENT_NO int NOT NULL,
   CUSTOMER_NO int NOT NULL,
   CUSTOMER_CONTRACT_NO int NOT NULL,
   VALID_FROM timestamp NOT NULL,
   VALID_TO timestamp,
   CONDITION_CD varchar(10),
   CARD_UID varchar(36),
   CARD_NO varchar(30),
   CARD_USAGE_ID int,
   DELETED smallint,
   UPDATE_CNT bigint
   
)
;


INSERT INTO customer_contract_conditions_tmp
           ( tenant_no 
        
           , contact_no 
           , company_no 
           , department_no 
           , customer_no 
           , customer_contract_no 
           , valid_from 
           , valid_to 
           , condition_cd 
           , card_uid 
           , card_no 
           , card_usage_id 
           , deleted 
           , update_cnt )
      (
	 SELECT 
	  tenant_no 
   
           , contact_no 
           , company_no 
           , department_no 
           , customer_no 
           , customer_contract_no 
           ,  cast (SUBSTR( CAST (valid_from AS varchar(23)),1,19) as TIMESTAMP) 
           , valid_to 
           , condition_cd 
           , card_uid 
           , card_no 
           , card_usage_id 
           , deleted 
           , update_cnt 
	 FROM customer_contract_conditions )
;


	  DELETE FROM  customer_contract_conditions;

  INSERT INTO customer_contract_conditions
           ( tenant_no 
           , contact_no 
           , company_no 
           , department_no 
           , customer_no 
           , customer_contract_no 
           , valid_from 
           , valid_to 
           , condition_cd 
           , card_uid 
           , card_no 
           , card_usage_id 
           , deleted 
           , update_cnt )
      (
	 SELECT 
	  tenant_no 
           , contact_no 
           , company_no 
           , department_no 
           , customer_no 
           , customer_contract_no 
           , valid_from
           , valid_to 
           , condition_cd 
           , card_uid 
           , card_no 
           , card_usage_id 
           , deleted 
           , update_cnt
	 FROM customer_contract_conditions_tmp );


    DROP TABLE  customer_contract_conditions_tmp;
