@flowselections/floriday-klanten-module 1.0.12 → 1.0.14
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/DiscountsTab.d.ts +4 -0
- package/dist-lib/components/klanten/DiscountsTab.d.ts.map +1 -0
- package/dist-lib/components/klanten/DiscountsTab.js +92 -0
- package/dist-lib/components/klanten/GroupedKlantDetail.d.ts.map +1 -1
- package/dist-lib/components/klanten/GroupedKlantDetail.js +4 -1
- package/dist-lib/components/klanten/ImportKlanten.d.ts +2 -0
- package/dist-lib/components/klanten/ImportKlanten.d.ts.map +1 -0
- package/dist-lib/components/klanten/ImportKlanten.js +406 -0
- package/dist-lib/components/klanten/KlantDetail.d.ts.map +1 -1
- package/dist-lib/components/klanten/KlantDetail.js +2 -1
- package/dist-lib/components/klanten/KlantenOverzicht.d.ts.map +1 -1
- package/dist-lib/components/klanten/KlantenOverzicht.js +83 -23
- package/dist-lib/components/klanten/LocalDiscountFormDialog.d.ts +10 -0
- package/dist-lib/components/klanten/LocalDiscountFormDialog.d.ts.map +1 -0
- package/dist-lib/components/klanten/LocalDiscountFormDialog.js +107 -0
- package/dist-lib/components/klanten/LocalDiscountsTab.d.ts +4 -0
- package/dist-lib/components/klanten/LocalDiscountsTab.d.ts.map +1 -0
- package/dist-lib/components/klanten/LocalDiscountsTab.js +101 -0
- package/dist-lib/components/klanten/NieuweKlant.d.ts.map +1 -1
- package/dist-lib/components/klanten/NieuweKlant.js +10 -1
- package/dist-lib/index.d.ts +1 -0
- package/dist-lib/index.d.ts.map +1 -1
- package/dist-lib/index.js +1 -0
- package/dist-lib/integrations/supabase/auth-middleware.d.ts +1857 -32
- package/dist-lib/integrations/supabase/auth-middleware.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/client.d.ts +1857 -32
- package/dist-lib/integrations/supabase/client.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/client.server.d.ts +1857 -32
- package/dist-lib/integrations/supabase/client.server.d.ts.map +1 -1
- package/dist-lib/integrations/supabase/types.d.ts +1873 -18
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/dist-lib/lib/accounting.functions.d.ts +5790 -315
- package/dist-lib/lib/accounting.functions.d.ts.map +1 -1
- package/dist-lib/lib/customer-analytics.functions.d.ts +1857 -32
- package/dist-lib/lib/customer-analytics.functions.d.ts.map +1 -1
- package/dist-lib/lib/customer-schemas.d.ts +147 -0
- package/dist-lib/lib/customer-schemas.d.ts.map +1 -1
- package/dist-lib/lib/customer-schemas.js +64 -7
- package/dist-lib/lib/customers.functions.d.ts +24512 -182
- package/dist-lib/lib/customers.functions.d.ts.map +1 -1
- package/dist-lib/lib/customers.functions.js +76 -17
- package/dist-lib/lib/delivery-locations.functions.d.ts +7300 -0
- package/dist-lib/lib/delivery-locations.functions.d.ts.map +1 -1
- package/dist-lib/lib/external-customers.functions.d.ts +7300 -0
- package/dist-lib/lib/external-customers.functions.d.ts.map +1 -1
- package/dist-lib/lib/floriday-discounts.functions.d.ts +22716 -0
- package/dist-lib/lib/floriday-discounts.functions.d.ts.map +1 -0
- package/dist-lib/lib/floriday-discounts.functions.js +83 -0
- package/dist-lib/lib/local-discounts.functions.d.ts +79495 -0
- package/dist-lib/lib/local-discounts.functions.d.ts.map +1 -0
- package/dist-lib/lib/local-discounts.functions.js +185 -0
- package/dist-lib/lib/overdue-invoices.functions.d.ts +11355 -0
- package/dist-lib/lib/overdue-invoices.functions.d.ts.map +1 -0
- package/dist-lib/lib/overdue-invoices.functions.js +72 -0
- package/package.json +9 -2
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
import { createServerFn } from "@tanstack/react-start";
|
|
2
2
|
import { requireSupabaseAuth } from "../integrations/supabase/auth-middleware";
|
|
3
|
-
import { customerCreateSchema, customerUpdateSchema, listFiltersSchema, } from "./customer-schemas";
|
|
3
|
+
import { customerCreateSchema, customerUpdateSchema, listFiltersSchema, customerImportSchema, } from "./customer-schemas";
|
|
4
|
+
const OPTIONAL_TEXT_FIELDS = [
|
|
5
|
+
"vat_number", "contact_person", "phone", "postal_code", "city",
|
|
6
|
+
"customer_class", "notes", "customer_number", "language", "website",
|
|
7
|
+
"billing_email", "address_type", "address_line1", "address_line2",
|
|
8
|
+
"icp_country_code", "attention_to", "fax", "coc_number",
|
|
9
|
+
"bank_name", "bank_account_holder", "bank_account_number", "bank_iban",
|
|
10
|
+
"bank_bic", "bank_national_code", "bank_address_line1", "bank_address_line2",
|
|
11
|
+
"bank_house_number", "bank_postal_code", "bank_city", "bank_state",
|
|
12
|
+
"bank_country", "vat_display",
|
|
13
|
+
];
|
|
14
|
+
const NUMERIC_FIELDS = ["discount_percentage", "discount_days", "payment_term_days"];
|
|
15
|
+
function buildCustomerInsert(row) {
|
|
16
|
+
const out = {
|
|
17
|
+
company_name: row.company_name,
|
|
18
|
+
email: row.email,
|
|
19
|
+
street: row.street,
|
|
20
|
+
house_number: row.house_number,
|
|
21
|
+
country: row.country,
|
|
22
|
+
is_active: row.is_active ?? true,
|
|
23
|
+
source: "local",
|
|
24
|
+
};
|
|
25
|
+
for (const k of OPTIONAL_TEXT_FIELDS) {
|
|
26
|
+
const v = row[k];
|
|
27
|
+
out[k] = v === undefined || v === "" ? null : v;
|
|
28
|
+
}
|
|
29
|
+
for (const k of NUMERIC_FIELDS) {
|
|
30
|
+
const v = row[k];
|
|
31
|
+
out[k] = v === undefined || v === "" || v === null ? null : v;
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
4
35
|
export const listCustomers = createServerFn({ method: "POST" })
|
|
5
36
|
.middleware([requireSupabaseAuth])
|
|
6
37
|
.inputValidator((input) => listFiltersSchema.parse(input))
|
|
@@ -133,22 +164,7 @@ export const createCustomer = createServerFn({ method: "POST" })
|
|
|
133
164
|
}
|
|
134
165
|
const { data: inserted, error } = await supabase
|
|
135
166
|
.from("customers")
|
|
136
|
-
.insert(
|
|
137
|
-
company_name: data.company_name,
|
|
138
|
-
vat_number: data.vat_number || null,
|
|
139
|
-
contact_person: data.contact_person || null,
|
|
140
|
-
email: data.email,
|
|
141
|
-
phone: data.phone || null,
|
|
142
|
-
street: data.street,
|
|
143
|
-
house_number: data.house_number,
|
|
144
|
-
postal_code: data.postal_code || null,
|
|
145
|
-
city: data.city || null,
|
|
146
|
-
country: data.country,
|
|
147
|
-
customer_class: data.customer_class || null,
|
|
148
|
-
notes: data.notes || null,
|
|
149
|
-
is_active: data.is_active ?? true,
|
|
150
|
-
source: "local",
|
|
151
|
-
})
|
|
167
|
+
.insert(buildCustomerInsert(data))
|
|
152
168
|
.select("*")
|
|
153
169
|
.single();
|
|
154
170
|
if (error)
|
|
@@ -226,3 +242,46 @@ export const listCustomerClasses = createServerFn({ method: "POST" })
|
|
|
226
242
|
.order("sort_order");
|
|
227
243
|
return { classes: (data ?? []).map((d) => d.label) };
|
|
228
244
|
});
|
|
245
|
+
export const bulkImportCustomers = createServerFn({ method: "POST" })
|
|
246
|
+
.middleware([requireSupabaseAuth])
|
|
247
|
+
.inputValidator((input) => customerImportSchema.parse(input))
|
|
248
|
+
.handler(async ({ data, context }) => {
|
|
249
|
+
const { supabase } = context;
|
|
250
|
+
const results = { created: 0, skipped: 0, failed: 0, errors: [] };
|
|
251
|
+
for (let i = 0; i < data.rows.length; i++) {
|
|
252
|
+
const row = data.rows[i];
|
|
253
|
+
try {
|
|
254
|
+
if (data.skipDuplicates) {
|
|
255
|
+
const dupes = await findDuplicates(supabase, {
|
|
256
|
+
email: row.email,
|
|
257
|
+
vat_number: row.vat_number || undefined,
|
|
258
|
+
company_name: row.company_name,
|
|
259
|
+
});
|
|
260
|
+
if (dupes.length > 0) {
|
|
261
|
+
results.skipped += 1;
|
|
262
|
+
results.errors.push({
|
|
263
|
+
row: i + 1,
|
|
264
|
+
company_name: row.company_name,
|
|
265
|
+
reason: `Overgeslagen (duplicaat: ${dupes[0].reason.toLowerCase()})`,
|
|
266
|
+
});
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const { error } = await supabase
|
|
271
|
+
.from("customers")
|
|
272
|
+
.insert(buildCustomerInsert(row));
|
|
273
|
+
if (error)
|
|
274
|
+
throw new Error(error.message);
|
|
275
|
+
results.created += 1;
|
|
276
|
+
}
|
|
277
|
+
catch (e) {
|
|
278
|
+
results.failed += 1;
|
|
279
|
+
results.errors.push({
|
|
280
|
+
row: i + 1,
|
|
281
|
+
company_name: row.company_name,
|
|
282
|
+
reason: e instanceof Error ? e.message : "Onbekende fout",
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return results;
|
|
287
|
+
});
|