@flowselections/floriday-klanten-module 1.0.11 → 1.0.13

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 (43) hide show
  1. package/dist-lib/components/klanten/DiscountsTab.d.ts +4 -0
  2. package/dist-lib/components/klanten/DiscountsTab.d.ts.map +1 -0
  3. package/dist-lib/components/klanten/DiscountsTab.js +92 -0
  4. package/dist-lib/components/klanten/GroupedKlantDetail.d.ts.map +1 -1
  5. package/dist-lib/components/klanten/GroupedKlantDetail.js +5 -2
  6. package/dist-lib/components/klanten/KlantDetail.d.ts.map +1 -1
  7. package/dist-lib/components/klanten/KlantDetail.js +3 -2
  8. package/dist-lib/components/klanten/KlantenOverzicht.d.ts.map +1 -1
  9. package/dist-lib/components/klanten/KlantenOverzicht.js +83 -23
  10. package/dist-lib/components/klanten/LocalDiscountFormDialog.d.ts +10 -0
  11. package/dist-lib/components/klanten/LocalDiscountFormDialog.d.ts.map +1 -0
  12. package/dist-lib/components/klanten/LocalDiscountFormDialog.js +107 -0
  13. package/dist-lib/components/klanten/LocalDiscountsTab.d.ts +4 -0
  14. package/dist-lib/components/klanten/LocalDiscountsTab.d.ts.map +1 -0
  15. package/dist-lib/components/klanten/LocalDiscountsTab.js +101 -0
  16. package/dist-lib/integrations/supabase/auth-middleware.d.ts +1788 -107
  17. package/dist-lib/integrations/supabase/auth-middleware.d.ts.map +1 -1
  18. package/dist-lib/integrations/supabase/client.d.ts +1788 -107
  19. package/dist-lib/integrations/supabase/client.d.ts.map +1 -1
  20. package/dist-lib/integrations/supabase/client.server.d.ts +1788 -107
  21. package/dist-lib/integrations/supabase/client.server.d.ts.map +1 -1
  22. package/dist-lib/integrations/supabase/types.d.ts +1819 -104
  23. package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
  24. package/dist-lib/lib/accounting.functions.d.ts +5362 -319
  25. package/dist-lib/lib/accounting.functions.d.ts.map +1 -1
  26. package/dist-lib/lib/customer-analytics.functions.d.ts +1788 -107
  27. package/dist-lib/lib/customer-analytics.functions.d.ts.map +1 -1
  28. package/dist-lib/lib/customers.functions.d.ts +11767 -0
  29. package/dist-lib/lib/customers.functions.d.ts.map +1 -1
  30. package/dist-lib/lib/delivery-locations.functions.d.ts +6724 -0
  31. package/dist-lib/lib/delivery-locations.functions.d.ts.map +1 -1
  32. package/dist-lib/lib/external-customers.functions.d.ts +6724 -0
  33. package/dist-lib/lib/external-customers.functions.d.ts.map +1 -1
  34. package/dist-lib/lib/floriday-discounts.functions.d.ts +21974 -0
  35. package/dist-lib/lib/floriday-discounts.functions.d.ts.map +1 -0
  36. package/dist-lib/lib/floriday-discounts.functions.js +83 -0
  37. package/dist-lib/lib/local-discounts.functions.d.ts +76898 -0
  38. package/dist-lib/lib/local-discounts.functions.d.ts.map +1 -0
  39. package/dist-lib/lib/local-discounts.functions.js +185 -0
  40. package/dist-lib/lib/overdue-invoices.functions.d.ts +10984 -0
  41. package/dist-lib/lib/overdue-invoices.functions.d.ts.map +1 -0
  42. package/dist-lib/lib/overdue-invoices.functions.js +72 -0
  43. package/package.json +1 -1
