@flowselections/logistiek-engine 1.0.209 → 1.0.212

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.
@@ -36589,3 +36589,133 @@ RETURNS TABLE(punt text, ok boolean, uitleg text) LANGUAGE sql STABLE SECURITY D
36589
36589
  AND position('logistics_acc_guard' IN pg_get_functiondef('public.logistics_product_hoofdverpakking(uuid)'::regprocedure)) > 0, 'Nieuwe functies controleren de aanroeper'
36590
36590
  $$;
36591
36591
  GRANT EXECUTE ON FUNCTION public.logistics_install_check_208() TO authenticated, service_role;
36592
+ -- ============================================================================
36593
+ -- 1.0.210 — tolerantie 1 % bij "maximaal per laag", hoogte uit Floricode = waarschuwing,
36594
+ -- karregel van een verouderde kar.
36595
+ -- ============================================================================
36596
+
36597
+ -- Eén benoemde regel; TS-tegenhanger: LAAG_TOLERANTIE in src/lib/dimensionPlanner.ts.
36598
+ CREATE OR REPLACE FUNCTION public.logistics_laag_tolerantie()
36599
+ RETURNS numeric LANGUAGE sql IMMUTABLE SET search_path TO 'public' AS $$ SELECT 0.01::numeric $$;
36600
+ GRANT EXECUTE ON FUNCTION public.logistics_laag_tolerantie() TO authenticated, service_role;
36601
+
36602
+ -- Strikte LayerSpace (zonder tolerantie): kopie van het oorspronkelijke algoritme.
36603
+ DO $do$
36604
+ DECLARE d text;
36605
+ BEGIN
36606
+ IF to_regprocedure('public.logistics_max_fusten_per_laag_strikt(numeric,numeric,numeric,numeric)') IS NOT NULL THEN RETURN; END IF;
36607
+ d := pg_get_functiondef('public.logistics_max_fusten_per_laag(numeric,numeric,numeric,numeric)'::regprocedure);
36608
+ IF position('logistics_laag_tolerantie' IN d) > 0 THEN RAISE EXCEPTION 'max_fusten_per_laag heeft al tolerantie maar strikt ontbreekt'; END IF;
36609
+ EXECUTE replace(d, 'public.logistics_max_fusten_per_laag(', 'public.logistics_max_fusten_per_laag_strikt(');
36610
+ END $do$;
36611
+ GRANT EXECUTE ON FUNCTION public.logistics_max_fusten_per_laag_strikt(numeric, numeric, numeric, numeric) TO authenticated, service_role;
36612
+
36613
+ -- Bestaande naam = met tolerantie; alle bestaande aanroepers krijgen daarmee dezelfde regel.
36614
+ CREATE OR REPLACE FUNCTION public.logistics_max_fusten_per_laag(p_ll numeric, p_lw numeric, p_fl numeric, p_fw numeric)
36615
+ RETURNS integer LANGUAGE sql IMMUTABLE SET search_path TO 'public' AS $$
36616
+ SELECT public.logistics_max_fusten_per_laag_strikt(p_ll * (1 + public.logistics_laag_tolerantie()),
36617
+ p_lw * (1 + public.logistics_laag_tolerantie()), p_fl, p_fw)
36618
+ $$;
36619
+
36620
+ -- Tekst als de tolerantie nodig was, anders NULL.
36621
+ CREATE OR REPLACE FUNCTION public.logistics_laag_tolerantie_tekst(p_ll numeric, p_lw numeric, p_fl numeric, p_fw numeric, p_n numeric)
36622
+ RETURNS text LANGUAGE plpgsql IMMUTABLE SET search_path TO 'public' AS $$
36623
+ DECLARE lo numeric := 0; hi numeric := public.logistics_laag_tolerantie(); mid numeric; k int;
36624
+ BEGIN
36625
+ IF coalesce(p_n,0) <= 0 OR coalesce(p_ll,0) <= 0 OR coalesce(p_lw,0) <= 0 OR coalesce(p_fl,0) <= 0 OR coalesce(p_fw,0) <= 0 THEN RETURN NULL; END IF;
36626
+ IF coalesce(public.logistics_max_fusten_per_laag_strikt(p_ll, p_lw, p_fl, p_fw), 0) >= p_n THEN RETURN NULL; END IF;
36627
+ IF coalesce(public.logistics_max_fusten_per_laag(p_ll, p_lw, p_fl, p_fw), 0) < p_n THEN RETURN NULL; END IF;
36628
+ FOR k IN 1..25 LOOP
36629
+ mid := (lo + hi) / 2;
36630
+ IF coalesce(public.logistics_max_fusten_per_laag_strikt(p_ll * (1 + mid), p_lw * (1 + mid), p_fl, p_fw), 0) >= p_n THEN hi := mid; ELSE lo := mid; END IF;
36631
+ END LOOP;
36632
+ RETURN format('%s per laag past met %s mm overstek (binnen %s %% tolerantie)', trim_scale(p_n),
36633
+ greatest(1, ceil(hi * p_lw * 10 - 1e-6))::int, trim_scale(round(public.logistics_laag_tolerantie() * 100, 2)));
36634
+ END $$;
36635
+ GRANT EXECUTE ON FUNCTION public.logistics_laag_tolerantie_tekst(numeric, numeric, numeric, numeric, numeric) TO authenticated, service_role;
36636
+
36637
+ -- Oordeel per regel: tolerantietekst en hoogte uit Floricode = waarschuwing.
36638
+ DO $do$
36639
+ DECLARE d text; n text;
36640
+ BEGIN
36641
+ d := pg_get_functiondef('public.logistics_product_oordeel_belading(jsonb)'::regprocedure);
36642
+ IF position('logistics_laag_tolerantie_tekst' IN d) > 0 THEN RETURN; END IF;
36643
+ n := replace(d,
36644
+ $a$ ls := public.logistics_max_fusten_per_laag(c.layer_length_cm, c.layer_width_cm, fl, fb);$a$,
36645
+ $a$ ls := public.logistics_max_fusten_per_laag(c.layer_length_cm, c.layer_width_cm, fl, fb);
36646
+ IF public.logistics_laag_tolerantie_tekst(c.layer_length_cm, c.layer_width_cm, fl, fb, cpl) IS NOT NULL THEN
36647
+ waar := waar || public.logistics_laag_tolerantie_tekst(c.layer_length_cm, c.layer_width_cm, fl, fb, cpl);
36648
+ END IF;$a$);
36649
+ n := replace(n,
36650
+ $a$ IF lpc * laag > c.max_height_cm + 1e-9 THEN
36651
+ blok := blok || format($a$,
36652
+ $a$ IF lpc * laag > c.max_height_cm + 1e-9 AND ph >= fh AND coalesce(gj->'velden'->'plant_height_cm'->>'bron', '') ILIKE 'floricode%' THEN
36653
+ waar := waar || format('planthoogte volgens Floricode; controleer: %s lagen × %s cm = %s cm, hoger dan %s (%s cm)',
36654
+ lpc, trim_scale(round(laag,1)), trim_scale(round(lpc*laag,1)), naam, trim_scale(round(c.max_height_cm::numeric,1)));
36655
+ ELSIF lpc * laag > c.max_height_cm + 1e-9 THEN
36656
+ blok := blok || format($a$);
36657
+ IF n = d OR position('logistics_laag_tolerantie_tekst' IN n) = 0 OR position('volgens Floricode' IN n) = 0 THEN
36658
+ RAISE EXCEPTION 'patroon oordeel_belading niet gevonden';
36659
+ END IF;
36660
+ EXECUTE n;
36661
+ END $do$;
36662
+
36663
+ DO $do$
36664
+ DECLARE d text; n text;
36665
+ BEGIN
36666
+ d := pg_get_functiondef('public.logistics_product_oordeel_many(uuid[])'::regprocedure);
36667
+ IF position('logistics_laag_tolerantie_tekst' IN d) > 0 THEN RETURN; END IF;
36668
+ n := replace(d,
36669
+ $a$ IF ls IS NOT NULL AND cpl > ls THEN$a$,
36670
+ $a$ IF public.logistics_laag_tolerantie_tekst(c.layer_length_cm, c.layer_width_cm,
36671
+ nullif(r.velden->'fust_length_mm'->>'waarde', '')::numeric / 10.0, nullif(r.velden->'fust_width_mm'->>'waarde', '')::numeric / 10.0, cpl) IS NOT NULL THEN
36672
+ waar := waar || public.logistics_laag_tolerantie_tekst(c.layer_length_cm, c.layer_width_cm,
36673
+ nullif(r.velden->'fust_length_mm'->>'waarde', '')::numeric / 10.0, nullif(r.velden->'fust_width_mm'->>'waarde', '')::numeric / 10.0, cpl);
36674
+ END IF;
36675
+ IF ls IS NOT NULL AND cpl > ls THEN$a$);
36676
+ n := replace(n,
36677
+ $a$ IF lpc * laag > c.max_height_cm + 1e-9 THEN
36678
+ blok := blok || format($a$,
36679
+ $a$ IF lpc * laag > c.max_height_cm + 1e-9 AND ph >= fh AND coalesce(r.velden->'plant_height_cm'->>'bron', '') ILIKE 'floricode%' THEN
36680
+ waar := waar || format('planthoogte volgens Floricode; controleer: %s lagen × %s cm = %s cm, hoger dan %s (%s cm)',
36681
+ lpc, trim_scale(round(laag,1)), trim_scale(round(lpc*laag,1)), naam, trim_scale(round(c.max_height_cm::numeric,1)));
36682
+ ELSIF lpc * laag > c.max_height_cm + 1e-9 THEN
36683
+ blok := blok || format($a$);
36684
+ IF n = d OR position('logistics_laag_tolerantie_tekst' IN n) = 0 OR position('volgens Floricode' IN n) = 0 THEN
36685
+ RAISE EXCEPTION 'patroon oordeel_many niet gevonden';
36686
+ END IF;
36687
+ EXECUTE n;
36688
+ END $do$;
36689
+
36690
+ -- Karregel: verouderde kar (regels in quarantaine) → "verouderd: opnieuw indelen", zonder lagen en %.
36691
+ DO $do$
36692
+ DECLARE d text; n text;
36693
+ BEGIN
36694
+ d := pg_get_functiondef('public.logistics_cart_platen_verrijk(jsonb)'::regprocedure);
36695
+ IF position('verouderd: opnieuw indelen' IN d) > 0 THEN RETURN; END IF;
36696
+ n := replace(d,
36697
+ $a$ 'karTekst', public.logistics_kar_tekst(c->>'carrierType', v_l, v_pct))$a$,
36698
+ $a$ 'karTekst', CASE WHEN v_id IS NOT NULL AND public.logistics_cart_verouderd_core(v_id) IS NOT NULL
36699
+ THEN 'verouderd: opnieuw indelen' ELSE public.logistics_kar_tekst(c->>'carrierType', v_l, v_pct) END)$a$);
36700
+ IF n = d THEN RAISE EXCEPTION 'patroon karTekst niet gevonden'; END IF;
36701
+ EXECUTE n;
36702
+ END $do$;
36703
+
36704
+ CREATE OR REPLACE FUNCTION public.logistics_install_check_210()
36705
+ RETURNS TABLE(punt text, ok boolean, uitleg text) LANGUAGE sql STABLE SECURITY DEFINER SET search_path TO 'public' AS $$
36706
+ SELECT 'laagtolerantie', public.logistics_laag_tolerantie() = 0.01
36707
+ AND position('logistics_laag_tolerantie' IN pg_get_functiondef('public.logistics_max_fusten_per_laag(numeric,numeric,numeric,numeric)'::regprocedure)) > 0,
36708
+ 'Maximaal per laag met 1 % tolerantie op de laagmaten'
36709
+ UNION ALL SELECT '412 op DC', public.logistics_max_fusten_per_laag(135, 56, 56.2, 25.3) >= 5, '412 Normtray: 5 per laag op Deense container'
36710
+ UNION ALL SELECT 'tolerantietekst in oordeel',
36711
+ position('logistics_laag_tolerantie_tekst' IN pg_get_functiondef('public.logistics_product_oordeel_belading(jsonb)'::regprocedure)) > 0
36712
+ AND position('logistics_laag_tolerantie_tekst' IN pg_get_functiondef('public.logistics_product_oordeel_many(uuid[])'::regprocedure)) > 0,
36713
+ 'Oordeel meldt wanneer de tolerantie nodig was'
36714
+ UNION ALL SELECT 'hoogte Floricode = waarschuwing',
36715
+ position('volgens Floricode' IN pg_get_functiondef('public.logistics_product_oordeel_belading(jsonb)'::regprocedure)) > 0
36716
+ AND position('volgens Floricode' IN pg_get_functiondef('public.logistics_product_oordeel_many(uuid[])'::regprocedure)) > 0,
36717
+ 'Planthoogte alleen uit Floricode blokkeert niet'
36718
+ UNION ALL SELECT 'karregel verouderd', position('verouderd: opnieuw indelen' IN pg_get_functiondef('public.logistics_cart_platen_verrijk(jsonb)'::regprocedure)) > 0,
36719
+ 'Verouderde kar toont geen lagen en %'
36720
+ $$;
36721
+ GRANT EXECUTE ON FUNCTION public.logistics_install_check_210() TO authenticated, service_role;
@@ -26298,6 +26298,72 @@ export type Database = {
26298
26298
  }
26299
26299
  ];
26300
26300
  };
