@flowselections/floriday-voorraad 1.0.141 → 1.0.143

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.
@@ -0,0 +1,15 @@
1
+ export type EngineCarrier = {
2
+ code: string | null;
3
+ melding: string | null;
4
+ };
5
+ export declare const ENGINE_ONTBREEKT = "De Logistiek Engine is niet ge\u00EFnstalleerd, daardoor kan de ladingdrager niet worden vertaald. Neem contact op met de beheerder.";
6
+ /** Zet het antwoord (of de fout) van de Engine om; puur, zodat het te testen is. */
7
+ export declare function interpretEngineCarrier(invoer: string, data: {
8
+ code?: string | null;
9
+ fout?: string | null;
10
+ } | null | undefined, error: {
11
+ code?: string;
12
+ message?: string;
13
+ } | null | undefined): EngineCarrier;
14
+ export declare function resolveEngineCarrier(client: any, code: string): Promise<EngineCarrier>;
15
+ //# sourceMappingURL=engine-carrier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine-carrier.d.ts","sourceRoot":"","sources":["../../src/lib/engine-carrier.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,aAAa,GAAG;IAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAE5E,eAAO,MAAM,gBAAgB,yIACsG,CAAC;AAEpI,oFAAoF;AACpF,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,EACvE,KAAK,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,GAC5D,aAAa,CAUf;AAED,wBAAsB,oBAAoB,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAI5F"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Ladingdrager → Engine-code. De enige bron is de Logistiek Engine
3
+ * (logistics_ladingdrager_resolve over logistics_floriday_carrier_map).
4
+ * Geen eigen terugvallijst: ontbreekt de Engine of de vertaling, dan een melding.
5
+ */
6
+ import { isMissingFunctionError } from "./buyer-organizations.js";
7
+ export const ENGINE_ONTBREEKT = "De Logistiek Engine is niet geïnstalleerd, daardoor kan de ladingdrager niet worden vertaald. Neem contact op met de beheerder.";
8
+ /** Zet het antwoord (of de fout) van de Engine om; puur, zodat het te testen is. */
9
+ export function interpretEngineCarrier(invoer, data, error) {
10
+ if (error) {
11
+ if (isMissingFunctionError(error))
12
+ return { code: null, melding: ENGINE_ONTBREEKT };
13
+ return { code: null, melding: "De ladingdrager kon niet bij de Logistiek Engine worden gecontroleerd. Probeer het opnieuw." };
14
+ }
15
+ if (data?.code)
16
+ return { code: data.code, melding: null };
17
+ return {
18
+ code: null,
19
+ melding: `De Logistiek Engine kan ladingdrager "${invoer}" niet vertalen${data?.fout ? ` (${data.fout})` : ""}. Kies een andere ladingdrager of vraag de beheerder de vertaling toe te voegen.`,
20
+ };
21
+ }
22
+ export async function resolveEngineCarrier(client, code) {
23
+ if (!code.trim())
24
+ return { code: null, melding: null };
25
+ const { data, error } = await client.rpc("logistics_ladingdrager_resolve", { p_code: code });
26
+ return interpretEngineCarrier(code, data, error);
27
+ }
@@ -14,16 +14,14 @@ export interface SimplePacking {
14
14
  loadCarrier: string;
15
15
  }
16
16
  export declare const EMPTY_SIMPLE_PACKING: SimplePacking;
17
- /** Floriday-ladingdrager → code van de Engine (load_carrier_types.code). */
18
- export declare const ENGINE_CARRIER_CODE: Record<string, string>;
19
17
  /** Namen van de velden die nog ontbreken of ongeldig zijn (leeg = compleet). */
20
18
  export declare function missingPackingFields(p: SimplePacking): string[];
21
19
  /** Hoofdverpakking voor product_packings; gooit als iets ontbreekt. */
22
20
  export declare function simplePackingToRow(p: SimplePacking): ProductPackingRow;
23
21
  /** Regel voor logistics_product_oordeel_belading (Engine). */
