@flowselections/floriday-klanten-module 1.0.84 → 1.0.87

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.
Files changed (90) hide show
  1. package/dist-lib/components/fs-ui/DataTable.d.ts +12 -0
  2. package/dist-lib/components/fs-ui/DataTable.d.ts.map +1 -0
  3. package/dist-lib/components/fs-ui/DataTable.js +10 -0
  4. package/dist-lib/components/fs-ui/EmptyState.d.ts +9 -0
  5. package/dist-lib/components/fs-ui/EmptyState.d.ts.map +1 -0
  6. package/dist-lib/components/fs-ui/EmptyState.js +5 -0
  7. package/dist-lib/components/fs-ui/FilterChips.d.ts +12 -0
  8. package/dist-lib/components/fs-ui/FilterChips.d.ts.map +1 -0
  9. package/dist-lib/components/fs-ui/FilterChips.js +8 -0
  10. package/dist-lib/components/fs-ui/HoverTip.d.ts +15 -0
  11. package/dist-lib/components/fs-ui/HoverTip.d.ts.map +1 -0
  12. package/dist-lib/components/fs-ui/HoverTip.js +24 -0
  13. package/dist-lib/components/fs-ui/InlineAlert.d.ts +14 -0
  14. package/dist-lib/components/fs-ui/InlineAlert.d.ts.map +1 -0
  15. package/dist-lib/components/fs-ui/InlineAlert.js +20 -0
  16. package/dist-lib/components/fs-ui/Kbd.d.ts +7 -0
  17. package/dist-lib/components/fs-ui/Kbd.d.ts.map +1 -0
  18. package/dist-lib/components/fs-ui/Kbd.js +7 -0
  19. package/dist-lib/components/fs-ui/KpiRow.d.ts +6 -0
  20. package/dist-lib/components/fs-ui/KpiRow.d.ts.map +1 -0
  21. package/dist-lib/components/fs-ui/KpiRow.js +5 -0
  22. package/dist-lib/components/fs-ui/KpiTile.d.ts +21 -0
  23. package/dist-lib/components/fs-ui/KpiTile.d.ts.map +1 -0
  24. package/dist-lib/components/fs-ui/KpiTile.js +40 -0
  25. package/dist-lib/components/fs-ui/MobilePrimaryAction.d.ts +8 -0
  26. package/dist-lib/components/fs-ui/MobilePrimaryAction.d.ts.map +1 -0
  27. package/dist-lib/components/fs-ui/MobilePrimaryAction.js +7 -0
  28. package/dist-lib/components/fs-ui/PageHeader.d.ts +10 -0
  29. package/dist-lib/components/fs-ui/PageHeader.d.ts.map +1 -0
  30. package/dist-lib/components/fs-ui/PageHeader.js +6 -0
  31. package/dist-lib/components/fs-ui/PillTabs.d.ts +14 -0
  32. package/dist-lib/components/fs-ui/PillTabs.d.ts.map +1 -0
  33. package/dist-lib/components/fs-ui/PillTabs.js +11 -0
  34. package/dist-lib/components/fs-ui/SearchInput.d.ts +10 -0
  35. package/dist-lib/components/fs-ui/SearchInput.d.ts.map +1 -0
  36. package/dist-lib/components/fs-ui/SearchInput.js +13 -0
  37. package/dist-lib/components/fs-ui/StatusIcon.d.ts +16 -0
  38. package/dist-lib/components/fs-ui/StatusIcon.d.ts.map +1 -0
  39. package/dist-lib/components/fs-ui/StatusIcon.js +12 -0
  40. package/dist-lib/components/fs-ui/TableSkeleton.d.ts +7 -0
  41. package/dist-lib/components/fs-ui/TableSkeleton.d.ts.map +1 -0
  42. package/dist-lib/components/fs-ui/TableSkeleton.js +9 -0
  43. package/dist-lib/components/fs-ui/Toolbar.d.ts +7 -0
  44. package/dist-lib/components/fs-ui/Toolbar.d.ts.map +1 -0
  45. package/dist-lib/components/fs-ui/Toolbar.js +5 -0
  46. package/dist-lib/components/fs-ui/UpdatedAt.d.ts +5 -0
  47. package/dist-lib/components/fs-ui/UpdatedAt.d.ts.map +1 -0
  48. package/dist-lib/components/fs-ui/UpdatedAt.js +7 -0
  49. package/dist-lib/components/fs-ui/index.d.ts +18 -0
  50. package/dist-lib/components/fs-ui/index.d.ts.map +1 -0
  51. package/dist-lib/components/fs-ui/index.js +18 -0
  52. package/dist-lib/components/fs-ui/shortcuts.d.ts +28 -0
  53. package/dist-lib/components/fs-ui/shortcuts.d.ts.map +1 -0
  54. package/dist-lib/components/fs-ui/shortcuts.js +74 -0
  55. package/dist-lib/components/klanten/BewerkKlant.js +2 -2
  56. package/dist-lib/components/klanten/CustomerAnalyticsTab.js +1 -1
  57. package/dist-lib/components/klanten/CustomerKpis.d.ts +7 -0
  58. package/dist-lib/components/klanten/CustomerKpis.d.ts.map +1 -0
  59. package/dist-lib/components/klanten/CustomerKpis.js +33 -0
  60. package/dist-lib/components/klanten/DeliveryLocationsTab.js +1 -1
  61. package/dist-lib/components/klanten/DiscountsTab.js +1 -1
  62. package/dist-lib/components/klanten/ExternalCacheBanner.d.ts.map +1 -1
  63. package/dist-lib/components/klanten/ExternalCacheBanner.js +2 -2
  64. package/dist-lib/components/klanten/FactureringKredietCard.js +1 -1
  65. package/dist-lib/components/klanten/FloridayTradeSettingsCard.js +1 -1
  66. package/dist-lib/components/klanten/GroupedKlantDetail.js +1 -1
  67. package/dist-lib/components/klanten/ImportKlanten.js +1 -1
  68. package/dist-lib/components/klanten/KlantDetail.d.ts.map +1 -1
  69. package/dist-lib/components/klanten/KlantDetail.js +6 -10
  70. package/dist-lib/components/klanten/KlantFormulier.js +8 -8
  71. package/dist-lib/components/klanten/KlantenOverzicht.d.ts.map +1 -1
  72. package/dist-lib/components/klanten/KlantenOverzicht.js +36 -35
  73. package/dist-lib/components/klanten/NieuweKlant.js +2 -2
  74. package/dist-lib/components/klanten/SyncStatusChip.js +1 -1
  75. package/dist-lib/components/klanten/ui/styleguide.d.ts +1 -57
  76. package/dist-lib/components/klanten/ui/styleguide.d.ts.map +1 -1
  77. package/dist-lib/components/klanten/ui/styleguide.js +2 -88
  78. package/dist-lib/components/klanten/useCustomerDefaults.d.ts +1 -1
  79. package/dist-lib/components/klanten/useCustomerDefaults.d.ts.map +1 -1
  80. package/dist-lib/components/klanten/useCustomerDefaults.js +1 -1
  81. package/dist-lib/integrations/supabase/types.d.ts +1722 -0
  82. package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
  83. package/dist-lib/lib/klanten-overzicht.d.ts +64 -0
  84. package/dist-lib/lib/klanten-overzicht.d.ts.map +1 -0
  85. package/dist-lib/lib/klanten-overzicht.functions.d.ts +46 -0
  86. package/dist-lib/lib/klanten-overzicht.functions.d.ts.map +1 -0
  87. package/dist-lib/lib/klanten-overzicht.functions.js +51 -0
  88. package/dist-lib/lib/klanten-overzicht.js +180 -0
  89. package/package.json +10 -1
  90. package/schema/klanten.sql +223 -1
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Referentieberekening van het klantenoverzicht: letterlijk dezelfde regels als
3
+ * KlantenOverzicht.tsx nu in de browser toepast (rijen samenstellen, tellers,
4
+ * filters, zoeken, sorteren). Wordt gebruikt door de gelijkheidstest van
5
+ * klanten_overzicht_pagina / klanten_overzicht_tellers. Het scherm zelf
6
+ * gebruikt deze module (nog) niet.
7
+ */
8
+ import type { OverdueEntry } from "./overdue-invoices.functions.js";
9
+ import type { RevenueEntry } from "./customer-revenue.functions.js";
10
+ import { type PaymentMethodInfo } from "./payment-method.js";
11
+ export type OverviewRow = {
12
+ key: string;
13
+ id: string | null;
14
+ group_key: string | null;
15
+ source: string;
16
+ providers: string[];
17
+ company_name: string;
18
+ commercial_name: string | null;
19
+ contact_person: string | null;
20
+ email: string | null;
21
+ city: string | null;
22
+ country: string | null;
23
+ customer_class: string | null;
24
+ logo_url: string | null;
25
+ is_active: boolean;
26
+ missing?: boolean;
27
+ overdue: OverdueEntry | null;
28
+ revenue: RevenueEntry | null;
29
+ payment_method: PaymentMethodInfo;
30
+ twinfield_code: string | null;
31
+ twinfield_connection_id: string | null;
32
+ missing_invoice?: string[];
33
+ };
34
+ export type OverviewFilters = {
35
+ view?: "all" | "active" | "inactive" | "overdue";
36
+ countries?: string[];
37
+ channels?: string[];
38
+ payments?: string[];
39
+ };
40
+ export type OverviewSort = {
41
+ col: "company_name" | "country";
42
+ dir: "asc" | "desc";
43
+ };
44
+ export declare function buildOverviewRows(localCustomers: any[], externalCustomers: any[], overdueData: {
45
+ by_provider?: {
46
+ twinfield?: Record<string, OverdueEntry>;
47
+ exact?: Record<string, OverdueEntry>;
48
+ };
49
+ } | null, revenueData: {
50
+ by_provider?: Partial<Record<"twinfield" | "exact" | "floriday" | "local", Record<string, RevenueEntry>>>;
51
+ } | null): OverviewRow[];
52
+ export declare function overviewTotals(rows: OverviewRow[]): {
53
+ all: number;
54
+ active: number;
55
+ inactive: number;
56
+ overdue: number;
57
+ };
58
+ export declare function overviewOptions(rows: OverviewRow[]): {
59
+ countries: string[];
60
+ channels: string[];
61
+ payments: string[];
62
+ };
63
+ export declare function filterSortOverview(rows: OverviewRow[], f: OverviewFilters, search: string, sort: OverviewSort): OverviewRow[];
64
+ //# sourceMappingURL=klanten-overzicht.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"klanten-overzicht.d.ts","sourceRoot":"","sources":["../../src/lib/klanten-overzicht.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAuB,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAI/E,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;IAC7B,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;IAC7B,cAAc,EAAE,iBAAiB,CAAC;IAClC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,uBAAuB,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,UAAU,GAAG,SAAS,CAAC;IACjD,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AACF,MAAM,MAAM,YAAY,GAAG;IAAE,GAAG,EAAE,cAAc,GAAG,SAAS,CAAC;IAAC,GAAG,EAAE,KAAK,GAAG,MAAM,CAAA;CAAE,CAAC;AAIpF,wBAAgB,iBAAiB,CAC/B,cAAc,EAAE,GAAG,EAAE,EACrB,iBAAiB,EAAE,GAAG,EAAE,EACxB,WAAW,EAAE;IAAE,WAAW,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;KAAE,CAAA;CAAE,GAAG,IAAI,EACxH,WAAW,EAAE;IAAE,WAAW,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,WAAW,GAAG,OAAO,GAAG,UAAU,GAAG,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,CAAA;CAAE,GAAG,IAAI,GAChI,WAAW,EAAE,CAyGf;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,EAAE;;;;;EAOjD;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,WAAW,EAAE;;;;EAWlD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,CAAC,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,WAAW,EAAE,CAoC7H"}
@@ -0,0 +1,46 @@
1
+ /** Eén pagina van het klantenoverzicht (25/50/100 rijen) met totaal; prijsgroepen alleen voor deze rijen. */
2
+ export declare const getKlantenOverzichtPagina: import("@tanstack/start-client-core").OptionalFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
3
+ supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
4
+ userId: string;
5
+ claims: import("@supabase/auth-js").JwtPayload;
6
+ }, undefined, undefined, undefined>], (input: unknown) => {
7
+ zoek: string;
8
+ filters: {
9
+ view?: "active" | "all" | "inactive" | "overdue" | undefined;
10
+ countries?: string[] | undefined;
11
+ channels?: string[] | undefined;
12
+ payments?: string[] | undefined;
13
+ };
14
+ sort: "company_name:asc" | "company_name:desc" | "country:asc" | "country:desc";
15
+ pagina: number;
16
+ aantal: 100 | 25 | 50;
17
+ }, Promise<{
18
+ rijen: any[];
19
+ totaal: number;
20
+ pagina: number;
21
+ paginas: number;
22
+ aantal: number;
23
+ }>>;
24
+ /** Tellers voor de vier tegels plus de keuzes in de filters. */
25
+ export declare const getKlantenOverzichtTellers: import("@tanstack/start-client-core").OptionalFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
26
+ supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
27
+ userId: string;
28
+ claims: import("@supabase/auth-js").JwtPayload;
29
+ }, undefined, undefined, undefined>], (input: unknown) => {
30
+ zoek: string;
31
+ filters: {
32
+ view?: "active" | "all" | "inactive" | "overdue" | undefined;
33
+ countries?: string[] | undefined;
34
+ channels?: string[] | undefined;
35
+ payments?: string[] | undefined;
36
+ };
37
+ }, Promise<{
38
+ alle: number;
39
+ met_omzet: number;
40
+ zonder_omzet: number;
41
+ achterstallig: number;
42
+ landen: string[];
43
+ kanalen: string[];
44
+ betaalvormen: string[];
45
+ }>>;
46
+ //# sourceMappingURL=klanten-overzicht.functions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"klanten-overzicht.functions.d.ts","sourceRoot":"","sources":["../../src/lib/klanten-overzicht.functions.ts"],"names":[],"mappings":"AAoBA,6GAA6G;AAC7G,eAAO,MAAM,yBAAyB;;;;8CAEZ,OAAO;;;;;;;;;;;;;YAMyB,MAAM;YAAU,MAAM;aAAW,MAAM;YAAU,MAAM;GAO7G,CAAC;AAEL,gEAAgE;AAChE,eAAO,MAAM,0BAA0B;;;;8CAEb,OAAO;;;;;;;;;UAUrB,MAAM;eAAa,MAAM;kBAAgB,MAAM;mBAAiB,MAAM;YACpE,MAAM,EAAE;aAAW,MAAM,EAAE;kBAAgB,MAAM,EAAE;GAE7D,CAAC"}
@@ -0,0 +1,51 @@
1
+ import { createServerFn } from "@tanstack/react-start";
2
+ import { z } from "zod";
3
+ import { requireSupabaseAuth } from "../integrations/supabase/auth-middleware.js";
4
+ import { buildPriceGroupsMap } from "./price-groups.functions.js";
5
+ const filtersSchema = z.object({
6
+ view: z.enum(["all", "active", "inactive", "overdue"]).optional(),
7
+ countries: z.array(z.string()).optional(),
8
+ channels: z.array(z.string()).optional(),
9
+ payments: z.array(z.string()).optional(),
10
+ }).default({});
11
+ const paginaSchema = z.object({
12
+ zoek: z.string().max(255).default(""),
13
+ filters: filtersSchema,
14
+ sort: z.enum(["company_name:asc", "company_name:desc", "country:asc", "country:desc"]).default("company_name:asc"),
15
+ pagina: z.number().int().min(1).default(1),
16
+ aantal: z.union([z.literal(25), z.literal(50), z.literal(100)]).default(25),
17
+ });
18
+ /** Eén pagina van het klantenoverzicht (25/50/100 rijen) met totaal; prijsgroepen alleen voor deze rijen. */
19
+ export const getKlantenOverzichtPagina = createServerFn({ method: "POST" })
20
+ .middleware([requireSupabaseAuth])
21
+ .inputValidator((input) => paginaSchema.parse(input ?? {}))
22
+ .handler(async ({ data, context }) => {
23
+ const { data: res, error } = await context.supabase.rpc("klanten_overzicht_pagina", {
24
+ p_zoek: data.zoek, p_filters: data.filters, p_sort: data.sort, p_pagina: data.pagina, p_aantal: data.aantal,
25
+ });
26
+ if (error)
27
+ throw new Error(`Klantenoverzicht laden mislukt: ${error.message}`);
28
+ const out = res;
29
+ const orgIds = out.rijen.map((r) => r.floriday_organization_id).filter((v) => typeof v === "string" && !!v);
30
+ const groups = orgIds.length ? await buildPriceGroupsMap(context.supabase, orgIds) : {};
31
+ return {
32
+ ...out,
33
+ rijen: out.rijen.map((r) => ({ ...r, price_groups: r.floriday_organization_id ? groups[r.floriday_organization_id] ?? [] : [] })),
34
+ };
35
+ });
36
+ /** Tellers voor de vier tegels plus de keuzes in de filters. */
37
+ export const getKlantenOverzichtTellers = createServerFn({ method: "POST" })
38
+ .middleware([requireSupabaseAuth])
39
+ .inputValidator((input) => z.object({ zoek: z.string().max(255).default(""), filters: filtersSchema }).parse(input ?? {}))
40
+ .handler(async ({ data, context }) => {
41
+ // Verouderde gegroepeerde weergave eerst verversen (alleen weergave, best effort), zoals de huidige lijst.
42
+ const { error: refreshErr } = await context.supabase.rpc("klanten_refresh_grouped_if_stale");
43
+ if (refreshErr)
44
+ console.warn("klanten_refresh_grouped_if_stale:", refreshErr.message);
45
+ const { data: res, error } = await context.supabase.rpc("klanten_overzicht_tellers", {
46
+ p_zoek: data.zoek, p_filters: data.filters,
47
+ });
48
+ if (error)
49
+ throw new Error(`Klantentellers laden mislukt: ${error.message}`);
50
+ return res;
51
+ });
@@ -0,0 +1,180 @@
1
+ import { derivePaymentMethod } from "./payment-method.js";
2
+ import { missingInvoiceAddressFields } from "./invoice-address.js";
3
+ import { formatCountry } from "./countries.js";
4
+ export function buildOverviewRows(localCustomers, externalCustomers, overdueData, revenueData) {
5
+ const tw = overdueData?.by_provider?.twinfield ?? {};
6
+ const ex = overdueData?.by_provider?.exact ?? {};
7
+ const rev = revenueData?.by_provider;
8
+ const revFor = (provider, externalId) => {
9
+ const map = provider === "twinfield" ? rev?.twinfield
10
+ : provider === "exact" ? rev?.exact
11
+ : provider === "floriday" ? rev?.floriday
12
+ : provider === "local" ? rev?.local
13
+ : undefined;
14
+ return map?.[externalId];
15
+ };
16
+ const mergeRevenue = (into, hit) => {
17
+ if (!hit)
18
+ return into;
19
+ if (!into)
20
+ return { ...hit };
21
+ return {
22
+ count: into.count + hit.count,
23
+ amount: into.amount + hit.amount,
24
+ last_date: hit.last_date > into.last_date ? hit.last_date : into.last_date,
25
+ };
26
+ };
27
+ const mergedLocalIds = new Set();
28
+ for (const c of externalCustomers) {
29
+ const provs = c.providers ?? [];
30
+ if (provs.length <= 1)
31
+ continue;
32
+ for (const s of (c.sources ?? []))
33
+ if (s.provider === "local")
34
+ mergedLocalIds.add(s.external_id);
35
+ }
36
+ const localById = new Map();
37
+ for (const c of localCustomers)
38
+ localById.set(String(c.id), c);
39
+ const local = localCustomers
40
+ .filter((c) => !mergedLocalIds.has(String(c.id)))
41
+ .map((c) => ({
42
+ key: `local-${c.id}`,
43
+ id: c.id,
44
+ group_key: null,
45
+ source: "local",
46
+ providers: [],
47
+ missing_invoice: missingInvoiceAddressFields(c),
48
+ company_name: c.company_name,
49
+ commercial_name: c.commercial_name ?? null,
50
+ contact_person: c.contact_person ?? null,
51
+ email: c.email ?? null,
52
+ city: c.city ?? null,
53
+ country: c.country ?? null,
54
+ customer_class: c.customer_class ?? null,
55
+ logo_url: c.logo_url ?? null,
56
+ is_active: !!c.is_active,
57
+ missing: c.twinfield_code ? c.twinfield_present === false : false,
58
+ overdue: null,
59
+ revenue: mergeRevenue(mergeRevenue(null, revFor("local", String(c.id))), c.twinfield_code ? revFor("twinfield", String(c.twinfield_code)) : undefined),
60
+ payment_method: derivePaymentMethod(null, c),
61
+ twinfield_code: c.twinfield_code ?? null,
62
+ twinfield_connection_id: null,
63
+ }));
64
+ const ext = externalCustomers
65
+ .filter((c) => !((c.providers ?? []).length === 1 && (c.providers ?? [])[0] === "local"))
66
+ .map((c) => {
67
+ const provs = c.providers ?? [];
68
+ const sources = (c.sources ?? []);
69
+ const localSource = sources.find((s) => s.provider === "local");
70
+ const localRow = localSource ? localById.get(String(localSource.external_id)) : undefined;
71
+ const twinfieldSource = sources.find((s) => s.provider === "twinfield");
72
+ let overdue = null;
73
+ let revenue = null;
74
+ for (const s of sources)
75
+ revenue = mergeRevenue(revenue, revFor(s.provider, s.external_id));
76
+ for (const s of sources) {
77
+ const hit = s.provider === "twinfield" ? tw[s.external_id] : s.provider === "exact" ? ex[s.external_id] : undefined;
78
+ if (!hit)
79
+ continue;
80
+ if (!overdue)
81
+ overdue = { count: 0, total: 0, oldest_due: hit.oldest_due };
82
+ overdue.count += hit.count;
83
+ overdue.total += hit.total;
84
+ if (hit.oldest_due < overdue.oldest_due)
85
+ overdue.oldest_due = hit.oldest_due;
86
+ }
87
+ return {
88
+ key: `grp-${c.group_key}`,
89
+ id: localSource?.external_id ?? null,
90
+ group_key: c.group_key,
91
+ source: provs[0] ?? "external",
92
+ providers: provs,
93
+ company_name: c.display_name,
94
+ commercial_name: c.commercial_name,
95
+ contact_person: c.contact_person,
96
+ email: c.email,
97
+ city: c.city,
98
+ country: c.country,
99
+ customer_class: localRow?.customer_class ?? null,
100
+ logo_url: c.logo_url,
101
+ is_active: (() => {
102
+ const st = String(twinfieldSource?.status ?? "").toLowerCase();
103
+ if (["hide", "hidden", "deleted", "inactive", "missing"].includes(st))
104
+ return false;
105
+ if (localRow?.twinfield_present === false)
106
+ return false;
107
+ return c.is_active;
108
+ })(),
109
+ missing: String(twinfieldSource?.status ?? "") === "missing" || localRow?.twinfield_present === false,
110
+ overdue,
111
+ revenue,
112
+ payment_method: derivePaymentMethod(sources, localRow),
113
+ twinfield_code: twinfieldSource?.external_id ?? localRow?.twinfield_code ?? null,
114
+ twinfield_connection_id: twinfieldSource?.connection_id ?? null,
115
+ };
116
+ });
117
+ return [...local, ...ext];
118
+ }
119
+ export function overviewTotals(rows) {
120
+ return {
121
+ all: rows.length,
122
+ active: rows.filter((c) => (c.revenue?.count ?? 0) > 0).length,
123
+ inactive: rows.filter((c) => (c.revenue?.count ?? 0) === 0).length,
124
+ overdue: rows.filter((c) => (c.overdue?.count ?? 0) > 0).length,
125
+ };
126
+ }
127
+ export function overviewOptions(rows) {
128
+ const countries = new Set();
129
+ const channels = new Set();
130
+ const payments = new Set();
131
+ rows.forEach((c) => {
132
+ const name = formatCountry(c.country);
133
+ if (name)
134
+ countries.add(name);
135
+ (c.providers ?? []).forEach((p) => { if (p && p !== "local")
136
+ channels.add(p); });
137
+ if (c.payment_method?.label)
138
+ payments.add(c.payment_method.label);
139
+ });
140
+ return { countries: [...countries].sort(), channels: [...channels].sort(), payments: [...payments].sort() };
141
+ }
142
+ export function filterSortOverview(rows, f, search, sort) {
143
+ const view = f.view ?? "all";
144
+ const selectedCountries = f.countries ?? [];
145
+ const selectedChannels = f.channels ?? [];
146
+ const selectedPayments = f.payments ?? [];
147
+ if (view === "active")
148
+ rows = rows.filter((c) => (c.revenue?.count ?? 0) > 0);
149
+ if (view === "inactive")
150
+ rows = rows.filter((c) => (c.revenue?.count ?? 0) === 0);
151
+ if (view === "overdue")
152
+ rows = rows.filter((c) => (c.overdue?.count ?? 0) > 0);
153
+ if (selectedCountries.length > 0)
154
+ rows = rows.filter((c) => {
155
+ const name = formatCountry(c.country);
156
+ return name && selectedCountries.includes(name);
157
+ });
158
+ if (selectedChannels.length > 0) {
159
+ rows = rows.filter((c) => {
160
+ const externalProviders = (c.providers ?? []).filter((p) => p && p !== "local");
161
+ if (selectedChannels.includes("__none__") && externalProviders.length === 0)
162
+ return true;
163
+ return selectedChannels.some((ch) => externalProviders.includes(ch));
164
+ });
165
+ }
166
+ if (selectedPayments.length > 0)
167
+ rows = rows.filter((c) => c.payment_method?.label && selectedPayments.includes(c.payment_method.label));
168
+ if (search) {
169
+ const s = search.toLowerCase();
170
+ rows = rows.filter((c) => [c.company_name, c.commercial_name, c.contact_person, c.email, c.city]
171
+ .filter(Boolean)
172
+ .some((v) => String(v).toLowerCase().includes(s)));
173
+ }
174
+ return [...rows].sort((a, b) => {
175
+ const av = String(a[sort.col] ?? "").toLowerCase();
176
+ const bv = String(b[sort.col] ?? "").toLowerCase();
177
+ const cmp = av.localeCompare(bv);
178
+ return sort.dir === "asc" ? cmp : -cmp;
179
+ });
180
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowselections/floriday-klanten-module",
3
- "version": "1.0.84",
3
+ "version": "1.0.87",
4
4
  "private": false,
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -94,6 +94,15 @@
94
94
  "POST"
95
95
  ]
96
96
  }
97
+ ],
98
+ "crons": [
99
+ {
100
+ "name": "klanten-twinfield-push-queue",
101
+ "schedule": "*/5 * * * *",
102
+ "kind": "http",
103
+ "path": "/api/public/twinfield/run-queue",
104
+ "auth": "twinfield_cron_auth"
105
+ }
97
106
  ]
98
107
  },
99
108
  "files": [