@flowselections/floriday-klanten-module 1.0.64 → 1.0.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-lib/components/klanten/CarrierAdminCard.d.ts +3 -0
- package/dist-lib/components/klanten/CarrierAdminCard.d.ts.map +1 -0
- package/dist-lib/components/klanten/CarrierAdminCard.js +23 -0
- package/dist-lib/components/klanten/CarrierPicker.d.ts +221 -0
- package/dist-lib/components/klanten/CarrierPicker.d.ts.map +1 -0
- package/dist-lib/components/klanten/CarrierPicker.js +74 -0
- package/dist-lib/components/klanten/CustomerCarrierCard.d.ts +5 -0
- package/dist-lib/components/klanten/CustomerCarrierCard.d.ts.map +1 -0
- package/dist-lib/components/klanten/CustomerCarrierCard.js +36 -0
- package/dist-lib/components/klanten/DeliveryLocationsTab.d.ts.map +1 -1
- package/dist-lib/components/klanten/DeliveryLocationsTab.js +38 -45
- package/dist-lib/components/klanten/KlantDetail.d.ts.map +1 -1
- package/dist-lib/components/klanten/KlantDetail.js +2 -1
- package/dist-lib/components/klanten/KlantFormulier.d.ts.map +1 -1
- package/dist-lib/components/klanten/KlantFormulier.js +8 -12
- package/dist-lib/components/klanten/KlantenOverzicht.d.ts.map +1 -1
- package/dist-lib/components/klanten/KlantenOverzicht.js +7 -3
- package/dist-lib/integrations/supabase/types.d.ts +1357 -28
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/dist-lib/lib/carrier-choice.d.ts +60 -0
- package/dist-lib/lib/carrier-choice.d.ts.map +1 -0
- package/dist-lib/lib/carrier-choice.js +68 -0
- package/dist-lib/lib/carriers.functions.d.ts +82 -0
- package/dist-lib/lib/carriers.functions.d.ts.map +1 -0
- package/dist-lib/lib/carriers.functions.js +180 -0
- package/dist-lib/lib/countries.d.ts +2 -0
- package/dist-lib/lib/countries.d.ts.map +1 -1
- package/dist-lib/lib/countries.js +2 -0
- package/dist-lib/lib/customer-schemas.d.ts +108 -2
- package/dist-lib/lib/customer-schemas.d.ts.map +1 -1
- package/dist-lib/lib/customer-schemas.js +15 -1
- package/dist-lib/lib/customers.functions.d.ts +4 -1
- package/dist-lib/lib/customers.functions.d.ts.map +1 -1
- package/dist-lib/lib/customers.functions.js +7 -0
- package/dist-lib/lib/delivery-locations.functions.d.ts +2 -2
- package/dist-lib/lib/delivery-locations.functions.d.ts.map +1 -1
- package/dist-lib/lib/delivery-locations.functions.js +31 -38
- package/dist-lib/lib/price-groups-local.functions.d.ts.map +1 -1
- package/dist-lib/lib/price-groups-local.functions.js +4 -1
- package/dist-lib/lib/twinfield-adopt.functions.d.ts +2 -1
- package/dist-lib/lib/twinfield-adopt.functions.d.ts.map +1 -1
- package/dist-lib/lib/twinfield-adopt.functions.js +2 -2
- package/dist-lib/lib/twinfield-customer-defaults.server.js +2 -2
- package/package.json +11 -3
- package/schema/klanten.sql +514 -48
package/schema/klanten.sql
CHANGED
|
@@ -171,7 +171,8 @@ SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN
|
|
|
171
171
|
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS address text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS address text');
|
|
172
172
|
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS city text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS city text');
|
|
173
173
|
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS postal_code text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS postal_code text');
|
|
174
|
-
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS country text
|
|
174
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS country text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS country text');
|
|
175
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ALTER COLUMN country DROP DEFAULT$klanten_stmt$, 'ALTER TABLE public.customers ALTER COLUMN country DROP DEFAULT');
|
|
175
176
|
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS notes text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS notes text');
|
|
176
177
|
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS custom_fields jsonb DEFAULT '{}'::jsonb NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS custom_fields jsonb DEFAULT ''{}''::jsonb NOT NU');
|
|
177
178
|
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT no');
|
|
@@ -254,6 +255,7 @@ SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN
|
|
|
254
255
|
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS blocked_locked boolean$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS blocked_locked boolean');
|
|
255
256
|
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS blocked_modified text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS blocked_modified text');
|
|
256
257
|
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS twinfield_create_on_insert boolean DEFAULT true NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS twinfield_create_on_insert boolean DEFAULT tru');
|
|
258
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS default_carrier_id uuid$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS default_carrier_id uuid');
|
|
257
259
|
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TABLE IF NOT EXISTS public.external_customer_providers ()$klanten_stmt$, 'CREATE TABLE IF NOT EXISTS public.external_customer_providers ()');
|
|
258
260
|
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.external_customer_providers ADD COLUMN IF NOT EXISTS provider text NOT NULL$klanten_stmt$, 'ALTER TABLE public.external_customer_providers ADD COLUMN IF NOT EXISTS provider text NOT NULL');
|
|
259
261
|
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.external_customer_providers ADD COLUMN IF NOT EXISTS label text NOT NULL$klanten_stmt$, 'ALTER TABLE public.external_customer_providers ADD COLUMN IF NOT EXISTS label text NOT NULL');
|
|
@@ -357,24 +359,24 @@ SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FR
|
|
|
357
359
|
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_logistics_strategy_pkey' AND conrelid='public.customer_logistics_strategy'::regclass) THEN ALTER TABLE public.customer_logistics_strategy ADD CONSTRAINT customer_logistics_strategy_pkey PRIMARY KEY (id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_logistics_strategy_p');
|
|
358
360
|
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_agreements_pkey' AND conrelid='public.local_customer_agreements'::regclass) THEN ALTER TABLE public.local_customer_agreements ADD CONSTRAINT local_customer_agreements_pkey PRIMARY KEY (id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''local_customer_agreements_pke');
|
|
359
361
|
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customers_pkey' AND conrelid='public.customers'::regclass) THEN ALTER TABLE public.customers ADD CONSTRAINT customers_pkey PRIMARY KEY (id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customers_pkey'' AND conrelid=');
|
|
360
|
-
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_price_groups_product_category_id_fkey' AND conrelid='public.local_customer_price_groups'::regclass) THEN ALTER TABLE public.local_customer_price_groups ADD CONSTRAINT local_customer_price_groups_product_category_id_fkey FOREIGN KEY (product_category_id) REFERENCES product_categories(id) ON DELETE SET NULL; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF
|
|
362
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF to_regclass('public.product_categories') IS NULL THEN RAISE NOTICE 'Klanten: verwijzing naar product_categories volgt bij de tweede ronde (local_customer_price_groups_product_category_id_fkey)'; ELSIF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_price_groups_product_category_id_fkey' AND conrelid='public.local_customer_price_groups'::regclass) THEN ALTER TABLE public.local_customer_price_groups ADD CONSTRAINT local_customer_price_groups_product_category_id_fkey FOREIGN KEY (product_category_id) REFERENCES product_categories(id) ON DELETE SET NULL; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF to_regclass(''public.product_categories'') IS NULL THEN RAISE NOTICE ''Klanten: verwijz');
|
|
361
363
|
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_contacts_customer_id_fkey' AND conrelid='public.customer_contacts'::regclass) THEN ALTER TABLE public.customer_contacts ADD CONSTRAINT customer_contacts_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_contacts_customer_id');
|
|
362
|
-
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_delivery_locations_carrier_id_fkey' AND conrelid='public.customer_delivery_locations'::regclass) THEN ALTER TABLE public.customer_delivery_locations ADD CONSTRAINT customer_delivery_locations_carrier_id_fkey FOREIGN KEY (carrier_id) REFERENCES carriers(id) ON DELETE SET NULL; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF
|
|
364
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF to_regclass('public.carriers') IS NULL THEN RAISE NOTICE 'Klanten: verwijzing naar carriers volgt bij de tweede ronde (customer_delivery_locations_carrier_id_fkey)'; ELSIF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_delivery_locations_carrier_id_fkey' AND conrelid='public.customer_delivery_locations'::regclass) THEN ALTER TABLE public.customer_delivery_locations ADD CONSTRAINT customer_delivery_locations_carrier_id_fkey FOREIGN KEY (carrier_id) REFERENCES carriers(id) ON DELETE SET NULL; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF to_regclass(''public.carriers'') IS NULL THEN RAISE NOTICE ''Klanten: verwijzing naar c');
|
|
363
365
|
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_delivery_locations_customer_id_fkey' AND conrelid='public.customer_delivery_locations'::regclass) THEN ALTER TABLE public.customer_delivery_locations ADD CONSTRAINT customer_delivery_locations_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_delivery_locations_c');
|
|
364
|
-
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_logistics_strategy_strategy_id_fkey' AND conrelid='public.customer_logistics_strategy'::regclass) THEN ALTER TABLE public.customer_logistics_strategy ADD CONSTRAINT customer_logistics_strategy_strategy_id_fkey FOREIGN KEY (strategy_id) REFERENCES logistics_strategies(id) ON DELETE SET NULL; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF
|
|
366
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF to_regclass('public.logistics_strategies') IS NULL THEN RAISE NOTICE 'Klanten: verwijzing naar logistics_strategies volgt bij de tweede ronde (customer_logistics_strategy_strategy_id_fkey)'; ELSIF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_logistics_strategy_strategy_id_fkey' AND conrelid='public.customer_logistics_strategy'::regclass) THEN ALTER TABLE public.customer_logistics_strategy ADD CONSTRAINT customer_logistics_strategy_strategy_id_fkey FOREIGN KEY (strategy_id) REFERENCES logistics_strategies(id) ON DELETE SET NULL; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF to_regclass(''public.logistics_strategies'') IS NULL THEN RAISE NOTICE ''Klanten: verwi');
|
|
365
367
|
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_notes_customer_id_fkey' AND conrelid='public.customer_notes'::regclass) THEN ALTER TABLE public.customer_notes ADD CONSTRAINT customer_notes_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_notes_customer_id_fk');
|
|
366
368
|
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_price_group_members_price_group_id_fkey' AND conrelid='public.customer_price_group_members'::regclass) THEN ALTER TABLE public.customer_price_group_members ADD CONSTRAINT customer_price_group_members_price_group_id_fkey FOREIGN KEY (price_group_id) REFERENCES customer_price_groups(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_price_group_members_');
|
|
367
369
|
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_selected_assortment_customer_id_fkey' AND conrelid='public.customer_selected_assortment'::regclass) THEN ALTER TABLE public.customer_selected_assortment ADD CONSTRAINT customer_selected_assortment_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_selected_assortment_');
|
|
368
370
|
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_trade_settings_customer_id_fkey' AND conrelid='public.customer_trade_settings'::regclass) THEN ALTER TABLE public.customer_trade_settings ADD CONSTRAINT customer_trade_settings_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_trade_settings_custo');
|
|
369
371
|
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_match_suggestions_customer_id_fkey' AND conrelid='public.customer_match_suggestions'::regclass) THEN ALTER TABLE public.customer_match_suggestions ADD CONSTRAINT customer_match_suggestions_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_match_suggestions_cu');
|
|
370
372
|
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_agreements_customer_id_fkey' AND conrelid='public.local_customer_agreements'::regclass) THEN ALTER TABLE public.local_customer_agreements ADD CONSTRAINT local_customer_agreements_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''local_customer_agreements_cus');
|
|
371
|
-
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_agreements_product_category_id_fkey' AND conrelid='public.local_customer_agreements'::regclass) THEN ALTER TABLE public.local_customer_agreements ADD CONSTRAINT local_customer_agreements_product_category_id_fkey FOREIGN KEY (product_category_id) REFERENCES product_categories(id) ON DELETE SET NULL; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF
|
|
372
|
-
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_agreements_product_id_fkey' AND conrelid='public.local_customer_agreements'::regclass) THEN ALTER TABLE public.local_customer_agreements ADD CONSTRAINT local_customer_agreements_product_id_fkey FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF
|
|
373
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF to_regclass('public.product_categories') IS NULL THEN RAISE NOTICE 'Klanten: verwijzing naar product_categories volgt bij de tweede ronde (local_customer_agreements_product_category_id_fkey)'; ELSIF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_agreements_product_category_id_fkey' AND conrelid='public.local_customer_agreements'::regclass) THEN ALTER TABLE public.local_customer_agreements ADD CONSTRAINT local_customer_agreements_product_category_id_fkey FOREIGN KEY (product_category_id) REFERENCES product_categories(id) ON DELETE SET NULL; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF to_regclass(''public.product_categories'') IS NULL THEN RAISE NOTICE ''Klanten: verwijz');
|
|
374
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF to_regclass('public.products') IS NULL THEN RAISE NOTICE 'Klanten: verwijzing naar products volgt bij de tweede ronde (local_customer_agreements_product_id_fkey)'; ELSIF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_agreements_product_id_fkey' AND conrelid='public.local_customer_agreements'::regclass) THEN ALTER TABLE public.local_customer_agreements ADD CONSTRAINT local_customer_agreements_product_id_fkey FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF to_regclass(''public.products'') IS NULL THEN RAISE NOTICE ''Klanten: verwijzing naar p');
|
|
373
375
|
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_price_groups_customer_id_fkey' AND conrelid='public.local_customer_price_groups'::regclass) THEN ALTER TABLE public.local_customer_price_groups ADD CONSTRAINT local_customer_price_groups_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''local_customer_price_groups_c');
|
|
374
|
-
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_price_groups_product_id_fkey' AND conrelid='public.local_customer_price_groups'::regclass) THEN ALTER TABLE public.local_customer_price_groups ADD CONSTRAINT local_customer_price_groups_product_id_fkey FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF
|
|
376
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF to_regclass('public.products') IS NULL THEN RAISE NOTICE 'Klanten: verwijzing naar products volgt bij de tweede ronde (local_customer_price_groups_product_id_fkey)'; ELSIF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_price_groups_product_id_fkey' AND conrelid='public.local_customer_price_groups'::regclass) THEN ALTER TABLE public.local_customer_price_groups ADD CONSTRAINT local_customer_price_groups_product_id_fkey FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF to_regclass(''public.products'') IS NULL THEN RAISE NOTICE ''Klanten: verwijzing naar p');
|
|
375
377
|
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_sales_strategies_customer_id_fkey' AND conrelid='public.local_customer_sales_strategies'::regclass) THEN ALTER TABLE public.local_customer_sales_strategies ADD CONSTRAINT local_customer_sales_strategies_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''local_customer_sales_strategi');
|
|
376
|
-
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_sales_strategies_product_category_id_fkey' AND conrelid='public.local_customer_sales_strategies'::regclass) THEN ALTER TABLE public.local_customer_sales_strategies ADD CONSTRAINT local_customer_sales_strategies_product_category_id_fkey FOREIGN KEY (product_category_id) REFERENCES product_categories(id) ON DELETE SET NULL; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF
|
|
377
|
-
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_sales_strategies_product_id_fkey' AND conrelid='public.local_customer_sales_strategies'::regclass) THEN ALTER TABLE public.local_customer_sales_strategies ADD CONSTRAINT local_customer_sales_strategies_product_id_fkey FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF
|
|
378
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF to_regclass('public.product_categories') IS NULL THEN RAISE NOTICE 'Klanten: verwijzing naar product_categories volgt bij de tweede ronde (local_customer_sales_strategies_product_category_id_fkey)'; ELSIF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_sales_strategies_product_category_id_fkey' AND conrelid='public.local_customer_sales_strategies'::regclass) THEN ALTER TABLE public.local_customer_sales_strategies ADD CONSTRAINT local_customer_sales_strategies_product_category_id_fkey FOREIGN KEY (product_category_id) REFERENCES product_categories(id) ON DELETE SET NULL; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF to_regclass(''public.product_categories'') IS NULL THEN RAISE NOTICE ''Klanten: verwijz');
|
|
379
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF to_regclass('public.products') IS NULL THEN RAISE NOTICE 'Klanten: verwijzing naar products volgt bij de tweede ronde (local_customer_sales_strategies_product_id_fkey)'; ELSIF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_sales_strategies_product_id_fkey' AND conrelid='public.local_customer_sales_strategies'::regclass) THEN ALTER TABLE public.local_customer_sales_strategies ADD CONSTRAINT local_customer_sales_strategies_product_id_fkey FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF to_regclass(''public.products'') IS NULL THEN RAISE NOTICE ''Klanten: verwijzing naar p');
|
|
378
380
|
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_logistics_strategy_scope_check' AND conrelid='public.customer_logistics_strategy'::regclass) THEN ALTER TABLE public.customer_logistics_strategy ADD CONSTRAINT customer_logistics_strategy_scope_check CHECK ((scope = ANY (ARRAY['customer'::text, 'group'::text]))); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_logistics_strategy_s');
|
|
379
381
|
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customers_sync_status_check' AND conrelid='public.customers'::regclass) THEN ALTER TABLE public.customers ADD CONSTRAINT customers_sync_status_check CHECK ((sync_status = ANY (ARRAY['idle'::text, 'syncing'::text, 'synced'::text, 'error'::text]))); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customers_sync_status_check'' ');
|
|
380
382
|
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customers_source_check' AND conrelid='public.customers'::regclass) THEN ALTER TABLE public.customers ADD CONSTRAINT customers_source_check CHECK ((source = ANY (ARRAY['local'::text, 'floriday'::text]))); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customers_source_check'' AND c');
|
|
@@ -389,6 +391,7 @@ SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FR
|
|
|
389
391
|
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_price_groups_calc_type_check' AND conrelid='public.customer_price_groups'::regclass) THEN ALTER TABLE public.customer_price_groups ADD CONSTRAINT customer_price_groups_calc_type_check CHECK ((calc_type = ANY (ARRAY['discount'::text, 'surcharge'::text]))); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_price_groups_calc_ty');
|
|
390
392
|
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_notes_one_owner' AND conrelid='public.customer_notes'::regclass) THEN ALTER TABLE public.customer_notes ADD CONSTRAINT customer_notes_one_owner CHECK ((((customer_id IS NOT NULL) AND (group_key IS NULL)) OR ((customer_id IS NULL) AND (group_key IS NOT NULL)))); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_notes_one_owner'' AND');
|
|
391
393
|
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_delivery_locations_carrier_assignment_source_check' AND conrelid='public.customer_delivery_locations'::regclass) THEN ALTER TABLE public.customer_delivery_locations ADD CONSTRAINT customer_delivery_locations_carrier_assignment_source_check CHECK ((carrier_assignment_source = ANY (ARRAY['auto'::text, 'manual'::text, 'none'::text]))); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_delivery_locations_c');
|
|
394
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF to_regclass('public.carriers') IS NULL THEN RAISE NOTICE 'Klanten: verwijzing naar carriers volgt bij de tweede ronde (customers_default_carrier_id_fkey)'; ELSIF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customers_default_carrier_id_fkey' AND conrelid='public.customers'::regclass) THEN ALTER TABLE public.customers ADD CONSTRAINT customers_default_carrier_id_fkey FOREIGN KEY (default_carrier_id) REFERENCES carriers(id) ON DELETE RESTRICT; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF to_regclass(''public.carriers'') IS NULL THEN RAISE NOTICE ''Klanten: verwijzing naar c');
|
|
392
395
|
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_customer_delivery_locations_customer ON public.customer_delivery_locations USING btree (customer_id)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_customer_delivery_locations_customer ON public.customer_delivery_loca');
|
|
393
396
|
SELECT pg_temp.klanten_try($klanten_stmt$CREATE UNIQUE INDEX IF NOT EXISTS customers_twinfield_code_key ON public.customers USING btree (twinfield_code) WHERE (twinfield_code IS NOT NULL)$klanten_stmt$, 'CREATE UNIQUE INDEX IF NOT EXISTS customers_twinfield_code_key ON public.customers USING btree (twin');
|
|
394
397
|
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_cdl_floriday_location ON public.customer_delivery_locations USING btree (floriday_location_id)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_cdl_floriday_location ON public.customer_delivery_locations USING btr');
|
|
@@ -439,28 +442,429 @@ SELECT pg_temp.klanten_try($klanten_stmt$CREATE UNIQUE INDEX IF NOT EXISTS custo
|
|
|
439
442
|
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_customers_email ON public.customers USING btree (email)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_customers_email ON public.customers USING btree (email)');
|
|
440
443
|
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_customers_class ON public.customers USING btree (customer_class)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_customers_class ON public.customers USING btree (customer_class)');
|
|
441
444
|
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_customer_notes_customer_id ON public.customer_notes USING btree (customer_id)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_customer_notes_customer_id ON public.customer_notes USING btree (cust');
|
|
442
|
-
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.
|
|
443
|
-
RETURNS
|
|
445
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.klanten_is_server()
|
|
446
|
+
RETURNS boolean
|
|
447
|
+
LANGUAGE sql
|
|
448
|
+
STABLE
|
|
449
|
+
SET search_path TO 'public'
|
|
450
|
+
AS $function$
|
|
451
|
+
SELECT COALESCE(NULLIF(current_setting('request.jwt.claims', true), '')::jsonb ->> 'role', '') = 'service_role'
|
|
452
|
+
OR session_user::text <> 'authenticator';
|
|
453
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.klanten_is_server() RETURNS boolean LANGUAGE sql STABLE SET search');
|
|
454
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.klanten_toegang(p_niveau text)
|
|
455
|
+
RETURNS void
|
|
444
456
|
LANGUAGE plpgsql
|
|
445
|
-
SECURITY DEFINER
|
|
457
|
+
STABLE SECURITY DEFINER
|
|
446
458
|
SET search_path TO 'public'
|
|
447
459
|
AS $function$
|
|
448
460
|
BEGIN
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
461
|
+
IF public.klanten_is_server() OR pg_trigger_depth() > 0 THEN RETURN; END IF;
|
|
462
|
+
IF p_niveau = 'server' THEN
|
|
463
|
+
RAISE EXCEPTION 'Deze functie mag alleen door de server worden aangeroepen.' USING ERRCODE = '42501';
|
|
464
|
+
END IF;
|
|
465
|
+
IF auth.uid() IS NULL THEN
|
|
466
|
+
RAISE EXCEPTION 'Je moet ingelogd zijn om deze functie te gebruiken.' USING ERRCODE = '42501';
|
|
467
|
+
END IF;
|
|
468
|
+
IF p_niveau = 'ingelogd' THEN RETURN; END IF;
|
|
469
|
+
IF p_niveau = 'beheerder' AND public.has_role(auth.uid(), 'admin'::public.app_role) THEN RETURN; END IF;
|
|
470
|
+
RAISE EXCEPTION 'Alleen beheerders mogen deze functie gebruiken.' USING ERRCODE = '42501';
|
|
471
|
+
END
|
|
472
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.klanten_toegang(p_niveau text) RETURNS void LANGUAGE plpgsql STABL');
|
|
473
|
+
SELECT pg_temp.klanten_try($klanten_stmt$REVOKE ALL ON FUNCTION public.klanten_toegang(text) FROM PUBLIC, anon, authenticated$klanten_stmt$, 'REVOKE ALL ON FUNCTION public.klanten_toegang(text) FROM PUBLIC, anon, authenticated');
|
|
474
|
+
SELECT pg_temp.klanten_try($klanten_stmt$GRANT EXECUTE ON FUNCTION public.klanten_toegang(text) TO service_role$klanten_stmt$, 'GRANT EXECUTE ON FUNCTION public.klanten_toegang(text) TO service_role');
|
|
475
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TABLE IF NOT EXISTS public.klanten_correctie_log (
|
|
476
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
477
|
+
functie text NOT NULL,
|
|
478
|
+
uitgevoerd boolean NOT NULL,
|
|
479
|
+
aanroeper text,
|
|
480
|
+
resultaat jsonb NOT NULL,
|
|
481
|
+
created_at timestamptz NOT NULL DEFAULT now()
|
|
482
|
+
)$klanten_stmt$, 'CREATE TABLE IF NOT EXISTS public.klanten_correctie_log ( id uuid PRIMARY KEY DEFAULT gen_random_uui');
|
|
483
|
+
SELECT pg_temp.klanten_try($klanten_stmt$GRANT SELECT ON public.klanten_correctie_log TO authenticated$klanten_stmt$, 'GRANT SELECT ON public.klanten_correctie_log TO authenticated');
|
|
484
|
+
SELECT pg_temp.klanten_try($klanten_stmt$GRANT ALL ON public.klanten_correctie_log TO service_role$klanten_stmt$, 'GRANT ALL ON public.klanten_correctie_log TO service_role');
|
|
485
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.klanten_correctie_log ENABLE ROW LEVEL SECURITY$klanten_stmt$, 'ALTER TABLE public.klanten_correctie_log ENABLE ROW LEVEL SECURITY');
|
|
486
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='klanten_correctie_log' AND policyname='Beheerders lezen correctielog') THEN CREATE POLICY "Beheerders lezen correctielog" ON public.klanten_correctie_log FOR SELECT TO authenticated USING (public.has_role(auth.uid(), 'admin'::public.app_role)); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''klant');
|
|
487
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.klanten_landnaam_kandidaten(p_waarde text)
|
|
488
|
+
RETURNS text[]
|
|
489
|
+
LANGUAGE sql
|
|
490
|
+
IMMUTABLE
|
|
491
|
+
SET search_path TO 'public'
|
|
492
|
+
AS $function$
|
|
493
|
+
WITH k AS (
|
|
494
|
+
SELECT btrim(regexp_replace(replace(lower(translate(btrim(COALESCE(p_waarde, '')),
|
|
495
|
+
'ÀÁÂÃÄÅàáâãäåÈÉÊËèéêëÌÍÎÏìíîïÒÓÔÕÖòóôõöÙÚÛÜùúûüÑñÇçÝýÿ',
|
|
496
|
+
'AAAAAAaaaaaaEEEEeeeeIIIIiiiiOOOOOoooooUUUUuuuuNnCcYyy')), '.', ''), '\s+', ' ', 'g')) AS sleutel
|
|
497
|
+
), m(naam, code) AS (VALUES
|
|
498
|
+
('nederland','NL'),
|
|
499
|
+
('belgie','BE'),
|
|
500
|
+
('duitsland','DE'),
|
|
501
|
+
('frankrijk','FR'),
|
|
502
|
+
('spanje','ES'),
|
|
503
|
+
('italie','IT'),
|
|
504
|
+
('verenigd koninkrijk','GB'),
|
|
505
|
+
('polen','PL'),
|
|
506
|
+
('denemarken','DK'),
|
|
507
|
+
('zweden','SE'),
|
|
508
|
+
('noorwegen','NO'),
|
|
509
|
+
('oostenrijk','AT'),
|
|
510
|
+
('zwitserland','CH'),
|
|
511
|
+
('portugal','PT'),
|
|
512
|
+
('ierland','IE'),
|
|
513
|
+
('luxemburg','LU'),
|
|
514
|
+
('tsjechie','CZ'),
|
|
515
|
+
('finland','FI'),
|
|
516
|
+
('verenigde staten','US'),
|
|
517
|
+
('canada','CA'),
|
|
518
|
+
('australie','AU'),
|
|
519
|
+
('nieuw-zeeland','NZ'),
|
|
520
|
+
('hongarije','HU'),
|
|
521
|
+
('roemenie','RO'),
|
|
522
|
+
('slowakije','SK'),
|
|
523
|
+
('slovenie','SI'),
|
|
524
|
+
('kroatie','HR'),
|
|
525
|
+
('bulgarije','BG'),
|
|
526
|
+
('estland','EE'),
|
|
527
|
+
('letland','LV'),
|
|
528
|
+
('litouwen','LT'),
|
|
529
|
+
('malta','MT'),
|
|
530
|
+
('cyprus','CY'),
|
|
531
|
+
('griekenland','GR'),
|
|
532
|
+
('ijsland','IS'),
|
|
533
|
+
('turkije','TR'),
|
|
534
|
+
('oekraine','UA'),
|
|
535
|
+
('servie','RS'),
|
|
536
|
+
('bosnie en herzegovina','BA'),
|
|
537
|
+
('montenegro','ME'),
|
|
538
|
+
('noord-macedonie','MK'),
|
|
539
|
+
('albanie','AL'),
|
|
540
|
+
('moldavie','MD'),
|
|
541
|
+
('belarus','BY'),
|
|
542
|
+
('rusland','RU'),
|
|
543
|
+
('georgie','GE'),
|
|
544
|
+
('armenie','AM'),
|
|
545
|
+
('azerbeidzjan','AZ'),
|
|
546
|
+
('israel','IL'),
|
|
547
|
+
('jordanie','JO'),
|
|
548
|
+
('libanon','LB'),
|
|
549
|
+
('marokko','MA'),
|
|
550
|
+
('tunesie','TN'),
|
|
551
|
+
('egypte','EG'),
|
|
552
|
+
('zuid-afrika','ZA'),
|
|
553
|
+
('china','CN'),
|
|
554
|
+
('india','IN'),
|
|
555
|
+
('japan','JP'),
|
|
556
|
+
('zuid-korea','KR'),
|
|
557
|
+
('singapore','SG'),
|
|
558
|
+
('thailand','TH'),
|
|
559
|
+
('maleisie','MY'),
|
|
560
|
+
('indonesie','ID'),
|
|
561
|
+
('filipijnen','PH'),
|
|
562
|
+
('vietnam','VN'),
|
|
563
|
+
('hongkong','HK'),
|
|
564
|
+
('taiwan','TW'),
|
|
565
|
+
('mexico','MX'),
|
|
566
|
+
('brazilie','BR'),
|
|
567
|
+
('argentinie','AR'),
|
|
568
|
+
('chili','CL'),
|
|
569
|
+
('colombia','CO'),
|
|
570
|
+
('peru','PE'),
|
|
571
|
+
('uruguay','UY'),
|
|
572
|
+
('venezuela','VE'),
|
|
573
|
+
('ecuador','EC'),
|
|
574
|
+
('bolivia','BO'),
|
|
575
|
+
('paraguay','PY'),
|
|
576
|
+
('costa rica','CR'),
|
|
577
|
+
('panama','PA'),
|
|
578
|
+
('guatemala','GT'),
|
|
579
|
+
('honduras','HN'),
|
|
580
|
+
('nicaragua','NI'),
|
|
581
|
+
('el salvador','SV'),
|
|
582
|
+
('dominicaanse republiek','DO'),
|
|
583
|
+
('jamaica','JM'),
|
|
584
|
+
('trinidad en tobago','TT'),
|
|
585
|
+
('barbados','BB'),
|
|
586
|
+
('bahama''s','BS'),
|
|
587
|
+
('caymaneilanden','KY'),
|
|
588
|
+
('nederlandse antillen','AN'),
|
|
589
|
+
('aruba','AW'),
|
|
590
|
+
('curacao','CW'),
|
|
591
|
+
('sint maarten','SX'),
|
|
592
|
+
('bonaire, sint eustatius en saba','BQ'),
|
|
593
|
+
('guadeloupe','GP'),
|
|
594
|
+
('martinique','MQ'),
|
|
595
|
+
('reunion','RE'),
|
|
596
|
+
('frans-guyana','GF'),
|
|
597
|
+
('frans-polynesie','PF'),
|
|
598
|
+
('nieuw-caledonie','NC'),
|
|
599
|
+
('mayotte','YT'),
|
|
600
|
+
('saint-pierre en miquelon','PM'),
|
|
601
|
+
('wallis en futuna','WF'),
|
|
602
|
+
('franse zuidelijke en antarctische gebieden','TF'),
|
|
603
|
+
('andorra','AD'),
|
|
604
|
+
('monaco','MC'),
|
|
605
|
+
('liechtenstein','LI'),
|
|
606
|
+
('san marino','SM'),
|
|
607
|
+
('vaticaanstad','VA'),
|
|
608
|
+
('gibraltar','GI'),
|
|
609
|
+
('faeroer','FO'),
|
|
610
|
+
('aland','AX'),
|
|
611
|
+
('spitsbergen en jan mayen','SJ'),
|
|
612
|
+
('isle of man','IM'),
|
|
613
|
+
('guernsey','GG'),
|
|
614
|
+
('jersey','JE'),
|
|
615
|
+
('kenia','KE'),
|
|
616
|
+
('saoedi-arabie','SA'),
|
|
617
|
+
('verenigde arabische emiraten','AE'),
|
|
618
|
+
('qatar','QA'),
|
|
619
|
+
('koeweit','KW'),
|
|
620
|
+
('bahrein','BH'),
|
|
621
|
+
('oman','OM'),
|
|
622
|
+
('nigeria','NG'),
|
|
623
|
+
('ghana','GH'),
|
|
624
|
+
('ethiopie','ET'),
|
|
625
|
+
('oeganda','UG'),
|
|
626
|
+
('tanzania','TZ'),
|
|
627
|
+
('algerije','DZ'),
|
|
628
|
+
('netherlands','NL'),
|
|
629
|
+
('the netherlands','NL'),
|
|
630
|
+
('holland','NL'),
|
|
631
|
+
('belgium','BE'),
|
|
632
|
+
('belgique','BE'),
|
|
633
|
+
('belgien','BE'),
|
|
634
|
+
('germany','DE'),
|
|
635
|
+
('deutschland','DE'),
|
|
636
|
+
('france','FR'),
|
|
637
|
+
('united kingdom','GB'),
|
|
638
|
+
('great britain','GB'),
|
|
639
|
+
('england','GB'),
|
|
640
|
+
('uk','GB'),
|
|
641
|
+
('spain','ES'),
|
|
642
|
+
('espana','ES'),
|
|
643
|
+
('italy','IT'),
|
|
644
|
+
('italia','IT'),
|
|
645
|
+
('poland','PL'),
|
|
646
|
+
('denmark','DK'),
|
|
647
|
+
('sweden','SE'),
|
|
648
|
+
('norway','NO'),
|
|
649
|
+
('austria','AT'),
|
|
650
|
+
('osterreich','AT'),
|
|
651
|
+
('switzerland','CH'),
|
|
652
|
+
('schweiz','CH'),
|
|
653
|
+
('luxembourg','LU'),
|
|
654
|
+
('ireland','IE'),
|
|
655
|
+
('czech republic','CZ'),
|
|
656
|
+
('czechia','CZ'),
|
|
657
|
+
('united states','US'),
|
|
658
|
+
('usa','US'),
|
|
659
|
+
('verenigde staten van amerika','US'),
|
|
660
|
+
('kenya','KE'),
|
|
661
|
+
('saudi arabia','SA'),
|
|
662
|
+
('nl','NL'),
|
|
663
|
+
('be','BE'),
|
|
664
|
+
('de','DE'),
|
|
665
|
+
('fr','FR'),
|
|
666
|
+
('es','ES'),
|
|
667
|
+
('it','IT'),
|
|
668
|
+
('gb','GB'),
|
|
669
|
+
('uk','GB'),
|
|
670
|
+
('pl','PL'),
|
|
671
|
+
('dk','DK'),
|
|
672
|
+
('se','SE'),
|
|
673
|
+
('no','NO'),
|
|
674
|
+
('at','AT'),
|
|
675
|
+
('ch','CH'),
|
|
676
|
+
('pt','PT'),
|
|
677
|
+
('ie','IE'),
|
|
678
|
+
('lu','LU'),
|
|
679
|
+
('cz','CZ'),
|
|
680
|
+
('fi','FI'),
|
|
681
|
+
('us','US'),
|
|
682
|
+
('ca','CA'),
|
|
683
|
+
('au','AU'),
|
|
684
|
+
('nz','NZ'),
|
|
685
|
+
('hu','HU'),
|
|
686
|
+
('ro','RO'),
|
|
687
|
+
('sk','SK'),
|
|
688
|
+
('si','SI'),
|
|
689
|
+
('hr','HR'),
|
|
690
|
+
('bg','BG'),
|
|
691
|
+
('ee','EE'),
|
|
692
|
+
('lv','LV'),
|
|
693
|
+
('lt','LT'),
|
|
694
|
+
('mt','MT'),
|
|
695
|
+
('cy','CY'),
|
|
696
|
+
('gr','GR'),
|
|
697
|
+
('is','IS'),
|
|
698
|
+
('tr','TR'),
|
|
699
|
+
('ua','UA'),
|
|
700
|
+
('rs','RS'),
|
|
701
|
+
('ba','BA'),
|
|
702
|
+
('me','ME'),
|
|
703
|
+
('mk','MK'),
|
|
704
|
+
('al','AL'),
|
|
705
|
+
('md','MD'),
|
|
706
|
+
('by','BY'),
|
|
707
|
+
('ru','RU'),
|
|
708
|
+
('ge','GE'),
|
|
709
|
+
('am','AM'),
|
|
710
|
+
('az','AZ'),
|
|
711
|
+
('il','IL'),
|
|
712
|
+
('jo','JO'),
|
|
713
|
+
('lb','LB'),
|
|
714
|
+
('ma','MA'),
|
|
715
|
+
('tn','TN'),
|
|
716
|
+
('eg','EG'),
|
|
717
|
+
('za','ZA'),
|
|
718
|
+
('cn','CN'),
|
|
719
|
+
('in','IN'),
|
|
720
|
+
('jp','JP'),
|
|
721
|
+
('kr','KR'),
|
|
722
|
+
('sg','SG'),
|
|
723
|
+
('th','TH'),
|
|
724
|
+
('my','MY'),
|
|
725
|
+
('id','ID'),
|
|
726
|
+
('ph','PH'),
|
|
727
|
+
('vn','VN'),
|
|
728
|
+
('hk','HK'),
|
|
729
|
+
('tw','TW'),
|
|
730
|
+
('mx','MX'),
|
|
731
|
+
('br','BR'),
|
|
732
|
+
('ar','AR'),
|
|
733
|
+
('cl','CL'),
|
|
734
|
+
('co','CO'),
|
|
735
|
+
('pe','PE'),
|
|
736
|
+
('uy','UY'),
|
|
737
|
+
('ve','VE'),
|
|
738
|
+
('ec','EC'),
|
|
739
|
+
('bo','BO'),
|
|
740
|
+
('py','PY'),
|
|
741
|
+
('cr','CR'),
|
|
742
|
+
('pa','PA'),
|
|
743
|
+
('gt','GT'),
|
|
744
|
+
('hn','HN'),
|
|
745
|
+
('ni','NI'),
|
|
746
|
+
('sv','SV'),
|
|
747
|
+
('do','DO'),
|
|
748
|
+
('jm','JM'),
|
|
749
|
+
('tt','TT'),
|
|
750
|
+
('bb','BB'),
|
|
751
|
+
('bs','BS'),
|
|
752
|
+
('ky','KY'),
|
|
753
|
+
('an','AN'),
|
|
754
|
+
('aw','AW'),
|
|
755
|
+
('cw','CW'),
|
|
756
|
+
('sx','SX'),
|
|
757
|
+
('bq','BQ'),
|
|
758
|
+
('gp','GP'),
|
|
759
|
+
('mq','MQ'),
|
|
760
|
+
('re','RE'),
|
|
761
|
+
('gf','GF'),
|
|
762
|
+
('pf','PF'),
|
|
763
|
+
('nc','NC'),
|
|
764
|
+
('yt','YT'),
|
|
765
|
+
('pm','PM'),
|
|
766
|
+
('wf','WF'),
|
|
767
|
+
('tf','TF'),
|
|
768
|
+
('ad','AD'),
|
|
769
|
+
('mc','MC'),
|
|
770
|
+
('li','LI'),
|
|
771
|
+
('sm','SM'),
|
|
772
|
+
('va','VA'),
|
|
773
|
+
('gi','GI'),
|
|
774
|
+
('fo','FO'),
|
|
775
|
+
('ax','AX'),
|
|
776
|
+
('sj','SJ'),
|
|
777
|
+
('im','IM'),
|
|
778
|
+
('gg','GG'),
|
|
779
|
+
('je','JE'),
|
|
780
|
+
('ke','KE'),
|
|
781
|
+
('sa','SA'),
|
|
782
|
+
('ae','AE'),
|
|
783
|
+
('qa','QA'),
|
|
784
|
+
('kw','KW'),
|
|
785
|
+
('bh','BH'),
|
|
786
|
+
('om','OM'),
|
|
787
|
+
('ng','NG'),
|
|
788
|
+
('gh','GH'),
|
|
789
|
+
('et','ET'),
|
|
790
|
+
('ug','UG'),
|
|
791
|
+
('tz','TZ'),
|
|
792
|
+
('dz','DZ')
|
|
460
793
|
)
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
794
|
+
SELECT COALESCE(array_agg(DISTINCT m.code ORDER BY m.code), '{}'::text[]) FROM k JOIN m ON m.naam = k.sleutel;
|
|
795
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.klanten_landnaam_kandidaten(p_waarde text) RETURNS text[] LANGUAGE');
|
|
796
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.klanten_correctie_landcodes(p_uitvoeren boolean DEFAULT false)
|
|
797
|
+
RETURNS jsonb
|
|
798
|
+
LANGUAGE plpgsql
|
|
799
|
+
SECURITY DEFINER
|
|
800
|
+
SET search_path TO 'public'
|
|
801
|
+
AS $function$
|
|
802
|
+
DECLARE
|
|
803
|
+
_r record; _k text[]; _sk text[]; _n int;
|
|
804
|
+
_rijen jsonb := '[]'::jsonb; _niet jsonb := '[]'::jsonb;
|
|
805
|
+
_tel jsonb := jsonb_build_object('customers.country', 0, 'customers.bank_country', 0, 'customer_delivery_locations.country', 0);
|
|
806
|
+
_res jsonb;
|
|
807
|
+
BEGIN
|
|
808
|
+
PERFORM public.klanten_toegang('server');
|
|
809
|
+
FOR _r IN
|
|
810
|
+
SELECT 'customers'::text AS t, 'country'::text AS kol, id, country AS v FROM public.customers
|
|
811
|
+
WHERE country IS NOT NULL AND btrim(country) <> '' AND country !~ '^[A-Z]{2}$'
|
|
812
|
+
UNION ALL
|
|
813
|
+
SELECT 'customers', 'bank_country', id, bank_country FROM public.customers
|
|
814
|
+
WHERE bank_country IS NOT NULL AND btrim(bank_country) <> '' AND bank_country !~ '^[A-Z]{2}$'
|
|
815
|
+
UNION ALL
|
|
816
|
+
SELECT 'customer_delivery_locations', 'country', id, country FROM public.customer_delivery_locations
|
|
817
|
+
WHERE country IS NOT NULL AND btrim(country) <> '' AND country !~ '^[A-Z]{2}$'
|
|
818
|
+
ORDER BY 1, 2, 3
|
|
819
|
+
LOOP
|
|
820
|
+
_k := public.klanten_landnaam_kandidaten(_r.v);
|
|
821
|
+
IF COALESCE(array_length(_k, 1), 0) <> 1 THEN
|
|
822
|
+
_niet := _niet || jsonb_build_object('tabel', _r.t, 'kolom', _r.kol, 'id', _r.id, 'oud', _r.v,
|
|
823
|
+
'reden', CASE WHEN COALESCE(array_length(_k, 1), 0) = 0 THEN 'onbekend land'
|
|
824
|
+
ELSE 'niet eenduidig: ' || array_to_string(_k, ', ') END);
|
|
825
|
+
CONTINUE;
|
|
826
|
+
END IF;
|
|
827
|
+
_n := 1;
|
|
828
|
+
IF p_uitvoeren THEN
|
|
829
|
+
IF _r.t = 'customers' THEN
|
|
830
|
+
PERFORM set_config('app.skip_twinfield_push', 'on', true);
|
|
831
|
+
IF _r.kol = 'country' THEN
|
|
832
|
+
UPDATE public.customers c SET country = _k[1],
|
|
833
|
+
twinfield_base_snapshot = CASE
|
|
834
|
+
WHEN c.twinfield_base_snapshot ? 'country' AND (c.twinfield_base_snapshot->>'country') !~ '^[A-Z]{2}$'
|
|
835
|
+
AND public.klanten_landnaam_kandidaten(c.twinfield_base_snapshot->>'country') = ARRAY[_k[1]]
|
|
836
|
+
THEN jsonb_set(c.twinfield_base_snapshot, '{country}', to_jsonb(_k[1])) ELSE c.twinfield_base_snapshot END
|
|
837
|
+
WHERE c.id = _r.id AND c.country = _r.v;
|
|
838
|
+
ELSE
|
|
839
|
+
UPDATE public.customers c SET bank_country = _k[1],
|
|
840
|
+
twinfield_base_snapshot = CASE
|
|
841
|
+
WHEN c.twinfield_base_snapshot ? 'bank_country' AND (c.twinfield_base_snapshot->>'bank_country') !~ '^[A-Z]{2}$'
|
|
842
|
+
AND public.klanten_landnaam_kandidaten(c.twinfield_base_snapshot->>'bank_country') = ARRAY[_k[1]]
|
|
843
|
+
THEN jsonb_set(c.twinfield_base_snapshot, '{bank_country}', to_jsonb(_k[1])) ELSE c.twinfield_base_snapshot END
|
|
844
|
+
WHERE c.id = _r.id AND c.bank_country = _r.v;
|
|
845
|
+
END IF;
|
|
846
|
+
GET DIAGNOSTICS _n = ROW_COUNT;
|
|
847
|
+
PERFORM set_config('app.skip_twinfield_push', '', true);
|
|
848
|
+
ELSE
|
|
849
|
+
UPDATE public.customer_delivery_locations l SET country = _k[1] WHERE l.id = _r.id AND l.country = _r.v;
|
|
850
|
+
GET DIAGNOSTICS _n = ROW_COUNT;
|
|
851
|
+
END IF;
|
|
852
|
+
END IF;
|
|
853
|
+
IF _n > 0 THEN
|
|
854
|
+
_rijen := _rijen || jsonb_build_object('tabel', _r.t, 'kolom', _r.kol, 'id', _r.id, 'oud', _r.v, 'nieuw', _k[1]);
|
|
855
|
+
_tel := jsonb_set(_tel, ARRAY[_r.t || '.' || _r.kol], to_jsonb((_tel->>(_r.t || '.' || _r.kol))::int + 1));
|
|
856
|
+
END IF;
|
|
857
|
+
END LOOP;
|
|
858
|
+
_res := jsonb_build_object('uitgevoerd', p_uitvoeren, 'aantallen', _tel, 'rijen', _rijen,
|
|
859
|
+
'niet_omgezet', _niet, 'tijdstip', now());
|
|
860
|
+
INSERT INTO public.klanten_correctie_log(functie, uitgevoerd, aanroeper, resultaat)
|
|
861
|
+
VALUES ('klanten_correctie_landcodes', p_uitvoeren,
|
|
862
|
+
COALESCE(NULLIF(current_setting('request.jwt.claims', true), '')::jsonb ->> 'role', session_user::text), _res);
|
|
863
|
+
RETURN _res;
|
|
864
|
+
END
|
|
865
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.klanten_correctie_landcodes(p_uitvoeren boolean DEFAULT false) RET');
|
|
866
|
+
SELECT pg_temp.klanten_try($klanten_stmt$REVOKE ALL ON FUNCTION public.klanten_correctie_landcodes(boolean) FROM PUBLIC, anon, authenticated$klanten_stmt$, 'REVOKE ALL ON FUNCTION public.klanten_correctie_landcodes(boolean) FROM PUBLIC, anon, authenticated');
|
|
867
|
+
SELECT pg_temp.klanten_try($klanten_stmt$GRANT EXECUTE ON FUNCTION public.klanten_correctie_landcodes(boolean) TO service_role$klanten_stmt$, 'GRANT EXECUTE ON FUNCTION public.klanten_correctie_landcodes(boolean) TO service_role');
|
|
464
868
|
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.customer_soft_key(_email text, _postal text, _house text, _name text)
|
|
465
869
|
RETURNS text
|
|
466
870
|
LANGUAGE sql
|
|
@@ -552,10 +956,14 @@ BEGIN
|
|
|
552
956
|
END$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.enqueue_twinfield_push() RETURNS trigger LANGUAGE plpgsql SECURITY');
|
|
553
957
|
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.floriday_effective_price(_buyer_id text, _trade_item_id text, _on_date date DEFAULT CURRENT_DATE, _quantity numeric DEFAULT 1)
|
|
554
958
|
RETURNS TABLE(source text, net_price numeric, base_price numeric, discount_type text, discount_value numeric, currency text, source_id text)
|
|
555
|
-
LANGUAGE
|
|
959
|
+
LANGUAGE plpgsql
|
|
556
960
|
STABLE SECURITY DEFINER
|
|
557
961
|
SET search_path TO 'public'
|
|
558
962
|
AS $function$
|
|
963
|
+
#variable_conflict use_column
|
|
964
|
+
BEGIN
|
|
965
|
+
PERFORM public.klanten_toegang('ingelogd');
|
|
966
|
+
RETURN QUERY
|
|
559
967
|
SELECT d.source, d.net_price, d.base_price, d.discount_type, d.discount_value, d.currency, d.source_id
|
|
560
968
|
FROM public.floriday_customer_discounts d
|
|
561
969
|
WHERE d.buyer_organization_id = _buyer_id
|
|
@@ -570,15 +978,19 @@ AS $function$
|
|
|
570
978
|
ELSE 4
|
|
571
979
|
END, d.net_price NULLS LAST
|
|
572
980
|
LIMIT 1;
|
|
981
|
+
END
|
|
573
982
|
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.floriday_effective_price(_buyer_id text, _trade_item_id text, _on_');
|
|
574
983
|
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.has_twinfield_link()
|
|
575
984
|
RETURNS boolean
|
|
576
|
-
LANGUAGE
|
|
985
|
+
LANGUAGE plpgsql
|
|
577
986
|
STABLE SECURITY DEFINER
|
|
578
987
|
SET search_path TO 'public'
|
|
579
988
|
AS $function$
|
|
580
|
-
|
|
581
|
-
|
|
989
|
+
BEGIN
|
|
990
|
+
PERFORM public.klanten_toegang('ingelogd');
|
|
991
|
+
RETURN EXISTS (SELECT 1 FROM public.twinfield_connections WHERE is_active = true);
|
|
992
|
+
END
|
|
993
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.has_twinfield_link() RETURNS boolean LANGUAGE plpgsql STABLE SECUR');
|
|
582
994
|
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.import_floriday_delivery_locations(_org_id text)
|
|
583
995
|
RETURNS integer
|
|
584
996
|
LANGUAGE plpgsql
|
|
@@ -587,6 +999,7 @@ SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.impor
|
|
|
587
999
|
AS $function$
|
|
588
1000
|
DECLARE _cid uuid; _n integer := 0; _l record; _a jsonb; _lid text;
|
|
589
1001
|
BEGIN
|
|
1002
|
+
PERFORM public.klanten_toegang('ingelogd');
|
|
590
1003
|
SELECT id INTO _cid FROM customers WHERE floriday_organization_id = _org_id;
|
|
591
1004
|
IF _cid IS NULL THEN RETURN 0; END IF;
|
|
592
1005
|
FOR _l IN SELECT * FROM floriday_delivery_locations_cache
|
|
@@ -615,8 +1028,9 @@ SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.klant
|
|
|
615
1028
|
STABLE SECURITY DEFINER
|
|
616
1029
|
SET search_path TO 'public'
|
|
617
1030
|
AS $function$
|
|
618
|
-
DECLARE _missing text[] := '{}'; _o text; _res jsonb := '{}'::jsonb;
|
|
1031
|
+
DECLARE _missing text[] := '{}'; _o text; _res jsonb := '{}'::jsonb; _f jsonb := '[]'::jsonb; _t jsonb := '[]'::jsonb; _p jsonb := '[]'::jsonb; _r record;
|
|
619
1032
|
BEGIN
|
|
1033
|
+
PERFORM public.klanten_toegang('ingelogd');
|
|
620
1034
|
FOREACH _o IN ARRAY ARRAY['customers','customer_delivery_locations','customer_match_suggestions','floriday_customers_cache',
|
|
621
1035
|
'floriday_connections','floriday_connections_cache','orders','app_settings','external_customers_grouped'] LOOP
|
|
622
1036
|
IF to_regclass('public.'||_o) IS NULL THEN _missing := _missing || _o; END IF;
|
|
@@ -624,9 +1038,36 @@ BEGIN
|
|
|
624
1038
|
FOREACH _o IN ARRAY ARRAY['promote_floriday_customer','floriday_customer_candidates','promote_floriday_order_customers',
|
|
625
1039
|
'import_floriday_delivery_locations','refresh_external_customers_grouped','enqueue_twinfield_push'] LOOP
|
|
626
1040
|
IF NOT EXISTS (SELECT 1 FROM pg_proc WHERE proname=_o AND pronamespace='public'::regnamespace) THEN _missing := _missing || (_o||'()'); END IF;
|
|
1041
|
+
END LOOP;
|
|
1042
|
+
FOR _r IN SELECT v.naam, v.niveau, p.oid AS oid, p.prosrc FROM (VALUES ('import_floriday_delivery_locations','ingelogd'),('next_twinfield_code','ingelogd'),('refresh_floriday_delivery_locations','ingelogd'),('reorder_customer_price_groups','ingelogd'),('retry_twinfield_push','ingelogd'),('set_primary_delivery_location','ingelogd'),('sync_floriday_prices_into_price_groups','ingelogd'),('klanten_auto_promote_status','ingelogd'),('klanten_refresh_grouped_if_stale','ingelogd'),('floriday_effective_price','ingelogd'),('has_twinfield_link','ingelogd'),('local_effective_price','ingelogd'),('refresh_external_customers_grouped','ingelogd'),('floriday_customer_candidates','ingelogd'),('floriday_customer_promotion_preview','ingelogd'),('klanten_install_check','ingelogd'),('schedule_floriday_network_sync','beheerder'),('klanten_set_auto_promote','beheerder'),('klanten_promote_round','beheerder'),('promote_floriday_customer','beheerder'),('run_twinfield_queue_tick','server'),('twinfield_sync_apply','server'),('twinfield_sync_insert','server'),('twinfield_sync_mark_missing','server'),('promote_floriday_order_customers','server'),('klanten_correctie_landcodes','server'),('customer_soft_key','open'),('server_now','open'),('klanten_is_server','open'),('klanten_toegang','open'),('klanten_landnaam_kandidaten','open'),('enqueue_twinfield_push','trigger'),('log_customer_changes','trigger'),('tg_customer_price_groups_touch','trigger'),('trg_floriday_delivery_location_import','trigger'),('trg_refresh_external_customers_grouped','trigger'),('validate_twinfield_required_fields','trigger')) v(naam, niveau)
|
|
1043
|
+
LEFT JOIN pg_proc p ON p.proname = v.naam AND p.pronamespace = 'public'::regnamespace ORDER BY v.niveau, v.naam LOOP
|
|
1044
|
+
_f := _f || jsonb_build_object('functie', _r.naam, 'niveau',
|
|
1045
|
+
CASE _r.niveau WHEN 'open' THEN 'bewust open (hulpfunctie zonder gegevens)'
|
|
1046
|
+
WHEN 'trigger' THEN 'trigger (niet los aan te roepen)'
|
|
1047
|
+
WHEN 'ingelogd' THEN 'ingelogd of server'
|
|
1048
|
+
WHEN 'beheerder' THEN 'beheerder of server'
|
|
1049
|
+
ELSE 'alleen server' END,
|
|
1050
|
+
'aanwezig', _r.oid IS NOT NULL,
|
|
1051
|
+
'interne_controle', CASE WHEN _r.niveau IN ('open','trigger') THEN NULL
|
|
1052
|
+
ELSE COALESCE(_r.prosrc ILIKE '%klanten_toegang(%', false) END,
|
|
1053
|
+
'uitvoerrecht_anon', CASE WHEN _r.oid IS NULL THEN NULL ELSE has_function_privilege('anon', _r.oid, 'execute') END,
|
|
1054
|
+
'uitvoerrecht_authenticated', CASE WHEN _r.oid IS NULL THEN NULL ELSE has_function_privilege('authenticated', _r.oid, 'execute') END);
|
|
1055
|
+
END LOOP;
|
|
1056
|
+
FOREACH _o IN ARRAY ARRAY['customers_enqueue_twinfield_push|customers','customers_validate_twinfield_required|customers','trg_cms_updated_at|customer_match_suggestions','trg_customer_notes_updated|customer_notes','trg_customer_price_groups_touch|customer_price_groups','trg_customers_refresh_external_grouped|customers','trg_floriday_cache_refresh_ecg|floriday_customers_cache','trg_local_agreements_updated|local_customer_agreements','trg_local_price_groups_updated|local_customer_price_groups','trg_local_sales_strategies_updated|local_customer_sales_strategies','trg_log_customer_changes|customers','trg_twinfield_cache_refresh_ecg|twinfield_customers_cache','update_customer_assortment_items_updated_at|customer_assortment_items','update_customer_product_stickers_updated_at|customer_product_stickers','update_customer_sticker_settings_updated_at|customer_sticker_settings','update_customers_updated_at|customers','update_external_customer_providers_updated_at|external_customer_providers'] LOOP
|
|
1057
|
+
_t := _t || jsonb_build_object('trigger', split_part(_o,'|',1), 'tabel', split_part(_o,'|',2),
|
|
1058
|
+
'aanwezig', EXISTS (SELECT 1 FROM pg_trigger tg JOIN pg_class c ON c.oid = tg.tgrelid
|
|
1059
|
+
WHERE tg.tgname = split_part(_o,'|',1) AND c.relname = split_part(_o,'|',2) AND c.relnamespace = 'public'::regnamespace));
|
|
1060
|
+
END LOOP;
|
|
1061
|
+
FOREACH _o IN ARRAY ARRAY['Authenticated can delete customer_contacts|customer_contacts','Authenticated can delete customer_delivery_locations|customer_delivery_locations','Authenticated can delete customer_selected_assortment|customer_selected_assortment','Authenticated can delete customer_trade_settings|customer_trade_settings','Authenticated can insert customer_contacts|customer_contacts','Authenticated can insert customer_delivery_locations|customer_delivery_locations','Authenticated can insert customer_selected_assortment|customer_selected_assortment','Authenticated can insert customer_trade_settings|customer_trade_settings','Authenticated can manage customer assortment|customer_assortment_items','Authenticated can read customer_contacts|customer_contacts','Authenticated can read customer_delivery_locations|customer_delivery_locations','Authenticated can read customer_selected_assortment|customer_selected_assortment','Authenticated can read customer_trade_settings|customer_trade_settings','Authenticated can update customer_contacts|customer_contacts','Authenticated can update customer_delivery_locations|customer_delivery_locations','Authenticated can update customer_selected_assortment|customer_selected_assortment','Authenticated can update customer_trade_settings|customer_trade_settings','Authenticated users can delete customers|customers','Authenticated users can insert customers|customers','Authenticated users can read customers|customers','Authenticated users can update customers|customers','External customer providers are readable by authenticated users|external_customer_providers','Ingelogd beoordelen voorstellen|customer_match_suggestions','Ingelogd lezen voorstellen|customer_match_suggestions','Ingelogde gebruikers beheren klantstickers|customer_product_stickers','Ingelogde gebruikers beheren stickerinstellingen|customer_sticker_settings','auth can read cls|customer_logistics_strategy','auth can write cls|customer_logistics_strategy','auth manage customer notes|customer_notes','auth manage local agreements|local_customer_agreements','auth manage local price groups|local_customer_price_groups','auth manage local sales strategies|local_customer_sales_strategies','own pg members - delete|customer_price_group_members','own pg members - insert|customer_price_group_members','own pg members - select|customer_price_group_members','own pg members - update|customer_price_group_members','own price groups - delete|customer_price_groups','own price groups - insert|customer_price_groups','own price groups - select|customer_price_groups','own price groups - update|customer_price_groups','service role only|twinfield_push_log','Beheerders lezen correctielog|klanten_correctie_log'] LOOP
|
|
1062
|
+
_p := _p || jsonb_build_object('policy', split_part(_o,'|',1), 'tabel', split_part(_o,'|',2),
|
|
1063
|
+
'aanwezig', EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND policyname = split_part(_o,'|',1) AND tablename = split_part(_o,'|',2)));
|
|
627
1064
|
END LOOP;
|
|
628
1065
|
_res := jsonb_build_object('ontbreekt', to_jsonb(_missing),
|
|
629
|
-
'cron_promote', EXISTS (SELECT 1 FROM pg_extension WHERE extname='pg_cron')
|
|
1066
|
+
'cron_promote', EXISTS (SELECT 1 FROM pg_extension WHERE extname='pg_cron'),
|
|
1067
|
+
'functies', _f, 'triggers', _t, 'policies', _p,
|
|
1068
|
+
'functies_zonder_controle', (SELECT COALESCE(jsonb_agg(x->>'functie'), '[]'::jsonb) FROM jsonb_array_elements(_f) x WHERE (x->>'interne_controle') = 'false'),
|
|
1069
|
+
'triggers_ontbreken', (SELECT COALESCE(jsonb_agg(x->>'trigger'), '[]'::jsonb) FROM jsonb_array_elements(_t) x WHERE NOT (x->>'aanwezig')::boolean),
|
|
1070
|
+
'policies_ontbreken', (SELECT COALESCE(jsonb_agg(x->>'policy'), '[]'::jsonb) FROM jsonb_array_elements(_p) x WHERE NOT (x->>'aanwezig')::boolean));
|
|
630
1071
|
IF array_length(_missing,1) IS NULL THEN
|
|
631
1072
|
_res := _res || jsonb_build_object(
|
|
632
1073
|
'klanten', (SELECT count(*) FROM customers),
|
|
@@ -642,10 +1083,14 @@ END;
|
|
|
642
1083
|
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.klanten_install_check() RETURNS jsonb LANGUAGE plpgsql STABLE SECU');
|
|
643
1084
|
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.local_effective_price(_customer_id uuid, _product_id uuid, _on_date date DEFAULT CURRENT_DATE, _quantity numeric DEFAULT 1)
|
|
644
1085
|
RETURNS TABLE(source text, source_id uuid, net_price numeric, discount_type text, discount_value numeric, currency text)
|
|
645
|
-
LANGUAGE
|
|
1086
|
+
LANGUAGE plpgsql
|
|
646
1087
|
STABLE SECURITY DEFINER
|
|
647
1088
|
SET search_path TO 'public'
|
|
648
1089
|
AS $function$
|
|
1090
|
+
#variable_conflict use_column
|
|
1091
|
+
BEGIN
|
|
1092
|
+
PERFORM public.klanten_toegang('ingelogd');
|
|
1093
|
+
RETURN QUERY
|
|
649
1094
|
WITH candidates AS (
|
|
650
1095
|
SELECT 1 AS prio, d.source, d.source_id, d.net_price, d.discount_type, d.discount_value, d.currency, d.min_quantity
|
|
651
1096
|
FROM public.local_customer_discounts d
|
|
@@ -675,6 +1120,7 @@ AS $function$
|
|
|
675
1120
|
FROM candidates c
|
|
676
1121
|
ORDER BY c.prio ASC, c.min_quantity DESC
|
|
677
1122
|
LIMIT 1;
|
|
1123
|
+
END
|
|
678
1124
|
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.local_effective_price(_customer_id uuid, _product_id uuid, _on_dat');
|
|
679
1125
|
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.log_customer_changes()
|
|
680
1126
|
RETURNS trigger
|
|
@@ -725,6 +1171,7 @@ AS $function$
|
|
|
725
1171
|
DECLARE
|
|
726
1172
|
n bigint;
|
|
727
1173
|
BEGIN
|
|
1174
|
+
PERFORM public.klanten_toegang('ingelogd');
|
|
728
1175
|
n := nextval('public.twinfield_customer_code_seq');
|
|
729
1176
|
RETURN 'KL' || lpad(n::text, 5, '0');
|
|
730
1177
|
END$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.next_twinfield_code() RETURNS text LANGUAGE plpgsql SECURITY DEFIN');
|
|
@@ -736,6 +1183,7 @@ SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.promo
|
|
|
736
1183
|
AS $function$
|
|
737
1184
|
DECLARE _id uuid; _c record; _addr jsonb; _gln text; _hits int;
|
|
738
1185
|
BEGIN
|
|
1186
|
+
PERFORM public.klanten_toegang('beheerder');
|
|
739
1187
|
IF _org_id IS NULL OR btrim(_org_id) = '' THEN
|
|
740
1188
|
RAISE EXCEPTION 'Geen Floriday-organisatienummer opgegeven';
|
|
741
1189
|
END IF;
|
|
@@ -827,12 +1275,15 @@ END;
|
|
|
827
1275
|
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.promote_floriday_customer(_org_id text) RETURNS uuid LANGUAGE plpg');
|
|
828
1276
|
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.refresh_external_customers_grouped()
|
|
829
1277
|
RETURNS void
|
|
830
|
-
LANGUAGE
|
|
1278
|
+
LANGUAGE plpgsql
|
|
831
1279
|
SECURITY DEFINER
|
|
832
1280
|
SET search_path TO 'public'
|
|
833
1281
|
AS $function$
|
|
1282
|
+
BEGIN
|
|
1283
|
+
PERFORM public.klanten_toegang('ingelogd');
|
|
834
1284
|
REFRESH MATERIALIZED VIEW CONCURRENTLY public.external_customers_grouped;
|
|
835
|
-
|
|
1285
|
+
END
|
|
1286
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.refresh_external_customers_grouped() RETURNS void LANGUAGE plpgsql');
|
|
836
1287
|
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.refresh_floriday_delivery_locations()
|
|
837
1288
|
RETURNS integer
|
|
838
1289
|
LANGUAGE plpgsql
|
|
@@ -841,6 +1292,7 @@ SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.refre
|
|
|
841
1292
|
AS $function$
|
|
842
1293
|
DECLARE _o text; _t integer := 0;
|
|
843
1294
|
BEGIN
|
|
1295
|
+
PERFORM public.klanten_toegang('ingelogd');
|
|
844
1296
|
FOR _o IN SELECT floriday_organization_id FROM customers WHERE floriday_organization_id IS NOT NULL LOOP
|
|
845
1297
|
BEGIN _t := _t + public.import_floriday_delivery_locations(_o);
|
|
846
1298
|
EXCEPTION WHEN OTHERS THEN RAISE WARNING 'locaties % mislukt: %', _o, SQLERRM; END;
|
|
@@ -858,6 +1310,7 @@ DECLARE
|
|
|
858
1310
|
_id UUID;
|
|
859
1311
|
_idx INT := 0;
|
|
860
1312
|
BEGIN
|
|
1313
|
+
PERFORM public.klanten_toegang('ingelogd');
|
|
861
1314
|
IF _uid IS NULL THEN
|
|
862
1315
|
RAISE EXCEPTION 'Not authenticated';
|
|
863
1316
|
END IF;
|
|
@@ -878,6 +1331,7 @@ AS $function$
|
|
|
878
1331
|
DECLARE
|
|
879
1332
|
n int;
|
|
880
1333
|
BEGIN
|
|
1334
|
+
PERFORM public.klanten_toegang('ingelogd');
|
|
881
1335
|
UPDATE public.twinfield_push_queue
|
|
882
1336
|
SET status = 'pending',
|
|
883
1337
|
attempts = 0,
|
|
@@ -899,6 +1353,7 @@ DECLARE
|
|
|
899
1353
|
v_url text;
|
|
900
1354
|
v_apikey text;
|
|
901
1355
|
BEGIN
|
|
1356
|
+
PERFORM public.klanten_toegang('server');
|
|
902
1357
|
SELECT value INTO v_url FROM public.app_settings WHERE key = 'twinfield_queue_url';
|
|
903
1358
|
SELECT value INTO v_apikey FROM public.app_settings WHERE key = 'twinfield_queue_apikey';
|
|
904
1359
|
|
|
@@ -930,9 +1385,7 @@ DECLARE
|
|
|
930
1385
|
v_jobid bigint;
|
|
931
1386
|
v_command text;
|
|
932
1387
|
BEGIN
|
|
933
|
-
|
|
934
|
-
RAISE EXCEPTION 'Alleen admins mogen de Floriday-netwerk-cron instellen';
|
|
935
|
-
END IF;
|
|
1388
|
+
PERFORM public.klanten_toegang('beheerder');
|
|
936
1389
|
|
|
937
1390
|
IF p_url IS NULL OR length(p_url) = 0 OR p_apikey IS NULL OR length(p_apikey) = 0 THEN
|
|
938
1391
|
RAISE EXCEPTION 'p_url en p_apikey zijn verplicht';
|
|
@@ -972,6 +1425,7 @@ SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.set_p
|
|
|
972
1425
|
AS $function$
|
|
973
1426
|
DECLARE v_cust uuid; v_group text;
|
|
974
1427
|
BEGIN
|
|
1428
|
+
PERFORM public.klanten_toegang('ingelogd');
|
|
975
1429
|
SELECT customer_id, group_key INTO v_cust, v_group FROM customer_delivery_locations WHERE id = p_location_id;
|
|
976
1430
|
IF NOT FOUND THEN RAISE EXCEPTION 'Locatie niet gevonden'; END IF;
|
|
977
1431
|
IF v_cust IS NOT NULL THEN
|
|
@@ -990,6 +1444,7 @@ AS $function$
|
|
|
990
1444
|
DECLARE
|
|
991
1445
|
v_count integer := 0;
|
|
992
1446
|
BEGIN
|
|
1447
|
+
PERFORM public.klanten_toegang('ingelogd');
|
|
993
1448
|
WITH fd AS (
|
|
994
1449
|
SELECT
|
|
995
1450
|
c.floriday_id::text AS fd_price_group_id,
|
|
@@ -1122,6 +1577,7 @@ SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.twinf
|
|
|
1122
1577
|
AS $function$
|
|
1123
1578
|
DECLARE k text; v jsonb; sets text := '';
|
|
1124
1579
|
BEGIN
|
|
1580
|
+
PERFORM public.klanten_toegang('server');
|
|
1125
1581
|
PERFORM set_config('app.skip_twinfield_push', 'on', true);
|
|
1126
1582
|
FOR k, v IN SELECT * FROM jsonb_each(coalesce(_patch, '{}'::jsonb)) LOOP
|
|
1127
1583
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema='public' AND table_name='customers' AND column_name=k) THEN CONTINUE; END IF;
|
|
@@ -1138,6 +1594,7 @@ SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.twinf
|
|
|
1138
1594
|
AS $function$
|
|
1139
1595
|
DECLARE new_id uuid; cols text; vals text;
|
|
1140
1596
|
BEGIN
|
|
1597
|
+
PERFORM public.klanten_toegang('server');
|
|
1141
1598
|
PERFORM set_config('app.skip_twinfield_push', 'on', true);
|
|
1142
1599
|
SELECT string_agg(format('%I', c.column_name), ', '),
|
|
1143
1600
|
string_agg(format('(jsonb_populate_record(NULL::public.customers, $1)).%I', c.column_name), ', ')
|
|
@@ -1155,6 +1612,7 @@ SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.twinf
|
|
|
1155
1612
|
SET search_path TO 'public'
|
|
1156
1613
|
AS $function$
|
|
1157
1614
|
BEGIN
|
|
1615
|
+
PERFORM public.klanten_toegang('server');
|
|
1158
1616
|
PERFORM set_config('app.skip_twinfield_push', 'on', true);
|
|
1159
1617
|
UPDATE public.customers SET twinfield_present = false, twinfield_missing_since = coalesce(twinfield_missing_since, now())
|
|
1160
1618
|
WHERE id = ANY(_ids);
|
|
@@ -1705,8 +2163,12 @@ SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FR
|
|
|
1705
2163
|
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='twinfield_push_log' AND policyname='service role only') THEN CREATE POLICY "service role only" ON public.twinfield_push_log AS PERMISSIVE FOR ALL TO service_role USING (true) WITH CHECK (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''twinf');
|
|
1706
2164
|
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.floriday_customer_candidates()
|
|
1707
2165
|
RETURNS TABLE(organization_id text, reason text, in_cache boolean)
|
|
1708
|
-
LANGUAGE
|
|
2166
|
+
LANGUAGE plpgsql STABLE SECURITY DEFINER SET search_path TO 'public'
|
|
1709
2167
|
AS $function$
|
|
2168
|
+
#variable_conflict use_column
|
|
2169
|
+
BEGIN
|
|
2170
|
+
PERFORM public.klanten_toegang('ingelogd');
|
|
2171
|
+
RETURN QUERY
|
|
1710
2172
|
WITH rel AS (
|
|
1711
2173
|
SELECT DISTINCT cc.data->>'customerOrganizationId' AS org, 'inkooprelatie'::text AS reason
|
|
1712
2174
|
FROM floriday_connections_cache cc
|
|
@@ -1722,10 +2184,14 @@ AS $function$
|
|
|
1722
2184
|
EXISTS (SELECT 1 FROM floriday_customers_cache f WHERE f.organization_id = al.org AND COALESCE(f.is_deleted,false)=false)
|
|
1723
2185
|
FROM al
|
|
1724
2186
|
WHERE NOT EXISTS (SELECT 1 FROM customers c WHERE c.floriday_organization_id = al.org);
|
|
2187
|
+
END
|
|
1725
2188
|
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.floriday_customer_candidates() RETURNS TABLE(organization_id text,');
|
|
1726
2189
|
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.floriday_customer_promotion_preview()
|
|
1727
|
-
RETURNS jsonb LANGUAGE
|
|
2190
|
+
RETURNS jsonb LANGUAGE plpgsql STABLE SECURITY DEFINER SET search_path TO 'public'
|
|
1728
2191
|
AS $function$
|
|
2192
|
+
BEGIN
|
|
2193
|
+
PERFORM public.klanten_toegang('ingelogd');
|
|
2194
|
+
RETURN (
|
|
1729
2195
|
WITH k AS (SELECT * FROM floriday_customer_candidates())
|
|
1730
2196
|
SELECT jsonb_build_object(
|
|
1731
2197
|
'nieuw_via_inkooprelatie', (SELECT count(*) FROM k WHERE reason='inkooprelatie' AND in_cache),
|
|
@@ -1734,14 +2200,16 @@ AS $function$
|
|
|
1734
2200
|
'koppelen_op_gln', (SELECT count(DISTINCT k.organization_id) FROM k
|
|
1735
2201
|
JOIN floriday_customers_cache f ON f.organization_id = k.organization_id AND COALESCE(f.is_deleted,false)=false
|
|
1736
2202
|
WHERE (SELECT count(*) FROM customers c WHERE c.floriday_organization_id IS NULL
|
|
1737
|
-
AND btrim(c.gln) = COALESCE(NULLIF(btrim(f.gln_code),''), NULLIF(btrim(f.data->>'companyGln'),''))) = 1));
|
|
1738
|
-
|
|
2203
|
+
AND btrim(c.gln) = COALESCE(NULLIF(btrim(f.gln_code),''), NULLIF(btrim(f.data->>'companyGln'),''))) = 1)));
|
|
2204
|
+
END
|
|
2205
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.floriday_customer_promotion_preview() RETURNS jsonb LANGUAGE plpgs');
|
|
1739
2206
|
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.klanten_promote_round()
|
|
1740
2207
|
RETURNS jsonb LANGUAGE plpgsql SECURITY DEFINER SET search_path TO 'public'
|
|
1741
2208
|
AS $function$
|
|
1742
2209
|
DECLARE _r record; _made int := 0; _linked int := 0; _skip int := 0; _fail int := 0; _filled int := 0;
|
|
1743
2210
|
_before int; _id uuid; _res jsonb;
|
|
1744
2211
|
BEGIN
|
|
2212
|
+
PERFORM public.klanten_toegang('beheerder');
|
|
1745
2213
|
FOR _r IN
|
|
1746
2214
|
SELECT organization_id, bool_or(in_cache) AS in_cache,
|
|
1747
2215
|
CASE WHEN bool_or(reason='inkooprelatie') THEN 'inkooprelatie' ELSE 'order' END AS reason
|
|
@@ -1792,6 +2260,7 @@ SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.promo
|
|
|
1792
2260
|
AS $function$
|
|
1793
2261
|
DECLARE _res jsonb;
|
|
1794
2262
|
BEGIN
|
|
2263
|
+
PERFORM public.klanten_toegang('server');
|
|
1795
2264
|
_res := klanten_promote_round();
|
|
1796
2265
|
RETURN COALESCE((_res->>'aangemaakt')::int,0) + COALESCE((_res->>'gekoppeld')::int,0);
|
|
1797
2266
|
END;
|
|
@@ -1801,9 +2270,7 @@ SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.klant
|
|
|
1801
2270
|
AS $function$
|
|
1802
2271
|
DECLARE _res jsonb;
|
|
1803
2272
|
BEGIN
|
|
1804
|
-
|
|
1805
|
-
RAISE EXCEPTION 'Alleen voor beheerders';
|
|
1806
|
-
END IF;
|
|
2273
|
+
PERFORM public.klanten_toegang('ingelogd');
|
|
1807
2274
|
WITH k AS (SELECT * FROM floriday_customer_candidates()),
|
|
1808
2275
|
g AS (
|
|
1809
2276
|
SELECT k.organization_id, k.reason, k.in_cache,
|
|
@@ -1851,9 +2318,7 @@ SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.klant
|
|
|
1851
2318
|
AS $function$
|
|
1852
2319
|
DECLARE _key text;
|
|
1853
2320
|
BEGIN
|
|
1854
|
-
|
|
1855
|
-
RAISE EXCEPTION 'Alleen voor beheerders';
|
|
1856
|
-
END IF;
|
|
2321
|
+
PERFORM public.klanten_toegang('beheerder');
|
|
1857
2322
|
_key := CASE p_kind WHEN 'relations' THEN 'klanten_auto_promote_relations'
|
|
1858
2323
|
WHEN 'orders' THEN 'klanten_auto_promote_orders' END;
|
|
1859
2324
|
IF _key IS NULL THEN RAISE EXCEPTION 'Onbekende schakelaar %', p_kind; END IF;
|
|
@@ -1875,6 +2340,7 @@ SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.klant
|
|
|
1875
2340
|
RETURNS boolean LANGUAGE plpgsql SECURITY DEFINER SET search_path TO 'public'
|
|
1876
2341
|
AS $function$
|
|
1877
2342
|
BEGIN
|
|
2343
|
+
PERFORM public.klanten_toegang('ingelogd');
|
|
1878
2344
|
IF auth.uid() IS NULL THEN RETURN false; END IF;
|
|
1879
2345
|
IF EXISTS (SELECT 1 FROM customers c WHERE NOT EXISTS (
|
|
1880
2346
|
SELECT 1 FROM external_customers_grouped g
|