@flowselections/floriday-afhandeling-module 1.0.105 → 1.0.107
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/integrations/supabase/previewAuthStorage.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/previewAuthStorage.js +2 -1
- package/dist-lib/integrations/supabase/types.d.ts +2086 -0
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/schema/90_afhandeling.sql +51 -19
package/package.json
CHANGED
|
@@ -569,6 +569,36 @@ $function$
|
|
|
569
569
|
|
|
570
570
|
;
|
|
571
571
|
|
|
572
|
+
CREATE OR REPLACE FUNCTION public.afh_order_signup_uitgesloten(p_order_id uuid)
|
|
573
|
+
RETURNS boolean
|
|
574
|
+
LANGUAGE plpgsql
|
|
575
|
+
STABLE SECURITY DEFINER
|
|
576
|
+
SET search_path TO 'public', 'pg_temp'
|
|
577
|
+
AS $function$
|
|
578
|
+
DECLARE v_cf jsonb; v_dd text; v_dag date; v_bf boolean;
|
|
579
|
+
BEGIN
|
|
580
|
+
PERFORM public.afh_assert_intern();
|
|
581
|
+
SELECT o.custom_fields, o.delivery_date INTO v_cf, v_dd FROM public.orders o WHERE o.id = p_order_id;
|
|
582
|
+
IF NOT FOUND THEN RETURN true; END IF;
|
|
583
|
+
-- Ingehaalde order: controle van de Engine, anders dezelfde regel zelf.
|
|
584
|
+
IF to_regprocedure('public.logistics_order_is_backfill(uuid)') IS NOT NULL THEN
|
|
585
|
+
EXECUTE 'SELECT public.logistics_order_is_backfill($1)' INTO v_bf USING p_order_id;
|
|
586
|
+
ELSE
|
|
587
|
+
v_bf := CASE
|
|
588
|
+
WHEN jsonb_typeof(v_cf) IS DISTINCT FROM 'object' OR NOT (v_cf ? 'backfill') THEN false
|
|
589
|
+
WHEN jsonb_typeof(v_cf->'backfill') = 'null' THEN false
|
|
590
|
+
WHEN jsonb_typeof(v_cf->'backfill') = 'boolean' THEN (v_cf->>'backfill')::boolean
|
|
591
|
+
ELSE lower(btrim(v_cf->>'backfill')) NOT IN ('', 'false', '0', 'nee', 'no') END;
|
|
592
|
+
END IF;
|
|
593
|
+
IF coalesce(v_bf, false) THEN RETURN true; END IF;
|
|
594
|
+
-- Leverdag in het verleden (Europe/Amsterdam); onbekende leverdag = niet aanmelden.
|
|
595
|
+
v_dag := public.logistics_order_date(v_dd);
|
|
596
|
+
RETURN v_dag IS NULL OR v_dag < (now() AT TIME ZONE 'Europe/Amsterdam')::date;
|
|
597
|
+
END;
|
|
598
|
+
$function$;
|
|
599
|
+
REVOKE ALL ON FUNCTION public.afh_order_signup_uitgesloten(uuid) FROM PUBLIC, anon, authenticated;
|
|
600
|
+
GRANT EXECUTE ON FUNCTION public.afh_order_signup_uitgesloten(uuid) TO service_role;
|
|
601
|
+
|
|
572
602
|
CREATE OR REPLACE FUNCTION public.afh_signup_groups_base(p_from date, p_to date, p_tz text)
|
|
573
603
|
RETURNS jsonb
|
|
574
604
|
LANGUAGE plpgsql
|
|
@@ -580,18 +610,18 @@ DECLARE
|
|
|
580
610
|
v_unassigned jsonb;
|
|
581
611
|
v_eng jsonb;
|
|
582
612
|
BEGIN
|
|
583
|
-
|
|
613
|
+
PERFORM public.afh_assert_intern();
|
|
584
614
|
IF NOT public.afh_orders_have_carrier_id() THEN
|
|
585
615
|
RETURN jsonb_build_object('groups', '[]'::jsonb, 'unassigned', '[]'::jsonb, 'reason', 'engine_te_oud');
|
|
586
616
|
END IF;
|
|
587
617
|
SELECT public.afh_signup_engine_moments(coalesce(array_agg(o.id), '{}'::uuid[])) INTO v_eng
|
|
588
618
|
FROM public.orders o
|
|
589
|
-
WHERE o.deleted_at IS NULL AND
|
|
619
|
+
WHERE o.deleted_at IS NULL AND public.logistics_order_date(o.delivery_date) BETWEEN p_from AND p_to;
|
|
590
620
|
|
|
591
621
|
WITH ob AS (
|
|
592
622
|
SELECT o.id, o.order_number,
|
|
593
623
|
coalesce(nullif(trim(c.commercial_name),''), nullif(trim(c.company_name),''), o.customer_name) AS customer_name,
|
|
594
|
-
o.delivery_date
|
|
624
|
+
public.logistics_order_date(o.delivery_date) AS delivery_date, o.created_at,
|
|
595
625
|
nullif(to_jsonb(o)->>'carrier_id', '')::uuid AS order_carrier_id,
|
|
596
626
|
(coalesce(o.custom_fields->>'floriday_sales_order_id', o.custom_fields->>'salesOrderId') IS NOT NULL) AS is_floriday,
|
|
597
627
|
public.afh_normalize_country(coalesce(dl.country, c.country)) AS country_code,
|
|
@@ -603,8 +633,8 @@ BEGIN
|
|
|
603
633
|
LEFT JOIN public.customers c ON c.id = o.customer_id
|
|
604
634
|
LEFT JOIN public.customer_delivery_locations dl ON dl.id::text = o.custom_fields->>'delivery_location'
|
|
605
635
|
WHERE o.deleted_at IS NULL
|
|
606
|
-
AND o.delivery_date
|
|
607
|
-
AND o.
|
|
636
|
+
AND public.logistics_order_date(o.delivery_date) BETWEEN p_from AND p_to
|
|
637
|
+
AND NOT public.afh_order_signup_uitgesloten(o.id)
|
|
608
638
|
AND lower(coalesce(o.status,'')) NOT IN ('geannuleerd','cancelled','canceled','annulled')
|
|
609
639
|
), cand AS (
|
|
610
640
|
SELECT ob.*, ca.id AS carrier_id, ca.name AS carrier_name, ca.email AS carrier_email, ca.pickup_moments, 1 AS rn
|
|
@@ -690,17 +720,11 @@ BEGIN
|
|
|
690
720
|
INTO v_groups FROM g2;
|
|
691
721
|
|
|
692
722
|
WITH ob AS (
|
|
693
|
-
SELECT o.id, o.order_number, o.delivery_date
|
|
694
|
-
public.afh_normalize_country(coalesce(dl.country, c.country)) AS country_code,
|
|
695
|
-
public.afh_normalize_nl_province(dl.province) AS province_code,
|
|
696
|
-
public.afh_city_code(public.afh_normalize_country(coalesce(dl.country, c.country)), coalesce(dl.city, c.city)) AS city_code,
|
|
697
|
-
nullif(trim(dl.gln), '') AS gln,
|
|
723
|
+
SELECT o.id, o.order_number, public.logistics_order_date(o.delivery_date) AS delivery_date,
|
|
698
724
|
nullif(to_jsonb(o)->>'carrier_id', '')::uuid AS order_carrier_id
|
|
699
725
|
FROM public.orders o
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
WHERE o.deleted_at IS NULL AND o.delivery_date ~ '^\d{4}-\d{2}-\d{2}'
|
|
703
|
-
AND o.delivery_date::date BETWEEN p_from AND p_to
|
|
726
|
+
WHERE o.deleted_at IS NULL AND public.logistics_order_date(o.delivery_date) BETWEEN p_from AND p_to
|
|
727
|
+
AND NOT public.afh_order_signup_uitgesloten(o.id)
|
|
704
728
|
AND lower(coalesce(o.status,'')) NOT IN ('geannuleerd','cancelled','canceled','annulled')
|
|
705
729
|
)
|
|
706
730
|
SELECT coalesce(jsonb_agg(jsonb_build_object('orderId', ob.id, 'orderNumber', ob.order_number, 'deliveryDate', ob.delivery_date) ORDER BY ob.delivery_date, ob.order_number), '[]'::jsonb)
|
|
@@ -968,6 +992,7 @@ CREATE OR REPLACE FUNCTION public.afh_signup_send_group(g jsonb, p_tz text, p_co
|
|
|
968
992
|
SET search_path TO 'public', 'pg_temp'
|
|
969
993
|
AS $function$
|
|
970
994
|
BEGIN
|
|
995
|
+
PERFORM public.afh_assert_intern();
|
|
971
996
|
IF jsonb_array_length(coalesce(g->'pending_orders','[]'::jsonb)) > 0
|
|
972
997
|
AND g->>'wait_until' IS NOT NULL AND now() < (g->>'wait_until')::timestamptz THEN
|
|
973
998
|
RETURN jsonb_build_object('ok', true, 'code', 'waiting_for_carts', 'wait_until', g->'wait_until');
|
|
@@ -978,6 +1003,11 @@ BEGIN
|
|
|
978
1003
|
IF coalesce((g->>'order_count')::int, 0) = 0 AND jsonb_array_length(coalesce(g->'floriday_done_orders','[]'::jsonb)) = 0 THEN
|
|
979
1004
|
RETURN jsonb_build_object('ok', true, 'code', 'waiting_for_carts');
|
|
980
1005
|
END IF;
|
|
1006
|
+
-- Vangnet: een ingehaalde order of een order met leverdag in het verleden wordt nooit aangemeld.
|
|
1007
|
+
IF EXISTS (SELECT 1 FROM jsonb_array_elements(coalesce(g->'orders','[]'::jsonb)) e
|
|
1008
|
+
WHERE public.afh_order_signup_uitgesloten((e->>'orderId')::uuid)) THEN
|
|
1009
|
+
RETURN jsonb_build_object('ok', true, 'code', 'uitgesloten');
|
|
1010
|
+
END IF;
|
|
981
1011
|
RETURN public.afh_signup_send_group_base(g, p_tz, p_connection, p_purpose, p_source, p_user);
|
|
982
1012
|
END;
|
|
983
1013
|
$function$
|
|
@@ -1396,7 +1426,7 @@ BEGIN
|
|
|
1396
1426
|
-- Orders bij een vervoerder die niet wordt aangemeld (soort, archief)
|
|
1397
1427
|
SELECT public.afh_signup_engine_moments(coalesce(array_agg(o.id), '{}'::uuid[])) INTO v_eng
|
|
1398
1428
|
FROM public.orders o
|
|
1399
|
-
WHERE o.deleted_at IS NULL AND
|
|
1429
|
+
WHERE o.deleted_at IS NULL AND public.logistics_order_date(o.delivery_date) BETWEEN p_from AND p_to + 14;
|
|
1400
1430
|
v_rows := v_rows || coalesce((
|
|
1401
1431
|
SELECT jsonb_agg(jsonb_build_object(
|
|
1402
1432
|
'carrierId', ca.id, 'carrierName', ca.name,
|
|
@@ -1434,7 +1464,7 @@ BEGIN
|
|
|
1434
1464
|
-- Orders zonder Engine-kar met een vervoerder op de order die niet wordt aangemeld
|
|
1435
1465
|
v_rows := v_rows || coalesce((
|
|
1436
1466
|
SELECT jsonb_agg(jsonb_build_object(
|
|
1437
|
-
'carrierId', ca.id, 'carrierName', ca.name, 'pickupDate', o.delivery_date
|
|
1467
|
+
'carrierId', ca.id, 'carrierName', ca.name, 'pickupDate', public.logistics_order_date(o.delivery_date), 'pickupTime', NULL, 'signupDeadline', NULL,
|
|
1438
1468
|
'orders', jsonb_build_array(jsonb_build_object('orderId', o.id, 'orderNumber', o.order_number)),
|
|
1439
1469
|
'cartCount', NULL, 'status', 'uitgesloten',
|
|
1440
1470
|
'reden', CASE WHEN ca.archived_at IS NOT NULL THEN 'gearchiveerd'
|
|
@@ -1445,7 +1475,7 @@ BEGIN
|
|
|
1445
1475
|
'sentAt', NULL))
|
|
1446
1476
|
FROM public.orders o
|
|
1447
1477
|
JOIN public.carriers ca ON ca.id = nullif(to_jsonb(o)->>'carrier_id', '')::uuid
|
|
1448
|
-
WHERE o.deleted_at IS NULL AND
|
|
1478
|
+
WHERE o.deleted_at IS NULL AND public.logistics_order_date(o.delivery_date) BETWEEN p_from AND p_to
|
|
1449
1479
|
AND NOT (coalesce(v_eng, '{}'::jsonb) ? o.id::text)
|
|
1450
1480
|
AND lower(coalesce(o.status,'')) NOT IN ('geannuleerd','cancelled','canceled','annulled')
|
|
1451
1481
|
AND (ca.archived_at IS NOT NULL OR ca.carrier_kind IS DISTINCT FROM 'extern' OR nullif(trim(ca.email),'') IS NULL)), '[]'::jsonb);
|
|
@@ -1935,6 +1965,7 @@ BEGIN
|
|
|
1935
1965
|
('afh_set_signup_auto_send','ingelogd'),
|
|
1936
1966
|
('afh_signup_config','intern'),
|
|
1937
1967
|
('afh_signup_engine_moments','intern'),
|
|
1968
|
+
('afh_order_signup_uitgesloten','intern'),
|
|
1938
1969
|
('afh_signup_groups','intern'),
|
|
1939
1970
|
('afh_signup_groups_base','intern'),
|
|
1940
1971
|
('afh_signup_groups_floriday','intern'),
|
|
@@ -1975,8 +2006,8 @@ BEGIN
|
|
|
1975
2006
|
v_cfg := public.afh_signup_config();
|
|
1976
2007
|
v_tz := v_cfg->>'timezone';
|
|
1977
2008
|
v_lead := nullif(v_cfg->>'lead_minutes','')::int;
|
|
1978
|
-
SELECT min(o.delivery_date
|
|
1979
|
-
FROM public.orders o WHERE o.id = ANY(p_order_ids)
|
|
2009
|
+
SELECT min(public.logistics_order_date(o.delivery_date)), max(public.logistics_order_date(o.delivery_date)) INTO v_from, v_to
|
|
2010
|
+
FROM public.orders o WHERE o.id = ANY(p_order_ids);
|
|
1980
2011
|
IF v_has_col AND v_tz IS NOT NULL AND v_lead IS NOT NULL AND v_from IS NOT NULL THEN
|
|
1981
2012
|
v_groups := coalesce(public.afh_signup_groups(v_from - 1, v_to + 1, v_tz)->'groups', '[]'::jsonb);
|
|
1982
2013
|
END IF;
|
|
@@ -2032,6 +2063,7 @@ BEGIN
|
|
|
2032
2063
|
('afh_signup_config','intern'),
|
|
2033
2064
|
('afh_signup_sender','intern'),
|
|
2034
2065
|
('afh_signup_engine_moments','intern'),
|
|
2066
|
+
('afh_order_signup_uitgesloten','intern'),
|
|
2035
2067
|
('afh_signup_moment_for_orders','ingelogd'),
|
|
2036
2068
|
('afh_signup_find_group','intern'),
|
|
2037
2069
|
('afh_signup_groups','intern'),
|