feat(transactions): işlem formu, bölme, liste, filtreler, ayrıntı ve CSV
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { exportTransactions } from "@/features/transactions/service";
|
||||
import { tr } from "@/i18n/tr";
|
||||
import { getHouseholdContext } from "@/lib/dal";
|
||||
import { csvMoney, toCsv } from "@/shared/csv";
|
||||
import { todayIstanbul } from "@/shared/dates";
|
||||
import { formatDate } from "@/shared/format";
|
||||
import { transactionFilterSchema } from "@/shared/schemas/transaction";
|
||||
|
||||
/** GET /islemler/disa-aktar?…filtreler → CSV (listedeki filtrelerle, sayfalama yok). */
|
||||
export async function GET(request: Request) {
|
||||
const ctx = await getHouseholdContext();
|
||||
if (!ctx?.household) return new Response(tr.common.unauthorized, { status: 401 });
|
||||
const params = Object.fromEntries(new URL(request.url).searchParams);
|
||||
const filters = transactionFilterSchema.parse(params);
|
||||
const rows = await exportTransactions(ctx.user.id, ctx.household.id, filters);
|
||||
if (!rows) return new Response(tr.common.unauthorized, { status: 403 });
|
||||
|
||||
const t = tr.transactions;
|
||||
const csv = toCsv(
|
||||
t.csv.header,
|
||||
rows.map((r) => [
|
||||
r.no,
|
||||
formatDate(`${r.date}T12:00:00+03:00`),
|
||||
t.types[r.type],
|
||||
t.statuses[r.status],
|
||||
r.account,
|
||||
r.toAccount,
|
||||
r.category,
|
||||
r.payee,
|
||||
r.description,
|
||||
r.note,
|
||||
r.tags,
|
||||
csvMoney(r.amountMinor),
|
||||
r.createdBy,
|
||||
]),
|
||||
);
|
||||
return new Response(csv, {
|
||||
headers: {
|
||||
"Content-Type": "text/csv; charset=utf-8",
|
||||
"Content-Disposition": `attachment; filename="${t.csv.filename(todayIstanbul())}"`,
|
||||
"Cache-Control": "no-store",
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import type { Metadata } from "next";
|
||||
import { notFound } from "next/navigation";
|
||||
import { PageHeader } from "@/components/page-header";
|
||||
import { listMemberOptions } from "@/features/accounts/service";
|
||||
import { hasHouseholdRole } from "@/features/households/roles";
|
||||
import { TransactionsView } from "@/features/transactions/components/transactions-view";
|
||||
import { getTransactionFormOptions, listTransactions } from "@/features/transactions/service";
|
||||
import { tr } from "@/i18n/tr";
|
||||
import { requireActiveHousehold } from "@/lib/dal";
|
||||
import { transactionFilterSchema } from "@/shared/schemas/transaction";
|
||||
|
||||
export const metadata: Metadata = { title: tr.transactions.title };
|
||||
|
||||
export default async function TransactionsPage({ searchParams }: PageProps<"/islemler">) {
|
||||
const { user, household } = await requireActiveHousehold("viewer");
|
||||
const params = await searchParams;
|
||||
// Yalnızca tekil string değerler (dizi parametreleri yok sayılır).
|
||||
const raw = Object.fromEntries(
|
||||
Object.entries(params).filter(
|
||||
(e): e is [string, string] => typeof e[1] === "string" && e[1] !== "",
|
||||
),
|
||||
);
|
||||
const filters = transactionFilterSchema.parse(raw);
|
||||
const [data, options, members] = await Promise.all([
|
||||
listTransactions(user.id, household.id, filters),
|
||||
getTransactionFormOptions(user.id, household.id),
|
||||
listMemberOptions(user.id, household.id),
|
||||
]);
|
||||
if (!data || !options || !members) notFound();
|
||||
return (
|
||||
<>
|
||||
<PageHeader title={tr.transactions.title} description={tr.transactions.description} />
|
||||
<TransactionsView
|
||||
// Filtre değişince istemci durumu (açık diyaloglar) sıfırlansın.
|
||||
key={JSON.stringify(raw)}
|
||||
data={data}
|
||||
filters={filters}
|
||||
raw={raw}
|
||||
options={{ ...options, members }}
|
||||
canWrite={hasHouseholdRole(household.role, "member")}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user