@flowselections/floriday-klanten-module 1.0.77 → 1.0.80
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/DeliveryLocationsTab.d.ts.map +1 -1
- package/dist-lib/components/klanten/DeliveryLocationsTab.js +34 -5
- package/dist-lib/components/klanten/KlantenOverzicht.js +2 -2
- package/dist-lib/components/klanten/LocationGlns.d.ts +20 -0
- package/dist-lib/components/klanten/LocationGlns.d.ts.map +1 -0
- package/dist-lib/components/klanten/LocationGlns.js +84 -0
- package/dist-lib/components/settings/ChannelsCard.d.ts +2 -0
- package/dist-lib/components/settings/ChannelsCard.d.ts.map +1 -0
- package/dist-lib/components/settings/ChannelsCard.js +35 -0
- package/dist-lib/index.d.ts.map +1 -1
- package/dist-lib/index.js +2 -0
- package/dist-lib/integrations/supabase/types.d.ts +183 -0
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/dist-lib/lib/channel-providers.d.ts +8 -0
- package/dist-lib/lib/channel-providers.d.ts.map +1 -0
- package/dist-lib/lib/channel-providers.js +23 -0
- package/dist-lib/lib/customer-schemas.d.ts +1 -1
- package/dist-lib/lib/customers.functions.d.ts +1 -1
- package/dist-lib/lib/delivery-gln.d.ts +58 -0
- package/dist-lib/lib/delivery-gln.d.ts.map +1 -0
- package/dist-lib/lib/delivery-gln.js +81 -0
- package/dist-lib/lib/delivery-locations.functions.d.ts +115 -1
- package/dist-lib/lib/delivery-locations.functions.d.ts.map +1 -1
- package/dist-lib/lib/delivery-locations.functions.js +124 -4
- package/dist-lib/lib/external-customers.functions.d.ts.map +1 -1
- package/dist-lib/lib/external-customers.functions.js +18 -15
- package/package.json +1 -1
- package/schema/klanten.sql +467 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ExternalProvider } from "./external-customers.functions.js";
|
|
2
|
+
/**
|
|
3
|
+
* Configuratierijen aangevuld met kanalen die in de koppelingen voorkomen maar geen rij hebben.
|
|
4
|
+
* Een rij met is_enabled=false blijft staan (en dus verborgen voor de lijst); ontbrekende rijen = aan.
|
|
5
|
+
*/
|
|
6
|
+
export declare function resolveProviders(rows: ExternalProvider[], seen: Iterable<string>): ExternalProvider[];
|
|
7
|
+
export declare function enabledProviderKeys(providers: ExternalProvider[]): Set<string>;
|
|
8
|
+
//# sourceMappingURL=channel-providers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel-providers.d.ts","sourceRoot":"","sources":["../../src/lib/channel-providers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AASvE;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,gBAAgB,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,gBAAgB,EAAE,CAUrG;AAED,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,gBAAgB,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAE9E"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Standaardgegevens voor kanalen zonder configuratierij. */
|
|
2
|
+
const DEFAULTS = {
|
|
3
|
+
local: { label: "Lokaal", icon: "user", color: "#6B7280", sort_order: 0 },
|
|
4
|
+
twinfield: { label: "Twinfield", icon: "/flowselections-assets/Klanten/twinfield-logo.svg", color: "#0057B7", sort_order: 10 },
|
|
5
|
+
floriday: { label: "Floriday", icon: "/flowselections-assets/Klanten/floriday-logo.png", color: "#00A651", sort_order: 20 },
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Configuratierijen aangevuld met kanalen die in de koppelingen voorkomen maar geen rij hebben.
|
|
9
|
+
* Een rij met is_enabled=false blijft staan (en dus verborgen voor de lijst); ontbrekende rijen = aan.
|
|
10
|
+
*/
|
|
11
|
+
export function resolveProviders(rows, seen) {
|
|
12
|
+
const byKey = new Map(rows.map((r) => [r.provider, r]));
|
|
13
|
+
for (const key of seen) {
|
|
14
|
+
if (!key || byKey.has(key))
|
|
15
|
+
continue;
|
|
16
|
+
const d = DEFAULTS[key] ?? { label: key.charAt(0).toUpperCase() + key.slice(1), icon: null, color: null, sort_order: 100 };
|
|
17
|
+
byKey.set(key, { provider: key, ...d, is_enabled: true, last_synced_at: null });
|
|
18
|
+
}
|
|
19
|
+
return Array.from(byKey.values()).sort((a, b) => a.sort_order - b.sort_order || a.provider.localeCompare(b.provider));
|
|
20
|
+
}
|
|
21
|
+
export function enabledProviderKeys(providers) {
|
|
22
|
+
return new Set(providers.filter((p) => p.is_enabled).map((p) => p.provider));
|
|
23
|
+
}
|
|
@@ -394,8 +394,8 @@ export declare const listFiltersSchema: z.ZodObject<{
|
|
|
394
394
|
}>>>;
|
|
395
395
|
source: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
396
396
|
local: "local";
|
|
397
|
-
all: "all";
|
|
398
397
|
floriday: "floriday";
|
|
398
|
+
all: "all";
|
|
399
399
|
}>>>;
|
|
400
400
|
since: z.ZodOptional<z.ZodString>;
|
|
401
401
|
}, z.core.$strip>;
|
|
@@ -62,7 +62,7 @@ export declare const listCustomers: import("@tanstack/start-client-core").Requir
|
|
|
62
62
|
customer_class: string;
|
|
63
63
|
country: string;
|
|
64
64
|
is_active: "active" | "all" | "inactive";
|
|
65
|
-
source: "local" | "
|
|
65
|
+
source: "local" | "floriday" | "all";
|
|
66
66
|
since?: string | undefined;
|
|
67
67
|
}, Promise<{
|
|
68
68
|
customers: any[];
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export declare function normalizeGln(value: string | null | undefined): string;
|
|
2
|
+
/** 13 cijfers en een kloppend GS1-controlecijfer. */
|
|
3
|
+
export declare function isValidGln(value: string | null | undefined): boolean;
|
|
4
|
+
export declare function glnError(value: string): string | null;
|
|
5
|
+
export type DupLocation = {
|
|
6
|
+
id: string;
|
|
7
|
+
name?: string | null;
|
|
8
|
+
street?: string | null;
|
|
9
|
+
house_number?: string | null;
|
|
10
|
+
address_line?: string | null;
|
|
11
|
+
postal_code?: string | null;
|
|
12
|
+
country?: string | null;
|
|
13
|
+
city?: string | null;
|
|
14
|
+
};
|
|
15
|
+
export declare function addressKey(l: DupLocation): string | null;
|
|
16
|
+
/**
|
|
17
|
+
* Mogelijk dubbel: zelfde adres én (zelfde naam óf één naam leeg).
|
|
18
|
+
* Docks/boxen op hetzelfde veilingcomplex met een andere naam tellen niet als dubbel.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isPossibleDuplicate(a: DupLocation, b: DupLocation): boolean;
|
|
21
|
+
/** Groepen van mogelijk dubbele locaties (elke groep ≥ 2). */
|
|
22
|
+
export declare function duplicateGroups<T extends DupLocation>(locations: T[]): T[][];
|
|
23
|
+
export type MergePreview = {
|
|
24
|
+
source: {
|
|
25
|
+
id: string;
|
|
26
|
+
name: string | null;
|
|
27
|
+
address: string | null;
|
|
28
|
+
postal_code: string | null;
|
|
29
|
+
city: string | null;
|
|
30
|
+
is_primary: boolean;
|
|
31
|
+
};
|
|
32
|
+
target: {
|
|
33
|
+
id: string;
|
|
34
|
+
name: string | null;
|
|
35
|
+
address: string | null;
|
|
36
|
+
postal_code: string | null;
|
|
37
|
+
city: string | null;
|
|
38
|
+
is_primary: boolean;
|
|
39
|
+
};
|
|
40
|
+
glns: Array<{
|
|
41
|
+
id: string;
|
|
42
|
+
gln: string;
|
|
43
|
+
removed: boolean;
|
|
44
|
+
}>;
|
|
45
|
+
shipments: number;
|
|
46
|
+
carrier_differences: Array<{
|
|
47
|
+
gln: string;
|
|
48
|
+
carrier_id: string;
|
|
49
|
+
carrier: string;
|
|
50
|
+
}>;
|
|
51
|
+
enabled: boolean;
|
|
52
|
+
};
|
|
53
|
+
/** Regels voor het samenvoegoverzicht. */
|
|
54
|
+
export declare function mergeSummary(p: MergePreview): {
|
|
55
|
+
lines: string[];
|
|
56
|
+
warnings: string[];
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=delivery-gln.d.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,GAAG,IAAI,CAAC;QAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,UAAU,EAAE,OAAO,CAAA;KAAE,CAAC;IAC1I,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,UAAU,EAAE,OAAO,CAAA;KAAE,CAAC;IAC1I,IAAI,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAC3D,SAAS,EAAE,MAAM,CAAC;IAClB,mBAAmB,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACjF,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAIF,0CAA0C;AAC1C,wBAAgB,YAAY,CAAC,CAAC,EAAE,YAAY,GAAG;IAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAgBrF"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Gedeelde regels voor GLN's van afleverlocaties (zelfde regels als klanten_gln_norm/klanten_gln_geldig in de database).
|
|
2
|
+
export function normalizeGln(value) {
|
|
3
|
+
return (value ?? "").replace(/\D/g, "");
|
|
4
|
+
}
|
|
5
|
+
/** 13 cijfers en een kloppend GS1-controlecijfer. */
|
|
6
|
+
export function isValidGln(value) {
|
|
7
|
+
const v = normalizeGln(value);
|
|
8
|
+
if (!/^\d{13}$/.test(v) || v !== (value ?? "").trim().replace(/\s/g, ""))
|
|
9
|
+
return false;
|
|
10
|
+
let sum = 0;
|
|
11
|
+
for (let i = 0; i < 12; i++)
|
|
12
|
+
sum += Number(v[i]) * (i % 2 === 1 ? 3 : 1);
|
|
13
|
+
return (10 - (sum % 10)) % 10 === Number(v[12]);
|
|
14
|
+
}
|
|
15
|
+
export function glnError(value) {
|
|
16
|
+
const v = value.trim().replace(/\s/g, "");
|
|
17
|
+
if (!v)
|
|
18
|
+
return "Vul een GLN in";
|
|
19
|
+
if (!/^\d{13}$/.test(v))
|
|
20
|
+
return "Een GLN bestaat uit 13 cijfers";
|
|
21
|
+
if (!isValidGln(v))
|
|
22
|
+
return "Het controlecijfer van deze GLN klopt niet";
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const compact = (v) => (v ?? "").toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
26
|
+
export function addressKey(l) {
|
|
27
|
+
const street = l.street ? `${l.street} ${l.house_number ?? ""}` : l.address_line;
|
|
28
|
+
const s = compact(street);
|
|
29
|
+
const p = compact(l.postal_code);
|
|
30
|
+
if (!s || !p)
|
|
31
|
+
return null;
|
|
32
|
+
return `${s}|${p}|${compact(l.country)}`;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Mogelijk dubbel: zelfde adres én (zelfde naam óf één naam leeg).
|
|
36
|
+
* Docks/boxen op hetzelfde veilingcomplex met een andere naam tellen niet als dubbel.
|
|
37
|
+
*/
|
|
38
|
+
export function isPossibleDuplicate(a, b) {
|
|
39
|
+
if (a.id === b.id)
|
|
40
|
+
return false;
|
|
41
|
+
const ka = addressKey(a);
|
|
42
|
+
if (!ka || ka !== addressKey(b))
|
|
43
|
+
return false;
|
|
44
|
+
const na = compact(a.name);
|
|
45
|
+
const nb = compact(b.name);
|
|
46
|
+
return !na || !nb || na === nb;
|
|
47
|
+
}
|
|
48
|
+
/** Groepen van mogelijk dubbele locaties (elke groep ≥ 2). */
|
|
49
|
+
export function duplicateGroups(locations) {
|
|
50
|
+
const seen = new Set();
|
|
51
|
+
const groups = [];
|
|
52
|
+
for (const a of locations) {
|
|
53
|
+
if (seen.has(a.id))
|
|
54
|
+
continue;
|
|
55
|
+
const group = [a, ...locations.filter((b) => !seen.has(b.id) && isPossibleDuplicate(a, b))];
|
|
56
|
+
if (group.length > 1) {
|
|
57
|
+
group.forEach((g) => seen.add(g.id));
|
|
58
|
+
groups.push(group);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return groups;
|
|
62
|
+
}
|
|
63
|
+
const label = (l) => l.name || l.address || "Naamloze locatie";
|
|
64
|
+
/** Regels voor het samenvoegoverzicht. */
|
|
65
|
+
export function mergeSummary(p) {
|
|
66
|
+
const target = label(p.target);
|
|
67
|
+
const lines = p.glns
|
|
68
|
+
.filter((g) => !g.removed)
|
|
69
|
+
.map((g) => `GLN ${g.gln} wordt toegevoegd aan ${target}`);
|
|
70
|
+
lines.push(`${p.shipments} ${p.shipments === 1 ? "zending wordt" : "zendingen worden"} omgezet`);
|
|
71
|
+
lines.push(`${label(p.source)} wordt verwijderd`);
|
|
72
|
+
lines.push(`De vervoerder van ${target} blijft behouden`);
|
|
73
|
+
const warnings = [];
|
|
74
|
+
if (compact(p.source.name) && compact(p.target.name) && compact(p.source.name) !== compact(p.target.name)) {
|
|
75
|
+
warnings.push("De namen verschillen: dit kan een andere dock of box zijn.");
|
|
76
|
+
}
|
|
77
|
+
for (const c of p.carrier_differences) {
|
|
78
|
+
warnings.push(`GLN ${c.gln} hoort bij vervoerder ${c.carrier}; na samenvoegen kan de route veranderen.`);
|
|
79
|
+
}
|
|
80
|
+
return { lines, warnings };
|
|
81
|
+
}
|
|
@@ -140,13 +140,127 @@ export declare const deleteDeliveryLocation: import("@tanstack/start-client-core
|
|
|
140
140
|
}, Promise<{
|
|
141
141
|
ok: true;
|
|
142
142
|
}>>;
|
|
143
|
+
export type LocationGln = {
|
|
144
|
+
id: string;
|
|
145
|
+
location_id: string;
|
|
146
|
+
gln: string;
|
|
147
|
+
is_primary: boolean;
|
|
148
|
+
source: "manual" | "floriday" | "merge";
|
|
149
|
+
removed_at: string | null;
|
|
150
|
+
created_at: string;
|
|
151
|
+
};
|
|
152
|
+
export declare const listLocationGlns: import("@tanstack/start-client-core").RequiredFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
|
|
153
|
+
supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
|
|
154
|
+
userId: string;
|
|
155
|
+
claims: import("@supabase/auth-js").JwtPayload;
|
|
156
|
+
}, undefined, undefined, undefined>], (input: {
|
|
157
|
+
location_ids: string[];
|
|
158
|
+
}) => {
|
|
159
|
+
location_ids: string[];
|
|
160
|
+
}, Promise<{
|
|
161
|
+
glns: LocationGln[];
|
|
162
|
+
mergeEnabled: boolean;
|
|
163
|
+
}>>;
|
|
164
|
+
export declare const locationShipmentCount: import("@tanstack/start-client-core").RequiredFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
|
|
165
|
+
supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
|
|
166
|
+
userId: string;
|
|
167
|
+
claims: import("@supabase/auth-js").JwtPayload;
|
|
168
|
+
}, undefined, undefined, undefined>], (input: {
|
|
169
|
+
id: string;
|
|
170
|
+
}) => {
|
|
171
|
+
id: string;
|
|
172
|
+
}, Promise<{
|
|
173
|
+
shipments: number;
|
|
174
|
+
}>>;
|
|
175
|
+
export type GlnConflict = {
|
|
176
|
+
conflict: true;
|
|
177
|
+
message: string;
|
|
178
|
+
location_id: string | null;
|
|
179
|
+
};
|
|
180
|
+
export declare const addLocationGln: import("@tanstack/start-client-core").RequiredFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
|
|
181
|
+
supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
|
|
182
|
+
userId: string;
|
|
183
|
+
claims: import("@supabase/auth-js").JwtPayload;
|
|
184
|
+
}, undefined, undefined, undefined>], (input: {
|
|
185
|
+
location_id: string;
|
|
186
|
+
gln: string;
|
|
187
|
+
}) => {
|
|
188
|
+
location_id: string;
|
|
189
|
+
gln: string;
|
|
190
|
+
}, Promise<GlnConflict | {
|
|
191
|
+
ok: true;
|
|
192
|
+
}>>;
|
|
193
|
+
export declare const removeLocationGln: import("@tanstack/start-client-core").RequiredFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
|
|
194
|
+
supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
|
|
195
|
+
userId: string;
|
|
196
|
+
claims: import("@supabase/auth-js").JwtPayload;
|
|
197
|
+
}, undefined, undefined, undefined>], (input: {
|
|
198
|
+
id: string;
|
|
199
|
+
}) => {
|
|
200
|
+
id: string;
|
|
201
|
+
}, Promise<{
|
|
202
|
+
ok: true;
|
|
203
|
+
}>>;
|
|
204
|
+
export declare const setPrimaryLocationGln: import("@tanstack/start-client-core").RequiredFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
|
|
205
|
+
supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
|
|
206
|
+
userId: string;
|
|
207
|
+
claims: import("@supabase/auth-js").JwtPayload;
|
|
208
|
+
}, undefined, undefined, undefined>], (input: {
|
|
209
|
+
id: string;
|
|
210
|
+
}) => {
|
|
211
|
+
id: string;
|
|
212
|
+
}, Promise<{
|
|
213
|
+
ok: true;
|
|
214
|
+
}>>;
|
|
215
|
+
export declare const previewLocationMerge: import("@tanstack/start-client-core").RequiredFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
|
|
216
|
+
supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
|
|
217
|
+
userId: string;
|
|
218
|
+
claims: import("@supabase/auth-js").JwtPayload;
|
|
219
|
+
}, undefined, undefined, undefined>], (input: {
|
|
220
|
+
source_id: string;
|
|
221
|
+
target_id: string;
|
|
222
|
+
}) => {
|
|
223
|
+
source_id: string;
|
|
224
|
+
target_id: string;
|
|
225
|
+
}, Promise<import("./delivery-gln.js").MergePreview>>;
|
|
226
|
+
export declare const mergeLocations: import("@tanstack/start-client-core").RequiredFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
|
|
227
|
+
supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
|
|
228
|
+
userId: string;
|
|
229
|
+
claims: import("@supabase/auth-js").JwtPayload;
|
|
230
|
+
}, undefined, undefined, undefined>], (input: {
|
|
231
|
+
source_id: string;
|
|
232
|
+
target_id: string;
|
|
233
|
+
}) => {
|
|
234
|
+
source_id: string;
|
|
235
|
+
target_id: string;
|
|
236
|
+
}, Promise<{
|
|
237
|
+
shipmentsMoved: number;
|
|
238
|
+
}>>;
|
|
239
|
+
export declare const getLocationMergeSetting: import("@tanstack/start-client-core").OptionalFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
|
|
240
|
+
supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
|
|
241
|
+
userId: string;
|
|
242
|
+
claims: import("@supabase/auth-js").JwtPayload;
|
|
243
|
+
}, undefined, undefined, undefined>], undefined, Promise<{
|
|
244
|
+
enabled: boolean;
|
|
245
|
+
}>>;
|
|
246
|
+
export declare const setLocationMergeSetting: import("@tanstack/start-client-core").RequiredFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
|
|
247
|
+
supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
|
|
248
|
+
userId: string;
|
|
249
|
+
claims: import("@supabase/auth-js").JwtPayload;
|
|
250
|
+
}, undefined, undefined, undefined>], (input: {
|
|
251
|
+
enabled: boolean;
|
|
252
|
+
}) => {
|
|
253
|
+
enabled: boolean;
|
|
254
|
+
}, Promise<{
|
|
255
|
+
enabled: boolean;
|
|
256
|
+
}>>;
|
|
143
257
|
export type FloridayLocationPreviewItem = {
|
|
144
258
|
floriday_id: string;
|
|
145
259
|
name: string;
|
|
146
260
|
customer_name: string | null;
|
|
147
261
|
address: string;
|
|
148
262
|
gln: string | null;
|
|
149
|
-
action: "create" | "update" | "no_customer";
|
|
263
|
+
action: "create" | "update" | "no_customer" | "known";
|
|
150
264
|
};
|
|
151
265
|
export type FloridayLocationImportResult = {
|
|
152
266
|
preview: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delivery-locations.functions.d.ts","sourceRoot":"","sources":["../../src/lib/delivery-locations.functions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"delivery-locations.functions.d.ts","sourceRoot":"","sources":["../../src/lib/delivery-locations.functions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,QAAA,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;iBAoBnB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAa3D;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EACrF,QAAQ,EAAE,KAAK,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,iBAAiB,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACnC,iBAAiB,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACnC,cAAc,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAChC,UAAU,CAAC,EAAE,MA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,OAAO,CAAC;CACvD,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,2BAA2B,EAAE,CAAC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AA4BF,eAAO,MAAM,+BAA+B;;;;8CAElB,OAAO;;yCA4J7B,CAAC"}
|
|
@@ -3,6 +3,7 @@ import { z } from "zod";
|
|
|
3
3
|
import { requireSupabaseAuth } from "../integrations/supabase/auth-middleware.js";
|
|
4
4
|
import { regionAliases } from "./eu-regions.js";
|
|
5
5
|
import { toIsoCountry } from "./countries.js";
|
|
6
|
+
import { normalizeGln } from "./delivery-gln.js";
|
|
6
7
|
import { locationCarrierFields } from "./carrier-choice.js";
|
|
7
8
|
const locationSchema = z.object({
|
|
8
9
|
id: z.string().uuid().optional(),
|
|
@@ -187,14 +188,103 @@ export const deleteDeliveryLocation = createServerFn({ method: "POST" })
|
|
|
187
188
|
.middleware([requireSupabaseAuth])
|
|
188
189
|
.inputValidator((input) => input)
|
|
189
190
|
.handler(async ({ data, context }) => {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
191
|
+
// Via de database: weigert bij zendingen en zet Floriday-gegevens op de genegeerd-lijst.
|
|
192
|
+
const { error } = await context.supabase.rpc("delete_customer_delivery_location", { p_location_id: data.id });
|
|
193
|
+
if (error)
|
|
194
|
+
throw new Error(error.message);
|
|
195
|
+
return { ok: true };
|
|
196
|
+
});
|
|
197
|
+
export const listLocationGlns = createServerFn({ method: "POST" })
|
|
198
|
+
.middleware([requireSupabaseAuth])
|
|
199
|
+
.inputValidator((input) => z.object({ location_ids: z.array(z.string().uuid()).max(1000) }).parse(input))
|
|
200
|
+
.handler(async ({ data, context }) => {
|
|
201
|
+
if (data.location_ids.length === 0)
|
|
202
|
+
return { glns: [], mergeEnabled: false };
|
|
203
|
+
const sb = context.supabase;
|
|
204
|
+
const [{ data: rows, error }, { data: enabled, error: e2 }] = await Promise.all([
|
|
205
|
+
sb.from("customer_delivery_location_glns").select("*").in("location_id", data.location_ids).is("removed_at", null).order("created_at"),
|
|
206
|
+
sb.rpc("klanten_locaties_samenvoegen_aan"),
|
|
207
|
+
]);
|
|
208
|
+
if (error)
|
|
209
|
+
throw new Error(error.message);
|
|
210
|
+
if (e2)
|
|
211
|
+
throw new Error(e2.message);
|
|
212
|
+
return { glns: (rows ?? []), mergeEnabled: enabled === true };
|
|
213
|
+
});
|
|
214
|
+
export const locationShipmentCount = createServerFn({ method: "POST" })
|
|
215
|
+
.middleware([requireSupabaseAuth])
|
|
216
|
+
.inputValidator((input) => z.object({ id: z.string().uuid() }).parse(input))
|
|
217
|
+
.handler(async ({ data, context }) => {
|
|
218
|
+
const { data: n, error } = await context.supabase.rpc("klanten_locatie_zendingen", { p_location_id: data.id });
|
|
219
|
+
if (error)
|
|
220
|
+
throw new Error(error.message);
|
|
221
|
+
return { shipments: Number(n ?? 0) };
|
|
222
|
+
});
|
|
223
|
+
export const addLocationGln = createServerFn({ method: "POST" })
|
|
224
|
+
.middleware([requireSupabaseAuth])
|
|
225
|
+
.inputValidator((input) => z.object({ location_id: z.string().uuid(), gln: z.string().trim().min(1).max(32) }).parse(input))
|
|
226
|
+
.handler(async ({ data, context }) => {
|
|
227
|
+
const { error } = await context.supabase.rpc("add_delivery_location_gln", { p_location_id: data.location_id, p_gln: data.gln });
|
|
228
|
+
if (error) {
|
|
229
|
+
if (error.code === "23505")
|
|
230
|
+
return { conflict: true, message: error.message, location_id: error.hint ?? null };
|
|
231
|
+
throw new Error(error.message);
|
|
232
|
+
}
|
|
233
|
+
return { ok: true };
|
|
234
|
+
});
|
|
235
|
+
export const removeLocationGln = createServerFn({ method: "POST" })
|
|
236
|
+
.middleware([requireSupabaseAuth])
|
|
237
|
+
.inputValidator((input) => z.object({ id: z.string().uuid() }).parse(input))
|
|
238
|
+
.handler(async ({ data, context }) => {
|
|
239
|
+
const { error } = await context.supabase.rpc("remove_delivery_location_gln", { p_gln_id: data.id });
|
|
194
240
|
if (error)
|
|
195
241
|
throw new Error(error.message);
|
|
196
242
|
return { ok: true };
|
|
197
243
|
});
|
|
244
|
+
export const setPrimaryLocationGln = createServerFn({ method: "POST" })
|
|
245
|
+
.middleware([requireSupabaseAuth])
|
|
246
|
+
.inputValidator((input) => z.object({ id: z.string().uuid() }).parse(input))
|
|
247
|
+
.handler(async ({ data, context }) => {
|
|
248
|
+
const { error } = await context.supabase.rpc("set_primary_delivery_location_gln", { p_gln_id: data.id });
|
|
249
|
+
if (error)
|
|
250
|
+
throw new Error(error.message);
|
|
251
|
+
return { ok: true };
|
|
252
|
+
});
|
|
253
|
+
export const previewLocationMerge = createServerFn({ method: "POST" })
|
|
254
|
+
.middleware([requireSupabaseAuth])
|
|
255
|
+
.inputValidator((input) => z.object({ source_id: z.string().uuid(), target_id: z.string().uuid() }).parse(input))
|
|
256
|
+
.handler(async ({ data, context }) => {
|
|
257
|
+
const { data: res, error } = await context.supabase.rpc("merge_preview", { p_source_id: data.source_id, p_target_id: data.target_id });
|
|
258
|
+
if (error)
|
|
259
|
+
throw new Error(error.message);
|
|
260
|
+
return res;
|
|
261
|
+
});
|
|
262
|
+
export const mergeLocations = createServerFn({ method: "POST" })
|
|
263
|
+
.middleware([requireSupabaseAuth])
|
|
264
|
+
.inputValidator((input) => z.object({ source_id: z.string().uuid(), target_id: z.string().uuid() }).parse(input))
|
|
265
|
+
.handler(async ({ data, context }) => {
|
|
266
|
+
const { data: res, error } = await context.supabase.rpc("merge_customer_delivery_locations", { p_source_id: data.source_id, p_target_id: data.target_id });
|
|
267
|
+
if (error)
|
|
268
|
+
throw new Error(error.message);
|
|
269
|
+
return { shipmentsMoved: Number(res?.shipments_moved ?? 0) };
|
|
270
|
+
});
|
|
271
|
+
export const getLocationMergeSetting = createServerFn({ method: "POST" })
|
|
272
|
+
.middleware([requireSupabaseAuth])
|
|
273
|
+
.handler(async ({ context }) => {
|
|
274
|
+
const { data, error } = await context.supabase.rpc("klanten_locaties_samenvoegen_aan");
|
|
275
|
+
if (error)
|
|
276
|
+
throw new Error(error.message);
|
|
277
|
+
return { enabled: data === true };
|
|
278
|
+
});
|
|
279
|
+
export const setLocationMergeSetting = createServerFn({ method: "POST" })
|
|
280
|
+
.middleware([requireSupabaseAuth])
|
|
281
|
+
.inputValidator((input) => z.object({ enabled: z.boolean() }).parse(input))
|
|
282
|
+
.handler(async ({ data, context }) => {
|
|
283
|
+
const { error } = await context.supabase.rpc("klanten_set_locaties_samenvoegen", { p_aan: data.enabled });
|
|
284
|
+
if (error)
|
|
285
|
+
throw new Error(error.message);
|
|
286
|
+
return { enabled: data.enabled };
|
|
287
|
+
});
|
|
198
288
|
function pickAddress(d) {
|
|
199
289
|
// Floriday levert adresvelden genest onder "address"; oudere payloads plat.
|
|
200
290
|
const addr = (d.address && typeof d.address === "object" ? d.address : d);
|
|
@@ -250,6 +340,24 @@ export const importFloridayDeliveryLocations = createServerFn({ method: "POST" }
|
|
|
250
340
|
if (r.floriday_location_id)
|
|
251
341
|
existing.set(String(r.floriday_location_id), String(r.id));
|
|
252
342
|
}
|
|
343
|
+
// Bekende GLN's / Floriday-ID's per klant (ook verwijderd of genegeerd): die maken nooit een nieuwe locatie aan.
|
|
344
|
+
const orgToCustomer = new Map();
|
|
345
|
+
const { data: custRows } = await sb.from("customers").select("id, floriday_organization_id").not("floriday_organization_id", "is", null);
|
|
346
|
+
for (const c of custRows ?? [])
|
|
347
|
+
orgToCustomer.set(String(c.floriday_organization_id), String(c.id));
|
|
348
|
+
const known = new Set();
|
|
349
|
+
const { data: glnRows, error: glnErr } = await sb.from("customer_delivery_location_glns").select("customer_id, gln, floriday_location_id");
|
|
350
|
+
if (glnErr)
|
|
351
|
+
throw new Error(glnErr.message);
|
|
352
|
+
const { data: ignRows, error: ignErr } = await sb.from("customer_delivery_location_ignored").select("customer_id, gln, floriday_location_id");
|
|
353
|
+
if (ignErr)
|
|
354
|
+
throw new Error(ignErr.message);
|
|
355
|
+
for (const r of [...(glnRows ?? []), ...(ignRows ?? [])]) {
|
|
356
|
+
if (r.gln)
|
|
357
|
+
known.add(`${r.customer_id}|g|${r.gln}`);
|
|
358
|
+
if (r.floriday_location_id)
|
|
359
|
+
known.add(`${r.customer_id}|f|${r.floriday_location_id}`);
|
|
360
|
+
}
|
|
253
361
|
const items = [];
|
|
254
362
|
let created = 0;
|
|
255
363
|
let updated = 0;
|
|
@@ -302,6 +410,18 @@ export const importFloridayDeliveryLocations = createServerFn({ method: "POST" }
|
|
|
302
410
|
self_pickup: false,
|
|
303
411
|
};
|
|
304
412
|
const existingId = existing.get(floridayId);
|
|
413
|
+
const custId = orgId ? orgToCustomer.get(orgId) : undefined;
|
|
414
|
+
const gln = normalizeGln(row.gln_code);
|
|
415
|
+
const glnKnown = !!custId && !!gln && known.has(`${custId}|g|${gln}`);
|
|
416
|
+
const idKnown = !!custId && known.has(`${custId}|f|${floridayId}`);
|
|
417
|
+
if (!existingId && (glnKnown || idKnown)) {
|
|
418
|
+
// Bekend (samengevoegd, verwijderd of genegeerd): geen nieuwe locatie.
|
|
419
|
+
skipped++;
|
|
420
|
+
items.push({ ...item, action: "known" });
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
if (glnKnown)
|
|
424
|
+
delete payload.gln;
|
|
305
425
|
if (existingId) {
|
|
306
426
|
updated++;
|
|
307
427
|
if (!data.preview) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-customers.functions.d.ts","sourceRoot":"","sources":["../../src/lib/external-customers.functions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"external-customers.functions.d.ts","sourceRoot":"","sources":["../../src/lib/external-customers.functions.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB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AAA;CAAE;;;;cAQtC,gBAAgB;cAAY,gBAAgB,GAAG,IAAI;GAyB5E,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createServerFn } from "@tanstack/react-start";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { requireSupabaseAuth } from "../integrations/supabase/auth-middleware.js";
|
|
4
|
+
import { resolveProviders, enabledProviderKeys } from "./channel-providers.js";
|
|
4
5
|
const GROUPED_COLS = "group_key, display_name, commercial_name, contact_person, email, phone, city, country, website, logo_url, vat_number, gln, is_active, fetched_at, last_changed_at, providers, source_count, is_merged, match_key, sources";
|
|
5
6
|
const SELECT_COLS = "provider, connection_id, external_id, company_name, commercial_name, contact_person, email, phone, street, house_number, postal_code, city, country, vat_number, gln, website, logo_url, status, is_active, is_deleted, fetched_at, raw";
|
|
6
7
|
const listInput = z.object({
|
|
@@ -44,7 +45,11 @@ export const listExternalProviders = createServerFn({ method: "GET" })
|
|
|
44
45
|
.order("sort_order", { ascending: true });
|
|
45
46
|
if (error)
|
|
46
47
|
throw new Error(`external_customer_providers: ${error.message}`);
|
|
47
|
-
|
|
48
|
+
// Kanalen uit de koppelingen meenemen, ook zonder configuratierij.
|
|
49
|
+
const rows = await fetchAllRows(() => sb.from("external_customers_grouped").select("providers"), "external_customers_grouped");
|
|
50
|
+
const seen = new Set();
|
|
51
|
+
rows.forEach((r) => (r.providers ?? []).forEach((p) => seen.add(p)));
|
|
52
|
+
return { providers: resolveProviders((data ?? []), seen) };
|
|
48
53
|
});
|
|
49
54
|
export const listExternalCustomers = createServerFn({ method: "POST" })
|
|
50
55
|
.middleware([requireSupabaseAuth])
|
|
@@ -63,26 +68,24 @@ export const listExternalCustomers = createServerFn({ method: "POST" })
|
|
|
63
68
|
.order("sort_order", { ascending: true });
|
|
64
69
|
if (provErr)
|
|
65
70
|
throw new Error(`external_customer_providers: ${provErr.message}`);
|
|
66
|
-
const providers = (providerRows ?? []);
|
|
67
|
-
const enabledKeys = new Set(providers.filter((p) => p.is_enabled).map((p) => p.provider));
|
|
68
|
-
const requested = data.providers?.length
|
|
69
|
-
? data.providers.filter((p) => enabledKeys.has(p))
|
|
70
|
-
: Array.from(enabledKeys);
|
|
71
|
-
if (requested.length === 0) {
|
|
72
|
-
return { customers: [], providers, last_fetched_at: null, server_now: new Date().toISOString() };
|
|
73
|
-
}
|
|
74
71
|
const build = () => {
|
|
75
|
-
let q = sb
|
|
76
|
-
.from("external_customers_grouped")
|
|
77
|
-
.select(GROUPED_COLS)
|
|
78
|
-
.overlaps("providers", requested);
|
|
72
|
+
let q = sb.from("external_customers_grouped").select(GROUPED_COLS);
|
|
79
73
|
if (data.status === "active")
|
|
80
74
|
q = q.eq("is_active", true);
|
|
81
75
|
if (data.since)
|
|
82
76
|
q = q.gt("last_changed_at", data.since);
|
|
83
77
|
return q;
|
|
84
78
|
};
|
|
85
|
-
|
|
79
|
+
const rawCustomers = await fetchAllRows(build, "external_customers_grouped", data.limit);
|
|
80
|
+
// Kanalen uit de koppelingen zelf afleiden, zodat een ontbrekende configuratierij ze niet verbergt.
|
|
81
|
+
const seen = new Set();
|
|
82
|
+
rawCustomers.forEach((c) => (c.providers ?? []).forEach((p) => seen.add(p)));
|
|
83
|
+
const providers = resolveProviders((providerRows ?? []), seen);
|
|
84
|
+
const enabledKeys = enabledProviderKeys(providers);
|
|
85
|
+
const requested = new Set(data.providers?.length ? data.providers.filter((p) => enabledKeys.has(p)) : Array.from(enabledKeys));
|
|
86
|
+
let customers = rawCustomers
|
|
87
|
+
.map((c) => ({ ...c, providers: (c.providers ?? []).filter((p) => enabledKeys.has(p)) }))
|
|
88
|
+
.filter((c) => c.providers.some((p) => requested.has(p)));
|
|
86
89
|
if (data.search) {
|
|
87
90
|
const s = data.search.toLowerCase();
|
|
88
91
|
customers = customers.filter((c) => [c.display_name, c.commercial_name, c.email, c.city, c.contact_person, c.gln, c.vat_number]
|
|
@@ -125,7 +128,7 @@ export const getGroupedCustomerDetail = createServerFn({ method: "POST" })
|
|
|
125
128
|
throw new Error(error.message);
|
|
126
129
|
if (pErr)
|
|
127
130
|
throw new Error(pErr.message);
|
|
128
|
-
const providers = (provs ?? []);
|
|
131
|
+
const providers = resolveProviders((provs ?? []), (row?.providers ?? []));
|
|
129
132
|
// Groep met een eigen klantrij → altijd de gewone klantpagina.
|
|
130
133
|
const localId = row
|
|
131
134
|
? (row.sources ?? []).find((s) => s.provider === "local")?.external_id
|