@@ -0,0 +1,185 @@
1
+ import { createServerFn } from "@tanstack/react-start";
2
+ import { z } from "zod";
3
+ import { requireSupabaseAuth } from "../integrations/supabase/auth-middleware";
4
+ const discountTypeSchema = z.enum(["percentage", "amount"]);
5
+ const dateOpt = z.string().min(1).nullable().optional();
6
+ const agreementSchema = z.object({
7
+ id: z.string().uuid().optional(),
8
+ customer_id: z.string().uuid(),
9
+ product_id: z.string().uuid().nullable().optional(),
10
+ product_category_id: z.string().uuid().nullable().optional(),
11
+ base_price: z.number().nullable().optional(),
12
+ net_price: z.number(),
13
+ currency: z.string().default("EUR"),
14
+ valid_from: dateOpt,
15
+ valid_until: dateOpt,
16
+ min_quantity: z.number().nonnegative().default(0),
17
+ notes: z.string().nullable().optional(),
18
+ });
19
+ const salesStrategySchema = z.object({
20
+ id: z.string().uuid().optional(),
21
+ customer_id: z.string().uuid(),
22
+ product_id: z.string().uuid().nullable().optional(),
23
+ product_category_id: z.string().uuid().nullable().optional(),
24
+ discount_type: discountTypeSchema,
25
+ discount_value: z.number(),
26
+ currency: z.string().default("EUR"),
27
+ valid_from: dateOpt,
28
+ valid_until: dateOpt,
29
+ min_quantity: z.number().nonnegative().default(0),
30
+ notes: z.string().nullable().optional(),
31
+ });
32
+ const priceGroupSchema = z.object({
33
+ id: z.string().uuid().optional(),
34
+ customer_id: z.string().uuid(),
35
+ product_id: z.string().uuid().nullable().optional(),
36
+ product_category_id: z.string().uuid().nullable().optional(),
37
+ min_quantity: z.number().nonnegative().default(0),
38
+ discount_type: discountTypeSchema,
39
+ discount_value: z.number(),
40
+ currency: z.string().default("EUR"),
41
+ valid_from: dateOpt,
42
+ valid_until: dateOpt,
43
+ notes: z.string().nullable().optional(),
44
+ });
45
+ const TABLE_BY_SOURCE = {
46
+ agreement: "local_customer_agreements",
47
+ sales_strategy: "local_customer_sales_strategies",
48
+ price_group: "local_customer_price_groups",
49
+ };
50
+ export const listLocalCustomerDiscounts = createServerFn({ method: "GET" })
51
+ .middleware([requireSupabaseAuth])
52
+ .inputValidator((input) => z.object({ customerId: z.string().uuid() }).parse(input))
53
+ .handler(async ({ data, context }) => {
54
+ const { data: rows, error } = await context.supabase
55
+ .from("local_customer_discounts")
56
+ .select("*")
57
+ .eq("customer_id", data.customerId)
58
+ .limit(2000);
59
+ if (error)
60
+ throw new Error(`local_customer_discounts: ${error.message}`);
61
+ const enriched = (rows ?? []).map((r) => ({
62
+ source: r.source,
63
+ source_id: r.source_id,
64
+ customer_id: r.customer_id,
65
+ product_id: r.product_id,
66
+ product_category_id: r.product_category_id,
67
+ product_name: r.product_name,
68
+ base_price: r.base_price != null ? Number(r.base_price) : null,
69
+ discount_type: r.discount_type,
70
+ discount_value: r.discount_value != null ? Number(r.discount_value) : null,
71
+ net_price: r.net_price != null ? Number(r.net_price) : null,
72
+ currency: r.currency ?? "EUR",
73
+ valid_from: r.valid_from,
74
+ valid_until: r.valid_until,
75
+ min_quantity: Number(r.min_quantity ?? 0),
76
+ }));
77
+ return {
78
+ rows: enriched,
79
+ summary: {
80
+ agreements: enriched.filter((r) => r.source === "agreement").length,
81
+ sales_strategies: enriched.filter((r) => r.source === "sales_strategy").length,
82
+ price_groups: enriched.filter((r) => r.source === "price_group").length,
83
+ },
84
+ };
85
+ });
86
+ export const getLocalEffectivePrice = createServerFn({ method: "GET" })
87
+ .middleware([requireSupabaseAuth])
88
+ .inputValidator((input) => z
89
+ .object({
90
+ customerId: z.string().uuid(),
91
+ productId: z.string().uuid(),
92
+ date: z.string().optional(),
93
+ quantity: z.number().optional(),
94
+ })
95
+ .parse(input))
96
+ .handler(async ({ data, context }) => {
97
+ const { data: row, error } = await context.supabase.rpc("local_effective_price", {
98
+ _customer_id: data.customerId,
99
+ _product_id: data.productId,
100
+ _on_date: data.date ?? new Date().toISOString().slice(0, 10),
101
+ _quantity: data.quantity ?? 1,
102
+ });
103
+ if (error)
104
+ throw new Error(`local_effective_price: ${error.message}`);
105
+ const first = Array.isArray(row) ? row[0] : row;
106
+ return first ?? null;
107
+ });
108
+ function cleanPayload(input) {
109
+ const out = {};
110
+ for (const [k, v] of Object.entries(input)) {
111
+ if (v === undefined)
112
+ continue;
113
+ out[k] = v === "" ? null : v;
114
+ }
115
+ return out;
116
+ }
117
+ export const upsertLocalAgreement = createServerFn({ method: "POST" })
118
+ .middleware([requireSupabaseAuth])
119
+ .inputValidator((input) => agreementSchema.parse(input))
120
+ .handler(async ({ data, context }) => {
121
+ const { id, ...rest } = data;
122
+ const payload = cleanPayload(rest);
123
+ const q = id
124
+ ? context.supabase.from("local_customer_agreements").update(payload).eq("id", id).select("*").single()
125
+ : context.supabase.from("local_customer_agreements").insert(payload).select("*").single();
126
+ const { data: row, error } = await q;
127
+ if (error)
128
+ throw new Error(error.message);
129
+ return { row };
130
+ });
131
+ export const upsertLocalSalesStrategy = createServerFn({ method: "POST" })
132
+ .middleware([requireSupabaseAuth])
133
+ .inputValidator((input) => salesStrategySchema.parse(input))
134
+ .handler(async ({ data, context }) => {
135
+ const { id, ...rest } = data;
136
+ const payload = cleanPayload(rest);
137
+ const q = id
138
+ ? context.supabase.from("local_customer_sales_strategies").update(payload).eq("id", id).select("*").single()
139
+ : context.supabase.from("local_customer_sales_strategies").insert(payload).select("*").single();
140
+ const { data: row, error } = await q;
141
+ if (error)
142
+ throw new Error(error.message);
143
+ return { row };
144
+ });
145
+ export const upsertLocalPriceGroup = createServerFn({ method: "POST" })
146
+ .middleware([requireSupabaseAuth])
147
+ .inputValidator((input) => priceGroupSchema.parse(input))
148
+ .handler(async ({ data, context }) => {
149
+ const { id, ...rest } = data;
150
+ const payload = cleanPayload(rest);
151
+ const q = id
152
+ ? context.supabase.from("local_customer_price_groups").update(payload).eq("id", id).select("*").single()
153
+ : context.supabase.from("local_customer_price_groups").insert(payload).select("*").single();
154
+ const { data: row, error } = await q;
155
+ if (error)
156
+ throw new Error(error.message);
157
+ return { row };
158
+ });
159
+ export const deleteLocalDiscount = createServerFn({ method: "POST" })
160
+ .middleware([requireSupabaseAuth])
161
+ .inputValidator((input) => z
162
+ .object({
163
+ source: z.enum(["agreement", "sales_strategy", "price_group"]),
164
+ id: z.string().uuid(),
165
+ })
166
+ .parse(input))
167
+ .handler(async ({ data, context }) => {
168
+ const table = TABLE_BY_SOURCE[data.source];
169
+ const { error } = await context.supabase.from(table).delete().eq("id", data.id);
170
+ if (error)
171
+ throw new Error(error.message);
172
+ return { ok: true };
173
+ });
174
+ export const listLocalProducts = createServerFn({ method: "GET" })
175
+ .middleware([requireSupabaseAuth])
176
+ .handler(async ({ context }) => {
177
+ const { data, error } = await context.supabase
178
+ .from("products")
179
+ .select("id, product, sale_price, unit")
180
+ .order("product")
181
+ .limit(1000);
182
+ if (error)
183
+ throw new Error(error.message);
184
+ return { products: data ?? [] };
185
+ });