24
- export declare function engineOordeelRegel(productId: string, p: SimplePacking): {
22
+ export declare function engineOordeelRegel(productId: string, p: SimplePacking, engineCarrierCode: string | null): {
25
23
  product_id: string;
26
- carrier_code: string;
24
+ carrier_code: string | null;
27
25
  plants_per_crate: number | null;
28
26
  crates_per_layer: number | null;
29
27
  layers_per_cart: number | null;
@@ -1 +1 @@
1
- {"version":3,"file":"simple-packing.d.ts","sourceRoot":"","sources":["../../src/lib/simple-packing.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,MAAM,WAAW,aAAa;IAC5B,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,sDAAsD;IACtD,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,oBAAoB,EAAE,aAMlC,CAAC;AAEF,4EAA4E;AAC5E,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAOtD,CAAC;AAOF,gFAAgF;AAChF,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,aAAa,GAAG,MAAM,EAAE,CAQ/D;AAED,uEAAuE;AACvE,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,aAAa,GAAG,iBAAiB,CActE;AAED,8DAA8D;AAC9D,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,aAAa;;;;;;EAQrE"}
1
+ {"version":3,"file":"simple-packing.d.ts","sourceRoot":"","sources":["../../src/lib/simple-packing.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,MAAM,WAAW,aAAa;IAC5B,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,sDAAsD;IACtD,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,oBAAoB,EAAE,aAMlC,CAAC;AAUF,gFAAgF;AAChF,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,aAAa,GAAG,MAAM,EAAE,CAQ/D;AAED,uEAAuE;AACvE,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,aAAa,GAAG,iBAAiB,CActE;AAED,8DAA8D;AAC9D,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,GAAG,IAAI;;;;;;EAQvG"}
@@ -5,15 +5,8 @@ export const EMPTY_SIMPLE_PACKING = {
5
5
  layersPerLoadCarrier: "",
6
6
  loadCarrier: "",
7
7
  };
8
- /** Floriday-ladingdrager → code van de Engine (load_carrier_types.code). */
9
- export const ENGINE_CARRIER_CODE = {
10
- AUCTION_TROLLEY: "trolley",
11
- DANISH_TROLLEY: "danish_container",
12
- EURO_TROLLEY: "euro_rolcontainer",
13
- PALLET: "pallet",
14
- EURO_PALLET: "euro_pallet",
15
- NONE: "loose",
16
- };
8
+ // De vertaling Floriday-ladingdrager → Engine-code komt alleen van de Engine
9
+ // (zie ../lib/engine-carrier.ts); hier staat bewust geen eigen lijst.
17
10
  function posInt(v) {
18
11
  const n = Number(String(v).trim());
19
12
  return Number.isInteger(n) && n > 0 ? n : null;
@@ -29,7 +22,7 @@ export function missingPackingFields(p) {
29
22
  out.push("fusten per laag");
30
23
  if (posInt(p.layersPerLoadCarrier) === null)
31
24
  out.push("lagen per kar");
32
- if (!ENGINE_CARRIER_CODE[p.loadCarrier])
25
+ if (!p.loadCarrier.trim())
33
26
  out.push("ladingdrager");
34
27
  return out;
35
28
  }
@@ -51,10 +44,10 @@ export function simplePackingToRow(p) {
51
44
  };
52
45
  }
53
46
  /** Regel voor logistics_product_oordeel_belading (Engine). */
54
- export function engineOordeelRegel(productId, p) {
47
+ export function engineOordeelRegel(productId, p, engineCarrierCode) {
55
48
  return {
56
49
  product_id: productId,
57
- carrier_code: ENGINE_CARRIER_CODE[p.loadCarrier] ?? null,
50
+ carrier_code: engineCarrierCode,
58
51
  plants_per_crate: posInt(p.piecesPerPackage),
59
52
  crates_per_layer: posInt(p.packagesPerLayer),
60
53
  layers_per_cart: posInt(p.layersPerLoadCarrier),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowselections/floriday-voorraad",
3
- "version": "1.0.141",
3
+ "version": "1.0.143",
4
4
  "sideEffects": false,
5
5
  "type": "module",
6
6
  "main": "./dist-lib/index.js",
@@ -51,7 +51,7 @@
51
51
  "devDependencies": {
52
52
  "@cloudflare/vite-plugin": "^1.25.5",
53
53
  "@eslint/js": "^9.32.0",
54
- "@flowselections/core": "1.0.34",
54
+ "@flowselections/core": "1.0.35",
55
55
  "@lovable.dev/vite-tanstack-config": "2.26.5",
56
56
  "@rsbuild/core": "^1.0.0",
57
57
  "@tailwindcss/vite": "^4.2.1",
package/sql/AGENTS.md CHANGED
@@ -6,4 +6,6 @@
6
6
  - The correct fust count per order line comes only from `voorraad_fust_juist(order_item_id)` (same rule as `sync_order_item_fusten`; removed, quarantined, externally fulfilled or cancelled = 0); fust corrections compare against it, because every hand-built copy of the rule drifted.
7
7
  - Local stock saves never depend on the Floriday write gate: every Voorraad queue insert first checks `voorraad_floriday_klaarzetten_toegestaan()` and runs in its own exception block, because the Engine gate trigger raises and rolled back the local save.
8
8
  - A note per stock change travels via tx setting `stock.change_note` (read by the deferred log trigger at commit, so never clear it inside the call); `trade_item_stock.notes` is the fixed article note and changes only when the caller asks (`stock.keep_notes`), because appending each save stacked notes.
9
- - `sql/floriday-voorraad-schema.sql` must carry the package version and required objects; `scripts/check-schema-version.mjs` (prepublishOnly + test) blocks publishing otherwise, because 1.0.139 shipped with a 1.0.136 schema.
9
+ - `sql/floriday-voorraad-schema.sql` must name the newest `supabase/migrations` file in its "Laatste migratie" header and contain the required objects; `scripts/check-schema-version.mjs` (prepublishOnly + test) blocks publishing otherwise; the header version is informational and never higher than package.json, because 1.0.139 shipped a stale schema and the dashboard bumps versions without schema changes.
10
+ - Default data only via `voorraad_ensure_defaults()` (system data upserted by code keeping `naam_aangepast`, retired codes set inactive; customer settings only inserted when missing, with column defaults equal to reader fallbacks); bump `voorraad_defaults_versie()` on every list change, because new shells get the schema without data and the fast exit compares that version.
11
+ - Load carrier → Engine code only via the Engine's `logistics_ladingdrager_resolve`; no own mapping list or fallback, because two lists drift.
@@ -1,4 +1,5 @@
1
- -- @flowselections/floriday-voorraad 1.0.141 – volledig schema (idempotent, geen gegevens).
1
+ -- @flowselections/floriday-voorraad 1.0.142 – volledig schema (idempotent, geen gegevens).
2
+ -- Laatste migratie: 20261102125718_08100bc6-2bc9-4905-9e62-4c7aca9ce3ff.sql
2
3
  -- Gegenereerd uit de database met scripts/generate-voorraad-schema.py. Niet met de hand wijzigen.
3
4
  -- Volgorde 20. Ontbrekende tabellen van andere modules worden overgeslagen met een NOTICE; draai opnieuw na die module.
4
5
  -- De statuscontrole van floriday_continuous_stock_queue is van Voorraad en wordt hier opnieuw gemaakt.
@@ -530,6 +531,13 @@ ALTER TABLE public.voorraad_custom_fields ADD COLUMN IF NOT EXISTS sort_order in
530
531
  ALTER TABLE public.voorraad_custom_fields ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT now() NOT NULL;
531
532
  ALTER TABLE public.voorraad_custom_fields ADD COLUMN IF NOT EXISTS updated_at timestamp with time zone DEFAULT now() NOT NULL;
532
533
 
534
+ -- voorraad_defaults_state
535
+ CREATE TABLE IF NOT EXISTS public.voorraad_defaults_state ();
536
+ ALTER TABLE public.voorraad_defaults_state ADD COLUMN IF NOT EXISTS id boolean DEFAULT true NOT NULL;
537
+ ALTER TABLE public.voorraad_defaults_state ADD COLUMN IF NOT EXISTS versie integer NOT NULL;
538
+ ALTER TABLE public.voorraad_defaults_state ADD COLUMN IF NOT EXISTS toegepast_at timestamp with time zone DEFAULT now() NOT NULL;
539
+ ALTER TABLE public.voorraad_defaults_state ADD COLUMN IF NOT EXISTS resultaat jsonb DEFAULT '{}'::jsonb NOT NULL;
540
+
533
541
  -- voorraad_load_carrier_types
534
542
  CREATE TABLE IF NOT EXISTS public.voorraad_load_carrier_types ();
535
543
  ALTER TABLE public.voorraad_load_carrier_types ADD COLUMN IF NOT EXISTS code text NOT NULL;
@@ -537,6 +545,8 @@ ALTER TABLE public.voorraad_load_carrier_types ADD COLUMN IF NOT EXISTS naam tex
537
545
  ALTER TABLE public.voorraad_load_carrier_types ADD COLUMN IF NOT EXISTS volgorde integer NOT NULL;
538
546
  ALTER TABLE public.voorraad_load_carrier_types ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT now() NOT NULL;
539
547
  ALTER TABLE public.voorraad_load_carrier_types ADD COLUMN IF NOT EXISTS updated_at timestamp with time zone DEFAULT now() NOT NULL;
548
+ ALTER TABLE public.voorraad_load_carrier_types ADD COLUMN IF NOT EXISTS actief boolean DEFAULT true NOT NULL;
549
+ ALTER TABLE public.voorraad_load_carrier_types ADD COLUMN IF NOT EXISTS naam_aangepast boolean DEFAULT false NOT NULL;
540
550
 
541
551
  -- voorraad_local_context
542
552
  CREATE TABLE IF NOT EXISTS public.voorraad_local_context ();
@@ -2258,6 +2268,7 @@ AS $function$
2258
2268
  DECLARE n integer := 0; v_batch int;
2259
2269
  BEGIN
2260
2270
  PERFORM public.voorraad_vereis('server', 'drain_inventory_recompute_queue');
2271
+ BEGIN PERFORM public.voorraad_ensure_defaults(); EXCEPTION WHEN others THEN NULL; END;
2261
2272
  SELECT drain_batch INTO v_batch FROM public.inventory_recompute_limits WHERE id;
2262
2273
  PERFORM set_config('inventory.inline_overflow', '0', true);
2263
2274
  n := public.process_inventory_recompute_queue(COALESCE(v_batch, 500));
@@ -4924,6 +4935,7 @@ DECLARE
4924
4935
  v_frozen_ids uuid[];
4925
4936
  BEGIN
4926
4937
  PERFORM public.voorraad_vereis('ingelogd', 'recompute_all_reserved_stock');
4938
+ BEGIN PERFORM public.voorraad_ensure_defaults(); EXCEPTION WHEN others THEN NULL; END;
4927
4939
  IF current_setting('app.recomputing_reserved', true) = 'on' THEN RETURN; END IF;
4928
4940
  PERFORM set_config('app.recomputing_reserved', 'on', true);
4929
4941
 
@@ -6059,7 +6071,7 @@ BEGIN
6059
6071
  v_user := COALESCE(v_uid, v_ctx.user_id);
6060
6072
  SELECT import_chunk_size, import_new_chunk_size, import_max_rows, import_max_bytes INTO l FROM public.inventory_recompute_limits WHERE id;
6061
6073
  v_cs := GREATEST(COALESCE(l.import_chunk_size, 200), 1);
6062
- v_ncs := LEAST(GREATEST(COALESCE(l.import_new_chunk_size, 40), 1), v_cs);
6074
+ v_ncs := LEAST(GREATEST(COALESCE(l.import_new_chunk_size, 20), 1), v_cs);
6063
6075
  IF p_rows IS NULL OR jsonb_typeof(p_rows) <> 'array' OR jsonb_array_length(p_rows) = 0 THEN
6064
6076
  RETURN jsonb_build_object('ok', false, 'code', 'IMPORT_EMPTY', 'message', 'Het bestand bevat geen rijen.');
6065
6077
  END IF;
@@ -8936,6 +8948,56 @@ REVOKE ALL ON FUNCTION voorraad_correctie_status(text) FROM PUBLIC;
8936
8948
  REVOKE ALL ON FUNCTION voorraad_correctie_status(text) FROM anon;
8937
8949
  GRANT EXECUTE ON FUNCTION voorraad_correctie_status(text) TO authenticated;
8938
8950
  GRANT EXECUTE ON FUNCTION voorraad_correctie_status(text) TO service_role;
8951
+ CREATE OR REPLACE FUNCTION public.voorraad_defaults_check()
8952
+ RETURNS jsonb
8953
+ LANGUAGE plpgsql
8954
+ STABLE SECURITY DEFINER
8955
+ SET search_path TO 'public'
8956
+ AS $function$
8957
+ DECLARE v_vert jsonb := '[]'::jsonb; r record; v_res jsonb; v_engine boolean;
8958
+ BEGIN
8959
+ PERFORM public.voorraad_vereis('ingelogd', 'voorraad_defaults_check');
8960
+ v_engine := to_regprocedure('public.logistics_ladingdrager_resolve(text)') IS NOT NULL;
8961
+ IF v_engine THEN
8962
+ FOR r IN SELECT code FROM public.voorraad_load_carrier_types WHERE actief ORDER BY volgorde, code LOOP
8963
+ BEGIN
8964
+ EXECUTE 'SELECT public.logistics_ladingdrager_resolve($1)' INTO v_res USING r.code;
8965
+ EXCEPTION WHEN others THEN v_res := jsonb_build_object('code', NULL, 'fout', SQLERRM);
8966
+ END;
8967
+ IF v_res->>'code' IS NULL THEN
8968
+ v_vert := v_vert || jsonb_build_object('code', r.code, 'reden', COALESCE(v_res->>'fout', 'onbekend'));
8969
+ END IF;
8970
+ END LOOP;
8971
+ END IF;
8972
+ RETURN jsonb_build_object(
8973
+ 'versie_code', public.voorraad_defaults_versie(),
8974
+ 'versie_toegepast', (SELECT versie FROM public.voorraad_defaults_state WHERE id),
8975
+ 'plaatshoudercodes', (SELECT count(*) FROM public.voorraad_placeholder_codes),
8976
+ 'ladingdragers_actief', (SELECT count(*) FROM public.voorraad_load_carrier_types WHERE actief),
8977
+ 'herberekenlimieten_aanwezig', EXISTS (SELECT 1 FROM public.inventory_recompute_limits WHERE id),
8978
+ 'engine_vertaling_aanwezig', v_engine,
8979
+ 'ladingdragers_niet_vertaalbaar', CASE WHEN v_engine THEN v_vert ELSE NULL END);
8980
+ END $function$
8981
+ ;
8982
+ REVOKE ALL ON FUNCTION voorraad_defaults_check() FROM PUBLIC;
8983
+ REVOKE ALL ON FUNCTION voorraad_defaults_check() FROM anon;
8984
+ GRANT EXECUTE ON FUNCTION voorraad_defaults_check() TO authenticated;
8985
+ GRANT EXECUTE ON FUNCTION voorraad_defaults_check() TO service_role;
8986
+ CREATE OR REPLACE FUNCTION public.voorraad_defaults_versie()
8987
+ RETURNS integer
8988
+ LANGUAGE sql
8989
+ IMMUTABLE
8990
+ SET search_path TO 'public'
8991
+ AS $function$ SELECT 1 $function$
8992
+ ;
8993
+ REVOKE ALL ON FUNCTION voorraad_defaults_versie() FROM PUBLIC;
8994
+ REVOKE ALL ON FUNCTION voorraad_defaults_versie() FROM anon;
8995
+ REVOKE EXECUTE ON FUNCTION voorraad_defaults_versie() FROM PUBLIC;
8996
+ GRANT EXECUTE ON FUNCTION voorraad_defaults_versie() TO authenticated;
8997
+ GRANT EXECUTE ON FUNCTION voorraad_defaults_versie() TO service_role;
8998
+ REVOKE EXECUTE ON FUNCTION voorraad_defaults_versie() FROM anon;
8999
+ GRANT EXECUTE ON FUNCTION voorraad_defaults_versie() TO authenticated;
9000
+ GRANT EXECUTE ON FUNCTION voorraad_defaults_versie() TO service_role;
8939
9001
  CREATE OR REPLACE FUNCTION public.voorraad_dubbele_voorraadregels()
8940
9002
  RETURNS jsonb
8941
9003
  LANGUAGE plpgsql
@@ -8963,6 +9025,68 @@ REVOKE ALL ON FUNCTION voorraad_dubbele_voorraadregels() FROM PUBLIC;
8963
9025
  REVOKE ALL ON FUNCTION voorraad_dubbele_voorraadregels() FROM anon;
8964
9026
  GRANT EXECUTE ON FUNCTION voorraad_dubbele_voorraadregels() TO authenticated;
8965
9027
  GRANT EXECUTE ON FUNCTION voorraad_dubbele_voorraadregels() TO service_role;
9028
+ CREATE OR REPLACE FUNCTION public.voorraad_ensure_defaults()
9029
+ RETURNS jsonb
9030
+ LANGUAGE plpgsql
9031
+ SECURITY DEFINER
9032
+ SET search_path TO 'public'
9033
+ AS $function$
9034
+ DECLARE
9035
+ v_versie int := public.voorraad_defaults_versie();
9036
+ -- Systeemgegevens (standaardlijst versie 1). Wijzig je deze lijst: verhoog voorraad_defaults_versie().
9037
+ v_ph text[] := ARRAY['artikelcode','artikelnummer','naam','name','code','article code','articlecode','test','-','x','nvt','n.v.t.','tbd','todo'];
9038
+ v_lc jsonb := '[{"code":"AUCTION_TROLLEY","naam":"Stapelwagen","volgorde":1},{"code":"DANISH_TROLLEY","naam":"Deense container","volgorde":2},{"code":"EURO_TROLLEY","naam":"Euro-rolcontainer","volgorde":3},{"code":"PALLET","naam":"Pallet","volgorde":4},{"code":"EURO_PALLET","naam":"Euro-pallet","volgorde":5},{"code":"NONE","naam":"Geen ladingdrager","volgorde":6}]';
9039
+ -- Standaardcodes die vervallen zijn: worden op niet actief gezet, nooit verwijderd.
9040
+ v_vervallen text[] := ARRAY[]::text[];
9041
+ n_ph int := 0; n_lc_nieuw int := 0; n_lc_bij int := 0; n_lc_uit int := 0; n_lim int := 0; v_res jsonb;
9042
+ BEGIN
9043
+ PERFORM public.voorraad_vereis('ingelogd', 'voorraad_ensure_defaults');
9044
+ BEGIN
9045
+ IF EXISTS (SELECT 1 FROM public.voorraad_defaults_state s WHERE s.id AND s.versie = v_versie)
9046
+ AND EXISTS (SELECT 1 FROM public.inventory_recompute_limits l WHERE l.id)
9047
+ AND EXISTS (SELECT 1 FROM public.voorraad_placeholder_codes)
9048
+ AND EXISTS (SELECT 1 FROM public.voorraad_load_carrier_types) THEN
9049
+ RETURN jsonb_build_object('ok', true, 'versie', v_versie, 'overgeslagen', true);
9050
+ END IF;
9051
+ PERFORM pg_advisory_xact_lock(hashtext('voorraad_ensure_defaults'));
9052
+
9053
+ INSERT INTO public.voorraad_placeholder_codes(code) SELECT c FROM unnest(v_ph) c ON CONFLICT (code) DO NOTHING;
9054
+ GET DIAGNOSTICS n_ph = ROW_COUNT;
9055
+
9056
+ INSERT INTO public.voorraad_load_carrier_types(code, naam, volgorde)
9057
+ SELECT e->>'code', e->>'naam', (e->>'volgorde')::int FROM jsonb_array_elements(v_lc) e
9058
+ ON CONFLICT (code) DO NOTHING;
9059
+ GET DIAGNOSTICS n_lc_nieuw = ROW_COUNT;
9060
+ UPDATE public.voorraad_load_carrier_types t
9061
+ SET volgorde = (e->>'volgorde')::int,
9062
+ naam = CASE WHEN t.naam_aangepast THEN t.naam ELSE e->>'naam' END,
9063
+ updated_at = now()
9064
+ FROM jsonb_array_elements(v_lc) e
9065
+ WHERE t.code = e->>'code'
9066
+ AND (t.volgorde IS DISTINCT FROM (e->>'volgorde')::int OR (NOT t.naam_aangepast AND t.naam IS DISTINCT FROM e->>'naam'));
9067
+ GET DIAGNOSTICS n_lc_bij = ROW_COUNT;
9068
+ UPDATE public.voorraad_load_carrier_types t SET actief = false, updated_at = now()
9069
+ WHERE t.code = ANY(v_vervallen) AND t.actief;
9070
+ GET DIAGNOSTICS n_lc_uit = ROW_COUNT;
9071
+
9072
+ -- Klantinstelling: alleen aanmaken als hij ontbreekt, met de kolomstandaarden.
9073
+ INSERT INTO public.inventory_recompute_limits DEFAULT VALUES ON CONFLICT (id) DO NOTHING;
9074
+ GET DIAGNOSTICS n_lim = ROW_COUNT;
9075
+
9076
+ v_res := jsonb_build_object('plaatshoudercodes_toegevoegd', n_ph, 'ladingdragers_toegevoegd', n_lc_nieuw,
9077
+ 'ladingdragers_bijgewerkt', n_lc_bij, 'ladingdragers_niet_actief', n_lc_uit, 'herberekenlimieten_aangemaakt', n_lim);
9078
+ INSERT INTO public.voorraad_defaults_state(id, versie, toegepast_at, resultaat) VALUES (true, v_versie, now(), v_res)
9079
+ ON CONFLICT (id) DO UPDATE SET versie = EXCLUDED.versie, toegepast_at = EXCLUDED.toegepast_at, resultaat = EXCLUDED.resultaat;
9080
+ RETURN jsonb_build_object('ok', true, 'versie', v_versie, 'overgeslagen', false) || v_res;
9081
+ EXCEPTION WHEN others THEN
9082
+ RETURN jsonb_build_object('ok', false, 'versie', v_versie, 'melding', 'Standaardgegevens konden niet worden aangevuld', 'detail', SQLERRM);
9083
+ END;
9084
+ END $function$
9085
+ ;
9086
+ REVOKE ALL ON FUNCTION voorraad_ensure_defaults() FROM PUBLIC;
9087
+ REVOKE ALL ON FUNCTION voorraad_ensure_defaults() FROM anon;
9088
+ GRANT EXECUTE ON FUNCTION voorraad_ensure_defaults() TO authenticated;
9089
+ GRANT EXECUTE ON FUNCTION voorraad_ensure_defaults() TO service_role;
8966
9090
  CREATE OR REPLACE FUNCTION public.voorraad_external_fulfilled_ids(p_cf jsonb)
8967
9091
  RETURNS text[]
8968
9092
  LANGUAGE sql
@@ -9301,9 +9425,9 @@ CREATE OR REPLACE FUNCTION public.voorraad_install_check()
9301
9425
  STABLE SECURITY DEFINER
9302
9426
  SET search_path TO 'public'
9303
9427
  AS $function$
9304
- DECLARE v_f text[] := ARRAY['voorraad_canoniek_artikel','voorraad_canoniek_sleutel','voorraad_artikel_prijs','voorraad_dubbele_voorraadregels','voorraad_correctie_1131','voorraad_correctie_1132','voorraad_gateway_routes_check','voorraad_placeholder_code_reason','trg_products_placeholder_code','voorraad_fust_juist','voorraad_correctie_1121','voorraad_correctie_1121_regels','voorraad_correctie_1123','voorraad_correctie_1124','voorraad_load_carriers','voorraad_packing_from_floriday','voorraad_packing_missing','voorraad_correctie_1126','voorraad_correctie_1127','trg_voorraad_link_primary_packing','voorraad_order_geannuleerd','voorraad_article_vbn','voorraad_correctie_1112','voorraad_reverse_order_mutations','voorraad_withdraw_stock_row','voorraad_floriday_klaarzetten_toegestaan','voorraad_afboeken','voorraad_voorraad_opslaan','voorraad_correctie_1140','voorraad_overzicht_orderregel_koppeling','voorraad_orderregel_sleutel','ensure_voorraad_local_context','get_stock_context','voorraad_stock_context_status','voorraad_fcsq_local_guard','_floriday_queue_cleanup_batch','_migrate_rewrite_stock_key','_stock_import_caller','apply_fust_stock_mutation','apply_stock_consumption','apply_stock_reservation','autolink_product_to_floriday','backfill_open_order_reservations','calculate_floriday_desired_stock','calculate_structure_available','canonicalize_trade_item_stock_key','check_product_structure','claim_floriday_base_supply','claim_floriday_stock_queue','cleanup_floriday_stock_queue','cleanup_voorraad_module_history','complete_floriday_base_supply','complete_floriday_stock_queue','complete_floriday_stock_queue_outcome','consume_bom_for_production','consume_order_item','drain_inventory_recompute_queue','enqueue_floriday_continuous_stock','enqueue_floriday_continuous_stock_after_warehouse_preference','enqueue_structure_recompute','ensure_inventory_recompute_drain','ensure_trade_item_stock_row','ensure_trade_item_stock_row_key','fcsq_block_disabled','fcsq_fallback_supersede','fcsq_wake_base_supply','find_trade_item_key','floriday_adopt_connection','floriday_autoheal_connections','floriday_capture_stock_snapshot','floriday_cleanup_stock_queue_v2','floriday_compact_stock_snapshots','floriday_default_owner','floriday_desired_stock_regression_check','floriday_ensure_inventory_settings','floriday_erp_leading_preview','floriday_fill_publish_horizon','floriday_follow_apply','floriday_ingest_sales_orders','floriday_leading_summary','floriday_make_erp_leading','floriday_norm_offer_forms','floriday_orphan_settings_count','floriday_publish_horizon_weeks','floriday_queue_erp_guard','floriday_queue_first_positive','floriday_recompute_inventory','floriday_relink_products','floriday_requeue_dead_letters','floriday_settings_change_recompute','floriday_settings_change_recompute_stmt','floriday_stock_change_recompute','floriday_stock_queue_supersede','floriday_takeover_apply','floriday_takeover_fetch_state','floriday_takeover_store_forms','floriday_takeover_undo','fust_negative_stock_report','fust_types_duplicate_guard','get_active_floriday_context','get_group_allocation_keys','get_group_head_key','get_product_stock','get_product_structure_totals','get_product_structure_totals_batch','inventory_inline_budget_ok','merge_products','normalize_order_source','process_inventory_recompute_queue','produce_designed_product','product_active_group_id','product_id_from_ref','product_is_set','product_label','product_member_group_ids','product_own_available','product_packings_derive','product_packings_replace','product_packings_sync_from_floriday','product_primary_pieces','product_set_depth_above','product_set_depth_below','product_structure_ancestors','product_structure_max_depth','product_structure_path','product_tray_stickers_touch','product_type','promote_trade_item_key','recompute_all_reserved_stock','recompute_order_status','recompute_reserved_for_order','recompute_reserved_stock','requeue_skipped_stock_rows','reset_stalled_floriday_stock_queue','resolve_group_allocation','resolve_group_member_stock_key','resolve_product_id_for_item','resolve_stock_trade_item_key','reverse_production','run_floriday_base_supply_process','run_floriday_continuous_stock_sync','run_floriday_follow','run_floriday_stock_queue_process','run_floriday_stock_reconcile','run_logistics_tasks_dispatch','self_heal_floriday_links','set_module_runtime_config_updated_at','set_product_bom_tenant','set_product_stock','set_updated_at_order_fust_bookings','stock_import_cleanup','stock_import_create','stock_import_process_chunk','stock_import_stop','stock_import_undo_chunk','sync_order_item_fusten','sync_products_quantity_from_stock','touch_fust_types_updated_at','trade_item_drafts_readonly','trade_item_prices_touch_updated_at','trade_item_stock_duplicates','trg_cart_numbers_sync_order_status_fn','trg_cart_session_consume_fn','trg_check_product_structure','trg_floriday_cache_relink_fn','trg_floriday_trade_items_autolink_fn','trg_order_items_autolink_fn','trg_order_items_fusten','trg_order_items_reserve_fn','trg_orders_cancel_release_fn','trg_orders_consume_on_complete_fn','trg_orders_default_phase_fn','trg_orders_external_fulfilled_fn','trg_orders_recompute_reserved_fn','trg_pgi_assign_sort_order','trg_pgi_order_taken_check','trg_process_recompute_on_commit','trg_product_packings_derive_fn','trg_products_autolink_fn','trg_products_floriday_link_enqueue','trg_products_seed_stock_fn','trg_requeue_no_warehouse_cache','trg_requeue_no_warehouse_connection','trg_requeue_no_warehouse_item_pref','trg_requeue_skipped_no_price','trg_stock_structure_recompute_ins','trg_stock_structure_recompute_upd','trg_structure_change_recompute','trg_trade_item_drafts_autolink_fn','trg_trade_item_stock_auto_bom','trg_trade_item_stock_auto_bom_reverse','trg_trade_item_stock_log_change','trg_trade_item_stock_reserve_fn','trg_trade_item_stock_zero_watch','trg_trade_items_cache_autolink_fn','update_updated_at_column','voorraad_alert_floriday_not_updated','voorraad_can_write','voorraad_cleanup_old_rows','voorraad_consume_external_fulfilled','voorraad_correctie_1098','voorraad_correctie_status','voorraad_external_fulfilled_ids','voorraad_floriday_leads_key','voorraad_fust_dimensions','voorraad_hook_base_url','voorraad_hook_on','voorraad_hook_post','voorraad_hook_switch_jobs','voorraad_install_check','voorraad_is_server','voorraad_mark_floriday_sold_before_switch','voorraad_production_enabled','voorraad_schema_ddl','voorraad_touch_updated_at','voorraad_vereis','voorraad_week_is_past'];
9428
+ DECLARE v_f text[] := ARRAY['voorraad_ensure_defaults','voorraad_defaults_check','voorraad_defaults_versie','voorraad_canoniek_artikel','voorraad_canoniek_sleutel','voorraad_artikel_prijs','voorraad_dubbele_voorraadregels','voorraad_correctie_1131','voorraad_correctie_1132','voorraad_gateway_routes_check','voorraad_placeholder_code_reason','trg_products_placeholder_code','voorraad_fust_juist','voorraad_correctie_1121','voorraad_correctie_1121_regels','voorraad_correctie_1123','voorraad_correctie_1124','voorraad_load_carriers','voorraad_packing_from_floriday','voorraad_packing_missing','voorraad_correctie_1126','voorraad_correctie_1127','trg_voorraad_link_primary_packing','voorraad_order_geannuleerd','voorraad_article_vbn','voorraad_correctie_1112','voorraad_reverse_order_mutations','voorraad_withdraw_stock_row','voorraad_floriday_klaarzetten_toegestaan','voorraad_afboeken','voorraad_voorraad_opslaan','voorraad_correctie_1140','voorraad_overzicht_orderregel_koppeling','voorraad_orderregel_sleutel','ensure_voorraad_local_context','get_stock_context','voorraad_stock_context_status','voorraad_fcsq_local_guard','_floriday_queue_cleanup_batch','_migrate_rewrite_stock_key','_stock_import_caller','apply_fust_stock_mutation','apply_stock_consumption','apply_stock_reservation','autolink_product_to_floriday','backfill_open_order_reservations','calculate_floriday_desired_stock','calculate_structure_available','canonicalize_trade_item_stock_key','check_product_structure','claim_floriday_base_supply','claim_floriday_stock_queue','cleanup_floriday_stock_queue','cleanup_voorraad_module_history','complete_floriday_base_supply','complete_floriday_stock_queue','complete_floriday_stock_queue_outcome','consume_bom_for_production','consume_order_item','drain_inventory_recompute_queue','enqueue_floriday_continuous_stock','enqueue_floriday_continuous_stock_after_warehouse_preference','enqueue_structure_recompute','ensure_inventory_recompute_drain','ensure_trade_item_stock_row','ensure_trade_item_stock_row_key','fcsq_block_disabled','fcsq_fallback_supersede','fcsq_wake_base_supply','find_trade_item_key','floriday_adopt_connection','floriday_autoheal_connections','floriday_capture_stock_snapshot','floriday_cleanup_stock_queue_v2','floriday_compact_stock_snapshots','floriday_default_owner','floriday_desired_stock_regression_check','floriday_ensure_inventory_settings','floriday_erp_leading_preview','floriday_fill_publish_horizon','floriday_follow_apply','floriday_ingest_sales_orders','floriday_leading_summary','floriday_make_erp_leading','floriday_norm_offer_forms','floriday_orphan_settings_count','floriday_publish_horizon_weeks','floriday_queue_erp_guard','floriday_queue_first_positive','floriday_recompute_inventory','floriday_relink_products','floriday_requeue_dead_letters','floriday_settings_change_recompute','floriday_settings_change_recompute_stmt','floriday_stock_change_recompute','floriday_stock_queue_supersede','floriday_takeover_apply','floriday_takeover_fetch_state','floriday_takeover_store_forms','floriday_takeover_undo','fust_negative_stock_report','fust_types_duplicate_guard','get_active_floriday_context','get_group_allocation_keys','get_group_head_key','get_product_stock','get_product_structure_totals','get_product_structure_totals_batch','inventory_inline_budget_ok','merge_products','normalize_order_source','process_inventory_recompute_queue','produce_designed_product','product_active_group_id','product_id_from_ref','product_is_set','product_label','product_member_group_ids','product_own_available','product_packings_derive','product_packings_replace','product_packings_sync_from_floriday','product_primary_pieces','product_set_depth_above','product_set_depth_below','product_structure_ancestors','product_structure_max_depth','product_structure_path','product_tray_stickers_touch','product_type','promote_trade_item_key','recompute_all_reserved_stock','recompute_order_status','recompute_reserved_for_order','recompute_reserved_stock','requeue_skipped_stock_rows','reset_stalled_floriday_stock_queue','resolve_group_allocation','resolve_group_member_stock_key','resolve_product_id_for_item','resolve_stock_trade_item_key','reverse_production','run_floriday_base_supply_process','run_floriday_continuous_stock_sync','run_floriday_follow','run_floriday_stock_queue_process','run_floriday_stock_reconcile','run_logistics_tasks_dispatch','self_heal_floriday_links','set_module_runtime_config_updated_at','set_product_bom_tenant','set_product_stock','set_updated_at_order_fust_bookings','stock_import_cleanup','stock_import_create','stock_import_process_chunk','stock_import_stop','stock_import_undo_chunk','sync_order_item_fusten','sync_products_quantity_from_stock','touch_fust_types_updated_at','trade_item_drafts_readonly','trade_item_prices_touch_updated_at','trade_item_stock_duplicates','trg_cart_numbers_sync_order_status_fn','trg_cart_session_consume_fn','trg_check_product_structure','trg_floriday_cache_relink_fn','trg_floriday_trade_items_autolink_fn','trg_order_items_autolink_fn','trg_order_items_fusten','trg_order_items_reserve_fn','trg_orders_cancel_release_fn','trg_orders_consume_on_complete_fn','trg_orders_default_phase_fn','trg_orders_external_fulfilled_fn','trg_orders_recompute_reserved_fn','trg_pgi_assign_sort_order','trg_pgi_order_taken_check','trg_process_recompute_on_commit','trg_product_packings_derive_fn','trg_products_autolink_fn','trg_products_floriday_link_enqueue','trg_products_seed_stock_fn','trg_requeue_no_warehouse_cache','trg_requeue_no_warehouse_connection','trg_requeue_no_warehouse_item_pref','trg_requeue_skipped_no_price','trg_stock_structure_recompute_ins','trg_stock_structure_recompute_upd','trg_structure_change_recompute','trg_trade_item_drafts_autolink_fn','trg_trade_item_stock_auto_bom','trg_trade_item_stock_auto_bom_reverse','trg_trade_item_stock_log_change','trg_trade_item_stock_reserve_fn','trg_trade_item_stock_zero_watch','trg_trade_items_cache_autolink_fn','update_updated_at_column','voorraad_alert_floriday_not_updated','voorraad_can_write','voorraad_cleanup_old_rows','voorraad_consume_external_fulfilled','voorraad_correctie_1098','voorraad_correctie_status','voorraad_external_fulfilled_ids','voorraad_floriday_leads_key','voorraad_fust_dimensions','voorraad_hook_base_url','voorraad_hook_on','voorraad_hook_post','voorraad_hook_switch_jobs','voorraad_install_check','voorraad_is_server','voorraad_mark_floriday_sold_before_switch','voorraad_production_enabled','voorraad_schema_ddl','voorraad_touch_updated_at','voorraad_vereis','voorraad_week_is_past'];
9305
9429
  v_t text[] := ARRAY['trg_voorraad_link_primary_packing@products','aa0_fcsq_local_context_guard@floriday_continuous_stock_queue','aa_fcsq_erp_leading_guard@floriday_continuous_stock_queue','aa_fis_norm_offer_forms@floriday_inventory_settings','aa_pgi_assign_sort_order@product_group_items','fcsq_block_disabled@floriday_continuous_stock_queue','fcsq_wake_base_supply_ins@floriday_continuous_stock_queue','fcsq_wake_base_supply_upd@floriday_continuous_stock_queue','fust_stock_mutations_apply@fust_stock_mutations','fust_types_duplicate_guard@fust_types','fust_types_touch@fust_types','product_packings_derive_trg@product_packings','product_packings_updated_at@product_packings','set_product_bom_tenant_trigger@product_bom_items','trade_item_prices_set_updated_at@trade_item_prices','trg_cart_numbers_sync_order_status@cart_numbers','trg_cart_session_consume@cart_control_sessions','trg_check_product_structure@product_bom_items','trg_check_product_structure@product_group_items','trg_check_product_structure@product_groups','trg_fcs_queue_updated_at@floriday_continuous_stock_queue','trg_fcsq_fallback_supersede@floriday_continuous_stock_queue','trg_fcsq_supersede@floriday_continuous_stock_queue','trg_floriday_cache_relink@floriday_trade_items_cache','trg_floriday_ensure_inventory_settings@products','trg_floriday_gate_stock_queue@floriday_continuous_stock_queue','trg_floriday_settings_change_recompute_ins@floriday_inventory_settings','trg_floriday_settings_change_recompute_upd@floriday_inventory_settings','trg_floriday_stock_change_recompute@trade_item_stock','trg_floriday_takeover_runs_updated_at@floriday_takeover_runs','trg_floriday_trade_items_autolink@floriday_trade_items_cache','trg_fust_types_requeue_blocked@fust_types','trg_module_runtime_config_updated_at@module_runtime_config','trg_order_fust_bookings_updated_at@order_fust_bookings','trg_order_items_autolink@order_items','trg_order_items_fusten_aiud@order_items','trg_order_items_reserve@order_items','trg_orders_cancel_release@orders','trg_orders_consume_on_complete@orders','trg_orders_default_phase@orders','trg_orders_external_fulfilled@orders','trg_orders_recompute_reserved@orders','trg_prevent_duplicate_product_draft@trade_item_drafts','trg_product_tray_stickers_touch@product_tray_stickers','trg_products_autolink@products','trg_products_floriday_link_enqueue@products','trg_products_seed_stock@products','trg_requeue_no_warehouse_cache@floriday_trade_items_cache','trg_requeue_no_warehouse_connection@floriday_connections','trg_requeue_no_warehouse_item_pref@trade_item_warehouse_preferences','trg_requeue_skipped_no_price@products','trg_stock_mutation_alert@stock_mutation_log','trg_stock_structure_recompute_ins@trade_item_stock','trg_stock_structure_recompute_upd@trade_item_stock','trg_structure_change_recompute@product_bom_items','trg_structure_change_recompute@product_group_items','trg_structure_change_recompute@product_groups','trg_sync_layer_stock_from_trade_stock@trade_item_stock','trg_sync_products_quantity_from_stock_del@trade_item_stock','trg_sync_products_quantity_from_stock_iu@trade_item_stock','trg_trade_item_drafts_autolink@trade_item_drafts','trg_trade_item_drafts_readonly@trade_item_drafts','trg_trade_item_stock_canonical_key@trade_item_stock','trg_trade_item_stock_publish@trade_item_stock','trg_trade_item_stock_reserve@trade_item_stock','trg_trade_item_stock_updated_at@trade_item_stock','trg_trade_item_stock_zero_watch@trade_item_stock','trg_trade_item_supply_lines_touch@trade_item_supply_lines','trg_trade_item_warehouse_preference_enqueue_stock@trade_item_warehouse_preferences','trg_trade_items_cache_autolink@floriday_trade_items_cache','trg_voorraad_buffer_state_updated_at@voorraad_buffer_state','trg_voorraad_event_log_updated_at@voorraad_logistics_event_log','update_trade_item_drafts_updated_at@trade_item_drafts','update_trade_item_warehouse_preferences_updated_at@trade_item_warehouse_preferences','update_voorraad_custom_fields_updated_at@voorraad_custom_fields','update_voorraad_publish_jobs_updated_at@voorraad_publish_jobs','update_voorraad_publish_learnings_updated_at@voorraad_publish_learnings','update_voorraad_publish_steps_updated_at@voorraad_publish_steps','voorraad_hook_switch_jobs@module_runtime_config','zz_fcsq_first_positive@floriday_continuous_stock_queue'];
9306
- v_p text[] := ARRAY['Authenticated can add learnings@voorraad_publish_learnings','Authenticated can delete voorraad custom fields@voorraad_custom_fields','Authenticated can insert vbn required characteristics@floriday_vbn_required_characteristics','Authenticated can insert voorraad custom fields@voorraad_custom_fields','Authenticated can read continuous stock cache@floriday_continuous_stock_cache','Authenticated can read learnings@voorraad_publish_learnings','Authenticated can read vbn required characteristics@floriday_vbn_required_characteristics','Authenticated can read voorraad custom fields@voorraad_custom_fields','Authenticated can update learnings@voorraad_publish_learnings','Authenticated can update vbn required characteristics@floriday_vbn_required_characteristics','Authenticated can update voorraad custom fields@voorraad_custom_fields','Authenticated delete trade_item_warehouse_preferences@trade_item_warehouse_preferences','Authenticated insert trade_item_warehouse_preferences@trade_item_warehouse_preferences','Authenticated select trade_item_warehouse_preferences@trade_item_warehouse_preferences','Authenticated update trade_item_warehouse_preferences@trade_item_warehouse_preferences','Eigen momentopnamen lezen@inventory_stock_snapshots','Eigen voorraadinstellingen beheren@floriday_inventory_settings','Eigenaar leest importporties@stock_import_chunks','Eigenaar leest importregels@stock_import_rows','Fust mutations delete@fust_stock_mutations','Fust mutations insert@fust_stock_mutations','Fust mutations read@fust_stock_mutations','Fust mutations update@fust_stock_mutations','Fust types delete@fust_types','Fust types insert@fust_types','Fust types read@fust_types','Fust types update@fust_types','Ingelogde gebruikers kunnen bufferstatus lezen@voorraad_buffer_state','Ingelogde gebruikers kunnen de eventlog lezen@voorraad_logistics_event_log','Ingelogde gebruikers kunnen fustboekingen lezen@order_fust_bookings','Ingelogde gebruikers lezen drempels@inventory_recompute_limits','Ingelogde gebruikers lezen opruimlogboek@structure_cleanup_log','Ingelogde gebruikers lezen opruimruns@floriday_queue_cleanup_runs','Ingelogden beheren traystickers@product_tray_stickers','Ingelogden lezen herberekenwachtrij@inventory_recompute_queue','Ingelogden lezen voorraadmeldingen@stock_integrity_alerts','Ingelogden markeren voorraadmeldingen als gezien@stock_integrity_alerts','Own queue rows select@floriday_continuous_stock_queue','Owner delete trade_item_drafts@trade_item_drafts','Owner insert trade_item_drafts@trade_item_drafts','Owner select trade_item_drafts@trade_item_drafts','Owner update trade_item_drafts@trade_item_drafts','Signed-in users read reconcile runs@floriday_reconcile_runs','Stock delete@trade_item_stock','Stock insert@trade_item_stock','Stock read@trade_item_stock','Stock update@trade_item_stock','Synchronisatieposities lezen@floriday_sync_cursors','Users can insert own publish attempts@voorraad_publish_attempts','Users can read own publish attempts@voorraad_publish_attempts','Users can read own stock mutations@stock_mutation_log','Users manage own import runs@stock_import_runs','Users manage own supply lines@trade_item_supply_lines','Users manage own trade item prices@trade_item_prices','Users manage their own publish jobs@voorraad_publish_jobs','Users manage their own publish steps@voorraad_publish_steps','Verwerkte orders lezen@floriday_sales_order_ingest','Voorraadschrijvers lezen overnameregels@floriday_takeover_items','Voorraadschrijvers lezen overnames@floriday_takeover_runs','authenticated can insert merge log@product_merge_log','authenticated can read merge log@product_merge_log','service role only@voorraad_media_upload_failures','product_packings_read@product_packings','product_packings_write@product_packings'];
9430
+ v_p text[] := ARRAY['Authenticated can add learnings@voorraad_publish_learnings','Authenticated can delete voorraad custom fields@voorraad_custom_fields','Authenticated can insert vbn required characteristics@floriday_vbn_required_characteristics','Authenticated can insert voorraad custom fields@voorraad_custom_fields','Authenticated can read continuous stock cache@floriday_continuous_stock_cache','Authenticated can read learnings@voorraad_publish_learnings','Authenticated can read vbn required characteristics@floriday_vbn_required_characteristics','Authenticated can read voorraad custom fields@voorraad_custom_fields','Authenticated can update learnings@voorraad_publish_learnings','Authenticated can update vbn required characteristics@floriday_vbn_required_characteristics','Authenticated can update voorraad custom fields@voorraad_custom_fields','Authenticated delete trade_item_warehouse_preferences@trade_item_warehouse_preferences','Authenticated insert trade_item_warehouse_preferences@trade_item_warehouse_preferences','Authenticated select trade_item_warehouse_preferences@trade_item_warehouse_preferences','Authenticated update trade_item_warehouse_preferences@trade_item_warehouse_preferences','Eigen momentopnamen lezen@inventory_stock_snapshots','Eigen voorraadinstellingen beheren@floriday_inventory_settings','Eigenaar leest importporties@stock_import_chunks','Eigenaar leest importregels@stock_import_rows','Fust mutations delete@fust_stock_mutations','Fust mutations insert@fust_stock_mutations','Fust mutations read@fust_stock_mutations','Fust mutations update@fust_stock_mutations','Fust types delete@fust_types','Fust types insert@fust_types','Fust types read@fust_types','Fust types update@fust_types','Ingelogde gebruikers kunnen bufferstatus lezen@voorraad_buffer_state','Ingelogde gebruikers kunnen de eventlog lezen@voorraad_logistics_event_log','Ingelogde gebruikers kunnen fustboekingen lezen@order_fust_bookings','Ingelogde gebruikers lezen drempels@inventory_recompute_limits','Ingelogd mag standaardstatus lezen@voorraad_defaults_state','Ingelogde gebruikers lezen opruimlogboek@structure_cleanup_log','Ingelogde gebruikers lezen opruimruns@floriday_queue_cleanup_runs','Ingelogden beheren traystickers@product_tray_stickers','Ingelogden lezen herberekenwachtrij@inventory_recompute_queue','Ingelogden lezen voorraadmeldingen@stock_integrity_alerts','Ingelogden markeren voorraadmeldingen als gezien@stock_integrity_alerts','Own queue rows select@floriday_continuous_stock_queue','Owner delete trade_item_drafts@trade_item_drafts','Owner insert trade_item_drafts@trade_item_drafts','Owner select trade_item_drafts@trade_item_drafts','Owner update trade_item_drafts@trade_item_drafts','Signed-in users read reconcile runs@floriday_reconcile_runs','Stock delete@trade_item_stock','Stock insert@trade_item_stock','Stock read@trade_item_stock','Stock update@trade_item_stock','Synchronisatieposities lezen@floriday_sync_cursors','Users can insert own publish attempts@voorraad_publish_attempts','Users can read own publish attempts@voorraad_publish_attempts','Users can read own stock mutations@stock_mutation_log','Users manage own import runs@stock_import_runs','Users manage own supply lines@trade_item_supply_lines','Users manage own trade item prices@trade_item_prices','Users manage their own publish jobs@voorraad_publish_jobs','Users manage their own publish steps@voorraad_publish_steps','Verwerkte orders lezen@floriday_sales_order_ingest','Voorraadschrijvers lezen overnameregels@floriday_takeover_items','Voorraadschrijvers lezen overnames@floriday_takeover_runs','authenticated can insert merge log@product_merge_log','authenticated can read merge log@product_merge_log','service role only@voorraad_media_upload_failures','product_packings_read@product_packings','product_packings_write@product_packings'];
9307
9431
  v_open text[] := ARRAY['voorraad_is_server','voorraad_vereis'];
9308
9432
  v_func jsonb; v_trig jsonb; v_pol jsonb;
9309
9433
  BEGIN
@@ -9329,7 +9453,7 @@ BEGIN
9329
9453
  SELECT jsonb_agg(jsonb_build_object('policy', split_part(t, '@', 1), 'tabel', split_part(t, '@', 2),
9330
9454
  'aanwezig', EXISTS (SELECT 1 FROM pg_policies x WHERE x.schemaname = 'public' AND x.policyname = split_part(t, '@', 1)
9331
9455
  AND x.tablename = split_part(t, '@', 2))) ORDER BY t) INTO v_pol FROM unnest(v_p) t;
9332
- RETURN jsonb_build_object('dubbele_voorraadregels', public.voorraad_dubbele_voorraadregels(), 'gateway_routes', public.voorraad_gateway_routes_check(),
9456
+ RETURN jsonb_build_object('standaardgegevens', public.voorraad_defaults_check(), 'dubbele_voorraadregels', public.voorraad_dubbele_voorraadregels(), 'gateway_routes', public.voorraad_gateway_routes_check(),
9333
9457
  'samenvatting', jsonb_build_object(
9334
9458
  'functies', jsonb_array_length(v_func),
9335
9459
  'functies_ontbrekend', (SELECT count(*) FROM jsonb_array_elements(v_func) e WHERE NOT (e->>'aanwezig')::boolean),
@@ -9367,12 +9491,12 @@ GRANT EXECUTE ON FUNCTION voorraad_is_server() TO service_role;
9367
9491
  CREATE OR REPLACE FUNCTION public.voorraad_load_carriers()
9368
9492
  RETURNS TABLE(code text, naam text, volgorde integer)
9369
9493
  LANGUAGE plpgsql
9370
- STABLE
9494
+ STABLE SECURITY DEFINER
9371
9495
  SET search_path TO 'public'
9372
9496
  AS $function$
9373
9497
  BEGIN
9374
9498
  PERFORM public.voorraad_vereis('ingelogd', 'voorraad_load_carriers');
9375
- RETURN QUERY SELECT t.code, t.naam, t.volgorde FROM public.voorraad_load_carrier_types t ORDER BY t.volgorde, t.code;
9499
+ RETURN QUERY SELECT t.code, t.naam, t.volgorde FROM public.voorraad_load_carrier_types t WHERE t.actief ORDER BY t.volgorde, t.code;
9376
9500
  END $function$
9377
9501
  ;
9378
9502
  REVOKE ALL ON FUNCTION voorraad_load_carriers() FROM PUBLIC;
@@ -10035,6 +10159,7 @@ DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'trade_i
10035
10159
  DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'voorraad_buffer_state_pkey' AND conrelid = 'public.voorraad_buffer_state'::regclass) THEN ALTER TABLE public.voorraad_buffer_state ADD CONSTRAINT voorraad_buffer_state_pkey PRIMARY KEY (buffer_id); END IF; END $c$;
10036
10160
  DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'voorraad_correcties_pkey' AND conrelid = 'public.voorraad_correcties'::regclass) THEN ALTER TABLE public.voorraad_correcties ADD CONSTRAINT voorraad_correcties_pkey PRIMARY KEY (id); END IF; END $c$;
10037
10161
  DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'voorraad_custom_fields_pkey' AND conrelid = 'public.voorraad_custom_fields'::regclass) THEN ALTER TABLE public.voorraad_custom_fields ADD CONSTRAINT voorraad_custom_fields_pkey PRIMARY KEY (id); END IF; END $c$;
10162
+ DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'voorraad_defaults_state_pkey' AND conrelid = 'public.voorraad_defaults_state'::regclass) THEN ALTER TABLE public.voorraad_defaults_state ADD CONSTRAINT voorraad_defaults_state_pkey PRIMARY KEY (id); END IF; END $c$;
10038
10163
  DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'voorraad_load_carrier_types_pkey' AND conrelid = 'public.voorraad_load_carrier_types'::regclass) THEN ALTER TABLE public.voorraad_load_carrier_types ADD CONSTRAINT voorraad_load_carrier_types_pkey PRIMARY KEY (code); END IF; END $c$;
10039
10164
  DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'voorraad_local_context_pkey' AND conrelid = 'public.voorraad_local_context'::regclass) THEN ALTER TABLE public.voorraad_local_context ADD CONSTRAINT voorraad_local_context_pkey PRIMARY KEY (id); END IF; END $c$;
10040
10165
  DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'voorraad_logistics_event_log_pkey' AND conrelid = 'public.voorraad_logistics_event_log'::regclass) THEN ALTER TABLE public.voorraad_logistics_event_log ADD CONSTRAINT voorraad_logistics_event_log_pkey PRIMARY KEY (event_id); END IF; END $c$;
@@ -10101,6 +10226,8 @@ ALTER TABLE public.stock_mutation_log DROP CONSTRAINT IF EXISTS stock_mutation_l
10101
10226
  ALTER TABLE public.stock_mutation_log ADD CONSTRAINT stock_mutation_log_mutation_type_check CHECK ((mutation_type = ANY (ARRAY['reservation'::text, 'reservation_release'::text, 'consumption'::text, 'stock_check'::text, 'reservation_skipped'::text, 'consumption_skipped'::text, 'consumption_blocked'::text, 'production_consume'::text, 'production_output'::text, 'production_reverse'::text, 'manual_correction'::text, 'order_sync'::text, 'import'::text, 'production'::text, 'stock_update'::text, 'reservation_recompute'::text, 'unknown'::text, 'consumption_done'::text, 'new_article'::text, 'manual_writeoff'::text])));
10102
10227
  ALTER TABLE public.trade_item_drafts DROP CONSTRAINT IF EXISTS trade_item_drafts_link_status_chk;
10103
10228
  ALTER TABLE public.trade_item_drafts ADD CONSTRAINT trade_item_drafts_link_status_chk CHECK ((floriday_link_status = ANY (ARRAY['unlinked'::text, 'linked'::text, 'waiting_for_data'::text, 'ready_to_publish'::text, 'publish_failed'::text, 'ambiguous_match'::text, 'published'::text])));
10229
+ ALTER TABLE public.voorraad_defaults_state DROP CONSTRAINT IF EXISTS voorraad_defaults_state_id_check;
10230
+ ALTER TABLE public.voorraad_defaults_state ADD CONSTRAINT voorraad_defaults_state_id_check CHECK (id);
10104
10231
  ALTER TABLE public.voorraad_local_context DROP CONSTRAINT IF EXISTS voorraad_local_context_singleton_check;
10105
10232
  ALTER TABLE public.voorraad_local_context ADD CONSTRAINT voorraad_local_context_singleton_check CHECK (singleton);
10106
10233
  DO $g$ BEGIN IF to_regclass('public.products') IS NULL THEN RAISE NOTICE 'Voorraad: products (core) ontbreekt, controles overgeslagen; draai de schema-update opnieuw na die module'; ELSE EXECUTE $q$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'floriday_inventory_settings_product_id_fkey' AND conrelid = 'public.floriday_inventory_settings'::regclass) THEN ALTER TABLE public.floriday_inventory_settings ADD CONSTRAINT floriday_inventory_settings_product_id_fkey FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE CASCADE; END IF; END $c$$q$; END IF; END $g$;
@@ -10291,6 +10418,10 @@ ALTER TABLE public.voorraad_custom_fields ENABLE ROW LEVEL SECURITY;
10291
10418
  REVOKE ALL ON public.voorraad_custom_fields FROM anon;
10292
10419
  GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON public.voorraad_custom_fields TO authenticated;
10293
10420
  GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON public.voorraad_custom_fields TO service_role;
10421
+ ALTER TABLE public.voorraad_defaults_state ENABLE ROW LEVEL SECURITY;
10422
+ REVOKE ALL ON public.voorraad_defaults_state FROM anon;
10423
+ GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON public.voorraad_defaults_state TO authenticated;
10424
+ GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON public.voorraad_defaults_state TO service_role;
10294
10425
  ALTER TABLE public.voorraad_load_carrier_types ENABLE ROW LEVEL SECURITY;
10295
10426
  REVOKE ALL ON public.voorraad_load_carrier_types FROM anon;
10296
10427
  GRANT DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON public.voorraad_load_carrier_types TO authenticated;
@@ -10442,6 +10573,8 @@ DROP POLICY IF EXISTS "Authenticated can read voorraad custom fields" ON public.
10442
10573
  CREATE POLICY "Authenticated can read voorraad custom fields" ON public.voorraad_custom_fields AS PERMISSIVE FOR SELECT TO authenticated USING (true);
10443
10574
  DROP POLICY IF EXISTS "Authenticated can update voorraad custom fields" ON public.voorraad_custom_fields;
10444
10575
  CREATE POLICY "Authenticated can update voorraad custom fields" ON public.voorraad_custom_fields AS PERMISSIVE FOR UPDATE TO authenticated USING (true) WITH CHECK (true);
10576
+ DROP POLICY IF EXISTS "Ingelogd mag standaardstatus lezen" ON public.voorraad_defaults_state;
10577
+ CREATE POLICY "Ingelogd mag standaardstatus lezen" ON public.voorraad_defaults_state AS PERMISSIVE FOR SELECT TO authenticated USING (true);
10445
10578
  DROP POLICY IF EXISTS "Ingelogd mag ladingdragers lezen" ON public.voorraad_load_carrier_types;
10446
10579
  CREATE POLICY "Ingelogd mag ladingdragers lezen" ON public.voorraad_load_carrier_types AS PERMISSIVE FOR SELECT TO authenticated USING (true);
10447
10580
  DROP POLICY IF EXISTS "Lokale context lezen" ON public.voorraad_local_context;
@@ -10604,6 +10737,8 @@ CREATE TRIGGER update_voorraad_publish_learnings_updated_at BEFORE UPDATE ON pub
10604
10737
  DROP TRIGGER IF EXISTS update_voorraad_publish_steps_updated_at ON public.voorraad_publish_steps;
10605
10738
  CREATE TRIGGER update_voorraad_publish_steps_updated_at BEFORE UPDATE ON public.voorraad_publish_steps FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
10606
10739
 
10740
+ -- standaardgegevens (systeemgegevens bijwerken, klantinstellingen alleen als ze ontbreken)
10741
+ SELECT public.voorraad_ensure_defaults();
10607
10742
  -- vaste taken
10608
10743
  DO $cron$
10609
10744
  BEGIN