diff --git a/.agents/skills/grand-functions/references/schema.md b/.agents/skills/grand-functions/references/schema.md index 28a94bb..cc956b8 100644 --- a/.agents/skills/grand-functions/references/schema.md +++ b/.agents/skills/grand-functions/references/schema.md @@ -33,7 +33,6 @@ Das Datenbankschema besteht aus folgenden Tabellen im Schema `public`: - `show_in_branches` (BOOLEAN) - `preselect` (BOOLEAN) - `resets_others` (BOOLEAN) -- `allow_update_discount` (BOOLEAN) <-- *Berechtigung für Update-Rabatt* ### `products` (Katalogprodukte / Basis-Editionen) - Hauptlösungen (z.B. Basic-Kasse, Backoffice). @@ -44,6 +43,7 @@ Das Datenbankschema besteht aus folgenden Tabellen im Schema `public`: - `tax_rate` (DECIMAL) - `billing_interval` (TEXT: `'one_time'` / `'monthly'`) - `show_in_branches` (BOOLEAN) +- `allow_update_discount` (BOOLEAN) <-- *Berechtigung für Update-Rabatt* ### `modules` (Zusatzmodule / Erweiterungen) - Optionale Erweiterungen für Produkte. Repräsentiert im TypeScript-Code durch das Interface `ProductModule`. diff --git a/shop/components/admin/category-dialog.tsx b/shop/components/admin/category-dialog.tsx index 8d0cf9f..cadc0c0 100644 --- a/shop/components/admin/category-dialog.tsx +++ b/shop/components/admin/category-dialog.tsx @@ -49,7 +49,6 @@ const categorySchema = z.object({ show_in_kauf: z.boolean().default(true), show_in_abo: z.boolean().default(true), resets_others: z.boolean().default(false), - allow_update_discount: z.boolean().default(true), }) type CategoryFormValues = z.infer @@ -78,7 +77,6 @@ export function CategoryDialog({ show_in_kauf: category?.show_in_kauf ?? true, show_in_abo: category?.show_in_abo ?? true, resets_others: category?.resets_others ?? false, - allow_update_discount: category?.allow_update_discount ?? true, }, }) @@ -296,29 +294,6 @@ export function CategoryDialog({ )} /> - ( - - - - -
- - Update-Rabatt erlauben - -

- Wenn aktiv, erhalten Kauf-Lizenzen dieser Kategorie den Update-Rabatt. -

-
-
- )} - /> -
@@ -93,6 +94,7 @@ export function CreateProductDialog({ show_in_abo: product ? (product.show_in_abo ?? true) : true, requirements: product?.requirements || [], exclusions: product?.exclusions || [], + allow_update_discount: product ? (product.allow_update_discount ?? true) : true, modules: product?.modules?.map(m => ({ id: m.id, name: m.name, @@ -277,6 +279,30 @@ export function CreateProductDialog({ />
+ {form.watch('billing_interval') === 'one_time' && ( + ( + + + + +
+ Update-Rabatt erlauben + + Kunden erhalten für dieses Produkt den selektiven Update-Rabatt. + +
+
+ )} + /> + )} + + { if (item.billing_interval === 'one_time') { - const cat = categories.find(c => c.id === item.category_id); - const allowDiscount = cat ? (cat as any).allow_update_discount !== false : true; + const prod = products.find(p => p.id === item.product_id); + const allowDiscount = prod ? prod.allow_update_discount !== false : true; if (allowDiscount) { item.item_total = item.item_total * multiplier; } diff --git a/shop/lib/types.ts b/shop/lib/types.ts index 49e04f1..613b761 100644 --- a/shop/lib/types.ts +++ b/shop/lib/types.ts @@ -17,6 +17,7 @@ export type Product = { show_in_abo?: boolean requirements?: string[] exclusions?: string[] + allow_update_discount?: boolean } export type Category = { @@ -32,7 +33,6 @@ export type Category = { show_in_kauf?: boolean show_in_abo?: boolean resets_others: boolean - allow_update_discount?: boolean created_at: string } diff --git a/shop/supabase/migrations/20260710003000_move_allow_update_discount_to_products.sql b/shop/supabase/migrations/20260710003000_move_allow_update_discount_to_products.sql new file mode 100644 index 0000000..89298fd --- /dev/null +++ b/shop/supabase/migrations/20260710003000_move_allow_update_discount_to_products.sql @@ -0,0 +1,7 @@ +-- Migration: Move allow_update_discount from categories to products +-- Purpose: Control update discount eligibility on product level rather than category level. + +ALTER TABLE public.categories DROP COLUMN IF EXISTS allow_update_discount; +ALTER TABLE public.products ADD COLUMN IF NOT EXISTS allow_update_discount BOOLEAN DEFAULT true NOT NULL; + +NOTIFY pgrst, 'reload schema';