26301
+ twinfield_invoice_mail_queue: {
26302
+ Row: {
26303
+ attempts: number;
26304
+ cc_addresses: string[];
26305
+ connection_id: string;
26306
+ created_at: string;
26307
+ group_key: string;
26308
+ id: string;
26309
+ invoice_number: string;
26310
+ last_error: string | null;
26311
+ mailbox_connection_id: string | null;
26312
+ next_attempt_at: string;
26313
+ purpose: string;
26314
+ sent_at: string | null;
26315
+ status: string;
26316
+ subject: string;
26317
+ test_mode: boolean;
26318
+ text_body: string;
26319
+ to_addresses: string[];
26320
+ updated_at: string;
26321
+ user_id: string;
26322
+ };
26323
+ Insert: {
26324
+ attempts?: number;
26325
+ cc_addresses?: string[];
26326
+ connection_id: string;
26327
+ created_at?: string;
26328
+ group_key: string;
26329
+ id?: string;
26330
+ invoice_number: string;
26331
+ last_error?: string | null;
26332
+ mailbox_connection_id?: string | null;
26333
+ next_attempt_at?: string;
26334
+ purpose: string;
26335
+ sent_at?: string | null;
26336
+ status?: string;
26337
+ subject: string;
26338
+ test_mode?: boolean;
26339
+ text_body: string;
26340
+ to_addresses: string[];
26341
+ updated_at?: string;
26342
+ user_id: string;
26343
+ };
26344
+ Update: {
26345
+ attempts?: number;
26346
+ cc_addresses?: string[];
26347
+ connection_id?: string;
26348
+ created_at?: string;
26349
+ group_key?: string;
26350
+ id?: string;
26351
+ invoice_number?: string;
26352
+ last_error?: string | null;
26353
+ mailbox_connection_id?: string | null;
26354
+ next_attempt_at?: string;
26355
+ purpose?: string;
26356
+ sent_at?: string | null;
26357
+ status?: string;
26358
+ subject?: string;
26359
+ test_mode?: boolean;
26360
+ text_body?: string;
26361
+ to_addresses?: string[];
26362
+ updated_at?: string;
26363
+ user_id?: string;
26364
+ };
26365
+ Relationships: [];
26366
+ };
26301
26367
  twinfield_invoice_pdf_cache: {
26302
26368
  Row: {
26303
26369
  connection_id: string;
@@ -33090,6 +33156,26 @@ export type Database = {
33090
33156
  trade_item_id: string;
33091
33157
  }[];
33092
33158
  };
33159
+ floriday_packing_blocked_items_v2: {
33160
+ Args: {
33161
+ p_connection_id: string;
33162
+ };
33163
+ Returns: {
33164
+ article_code: string;
33165
+ article_name: string;
33166
+ blocked_attempts: number;
33167
+ blocked_by: string;
33168
+ details: string;
33169
+ last_blocked_at: string;
33170
+ mismatch_id: string;
33171
+ reason: string;
33172
+ since: string;
33173
+ source_kind: string;
33174
+ source_paths: string[];
33175
+ source_ref: string;
33176
+ trade_item_id: string;
33177
+ }[];
33178
+ };
33093
33179
  floriday_publish_horizon_weeks: {
33094
33180
  Args: never;
33095
33181
  Returns: number;
@@ -36191,6 +36277,14 @@ export type Database = {
36191
36277
  uitleg: string;
36192
36278
  }[];
36193
36279
  };
36280
+ logistics_install_check_210: {
36281
+ Args: never;
36282
+ Returns: {
36283
+ ok: boolean;
36284
+ punt: string;
36285
+ uitleg: string;
36286
+ }[];
36287
+ };
36194
36288
  logistics_is_beheer: {
36195
36289
  Args: never;
36196
36290
  Returns: boolean;
@@ -36281,6 +36375,20 @@ export type Database = {
36281
36375
  Args: never;
36282
36376
  Returns: Json;
36283
36377
  };
36378
+ logistics_laag_tolerantie: {
36379
+ Args: never;
36380
+ Returns: number;
36381
+ };
36382
+ logistics_laag_tolerantie_tekst: {
36383
+ Args: {
36384
+ p_fl: number;
36385
+ p_fw: number;
36386
+ p_ll: number;
36387
+ p_lw: number;
36388
+ p_n: number;
36389
+ };
36390
+ Returns: string;
36391
+ };
36284
36392
  logistics_ladingdrager_referentie: {
36285
36393
  Args: never;
36286
36394
  Returns: {
@@ -36378,6 +36486,15 @@ export type Database = {
36378
36486
  };
36379
36487
  Returns: number;
36380
36488
  };
36489
+ logistics_max_fusten_per_laag_strikt: {
36490
+ Args: {
36491
+ p_fl: number;
36492
+ p_fw: number;
36493
+ p_ll: number;
36494
+ p_lw: number;
36495
+ };
36496
+ Returns: number;
36497
+ };
36381
36498
  logistics_merge_decision: {
36382
36499
  Args: {
36383
36500
  p_lines: Json;