- Creator-Code = Gutschein mit Creator; Stufen mit Rabatt (Prozent/Festbetrag, Deckel, Mindestwert) und Provision, Werte je Creator überschreibbar - Ausschlüsse: global je Kategorie, je Stufe (Produkte/Kategorien), Schalter am Produkt; Artikel im Sale ausgenommen - Link /c/CODE[/pfad] merkt den Code (Cookie, 30 Tage), zählt Klicks ohne IP, Hinweis oben im Shop - Bestellung friert Creator, Stufe, Satz und Netto-Basis ein; Rabattanteil je Position (auch für Rechnungs-Steuern) - Provision: vorgemerkt, Freigabe nach Haltefrist ab Versand (Kurse: ab Zahlung), Storno vor/nach Auszahlung, Auszahlung verbuchen - Admin /admin/creator (Liste, Detail, Stufen, Einstellungen), Rechte creators.*, Badge in Bestellungen - Kundenkonto /konto/creator: Bedingungen bestätigen, Code/Link, Zahlen je Monat, Provisionen, IBAN und Steuerstatus - Kein Rabatt auf eigene Bestellungen, Willkommens-Mail, Datenschutz-/AGB-Vorlagen ergänzt Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HsJ4RG9iGFNcNnG8YcScYE
88 lines
4.7 KiB
TypeScript
88 lines
4.7 KiB
TypeScript
import Link from "next/link";
|
|
import type { Prisma } from "@prisma/client";
|
|
import { db } from "@/lib/db";
|
|
import { requireAdmin } from "@/lib/auth";
|
|
import { formatPrice } from "@/lib/money";
|
|
import { ORDER_STATUS, PAYMENT_STATUS, dateFmt } from "@/lib/status";
|
|
import { Card, Empty, PageHead, Pill } from "@/components/admin/ui";
|
|
|
|
const TABS: { key: string; label: string; where: Prisma.OrderWhereInput }[] = [
|
|
{ key: "alle", label: "Alle", where: {} },
|
|
{ key: "offen", label: "Zu versenden", where: { status: { in: ["PAID", "PROCESSING"] } } },
|
|
{ key: "zahlung", label: "Zahlung offen", where: { status: "PENDING" } },
|
|
{ key: "versendet", label: "Versendet", where: { status: "SHIPPED" } },
|
|
{ key: "abgeschlossen", label: "Abgeschlossen", where: { status: "COMPLETED" } },
|
|
{ key: "storniert", label: "Storniert", where: { status: { in: ["CANCELLED", "REFUNDED"] } } },
|
|
];
|
|
|
|
export default async function OrdersPage({ searchParams }: { searchParams: Promise<{ status?: string; q?: string; seite?: string }> }) {
|
|
await requireAdmin("orders.view");
|
|
const sp = await searchParams;
|
|
const tab = TABS.find((t) => t.key === sp.status) ?? TABS[0];
|
|
const q = (sp.q ?? "").trim();
|
|
const page = Math.max(1, Number(sp.seite) || 1);
|
|
const where: Prisma.OrderWhereInput = {
|
|
...tab.where,
|
|
...(q ? { OR: [{ number: { contains: q, mode: "insensitive" } }, { email: { contains: q, mode: "insensitive" } }] } : {}),
|
|
};
|
|
const [orders, total, counts] = await Promise.all([
|
|
db.order.findMany({ where, orderBy: { createdAt: "desc" }, take: 50, skip: (page - 1) * 50, include: { _count: { select: { items: true } } } }),
|
|
db.order.count({ where }),
|
|
Promise.all(TABS.map((t) => db.order.count({ where: t.where }))),
|
|
]);
|
|
return (
|
|
<div className="ad-wrap">
|
|
<PageHead title="Bestellungen" lead="Alle Bestellungen auf einen Blick. Klick auf eine Bestellung, um sie zu bearbeiten." />
|
|
<Card flush>
|
|
<div className="ad-toolbar">
|
|
<nav className="ad-tabs" aria-label="Filter">
|
|
{TABS.map((t, i) => (
|
|
<Link key={t.key} className={`ad-tab${t.key === tab.key ? " is-active" : ""}`} href={`/admin/bestellungen?status=${t.key}`}>
|
|
{t.label} <span>{counts[i]}</span>
|
|
</Link>
|
|
))}
|
|
</nav>
|
|
<form method="get" style={{ marginLeft: "auto", display: "flex", gap: 8 }}>
|
|
<input type="hidden" name="status" value={tab.key} />
|
|
<input className="sm-input" type="search" name="q" defaultValue={q} placeholder="Nummer oder E-Mail suchen" aria-label="Bestellungen durchsuchen" />
|
|
</form>
|
|
</div>
|
|
{orders.length === 0 ? (
|
|
<Empty title="Keine Bestellungen gefunden" text={q ? "Versuch es mit einem anderen Suchbegriff." : "In diesem Filter ist gerade nichts."} />
|
|
) : (
|
|
<div className="ad-table-wrap">
|
|
<table className="ad-table">
|
|
<thead>
|
|
<tr><th>Bestellung</th><th>Datum</th><th>Kunde</th><th>Zahlung</th><th>Status</th><th className="num">Summe</th></tr>
|
|
</thead>
|
|
<tbody>
|
|
{orders.map((o) => {
|
|
const addr = o.shippingAddress as { firstName?: string; lastName?: string };
|
|
return (
|
|
<tr key={o.id}>
|
|
<td><Link className="ad-rowlink" href={`/admin/bestellungen/${o.id}`}>{o.number}</Link><div className="body-sm ad-muted">{o._count.items} Positionen</div>{o.creatorId && <Pill tone="gold">Creator: {o.couponCode}</Pill>}</td>
|
|
<td className="body-sm">{dateFmt.format(o.createdAt)}</td>
|
|
<td>{addr.firstName} {addr.lastName}<div className="body-sm ad-muted">{o.email}</div></td>
|
|
<td><Pill tone={PAYMENT_STATUS[o.paymentStatus].tone}>{PAYMENT_STATUS[o.paymentStatus].label}</Pill></td>
|
|
<td><Pill tone={ORDER_STATUS[o.status].tone}>{ORDER_STATUS[o.status].label}</Pill></td>
|
|
<td className="num">{formatPrice(o.total)}</td>
|
|
</tr>
|
|
);
|
|
})}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
)}
|
|
{total > 50 && (
|
|
<div className="ad-card__foot" style={{ justifyContent: "space-between" }}>
|
|
<span className="body-sm ad-muted">Seite {page} von {Math.ceil(total / 50)}</span>
|
|
<span className="sm-btn-row">
|
|
{page > 1 && <Link className="sm-btn sm-btn--secondary sm-btn--sm" href={`?status=${tab.key}&q=${q}&seite=${page - 1}`}>Zurück</Link>}
|
|
{page * 50 < total && <Link className="sm-btn sm-btn--secondary sm-btn--sm" href={`?status=${tab.key}&q=${q}&seite=${page + 1}`}>Weiter</Link>}
|
|
</span>
|
|
</div>
|
|
)}
|
|
</Card>
|
|
</div>
|
|
);
|
|
}
|