Files
kakeibo/frontend/src/lib/transfer.ts
T
suphicakir 4d764689e2 feat(veri): CSV dışa ve içe aktarma (harcamalar, plan kalemleri, varlık işlemleri)
- Excel uyumlu CSV indirme
- İçe aktarma: önce deneme raporu (geçerli / zaten var / satır satır hata), onayla geçerli satırlar
- Sütunlar adla, esnek tutar/tarih yazımı, ; ve , ayırıcı, Windows-1254 desteği
- Varlıkta tarih sırasına göre eldekinden fazla satış denetimi
- Ayarlar sayfasında Veri bölümü

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 02:21:44 +03:00

32 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* CSV dışa / içe aktarma. İçe aktarma iki adım: deneme (`commit: false`) → onay (`true`).
* Aktarımdan sonra dönem, rapor ve birikim verileri yenilenir.
*/
import { useMutation, useQueryClient } from '@tanstack/react-query'
import type { ImportReport } from '@/types/ImportReport'
import { api } from './api'
import { queryKeys } from './query'
export const TRANSFER_KINDS = ['entries', 'plan-items', 'asset-transactions'] as const
export type TransferKind = (typeof TRANSFER_KINDS)[number]
/** İndirme adresi (çerezle; tarayıcı dosya olarak kaydeder) */
export const exportUrl = (kind: TransferKind) => `/api/export/${kind}.csv`
export function useImport() {
const qc = useQueryClient()
return useMutation({
mutationFn: ({ kind, csv, commit }: { kind: TransferKind; csv: string; commit: boolean }) =>
api.postCsv<ImportReport>(`/import/${kind}?commit=${commit}`, csv),
onSuccess: (_, v) => {
if (!v.commit) return
void Promise.all([
qc.invalidateQueries({ queryKey: queryKeys.periods }),
qc.invalidateQueries({ queryKey: ['period'] }),
qc.invalidateQueries({ queryKey: queryKeys.portfolio }),
qc.invalidateQueries({ queryKey: queryKeys.reports }),
])
},
})
}